]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
tuntap: add sanity checks about msg_controllen in sendmsg
authorHarold Huang <baymaxhuang@gmail.com>
Thu, 3 Mar 2022 02:24:40 +0000 (10:24 +0800)
committerStefan Bader <stefan.bader@canonical.com>
Fri, 20 May 2022 13:19:48 +0000 (15:19 +0200)
BugLink: https://bugs.launchpad.net/bugs/1971497
[ Upstream commit 74a335a07a17d131b9263bfdbdcb5e40673ca9ca ]

In patch [1], tun_msg_ctl was added to allow pass batched xdp buffers to
tun_sendmsg. Although we donot use msg_controllen in this path, we should
check msg_controllen to make sure the caller pass a valid msg_ctl.

[1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=fe8dd45bb7556246c6b76277b1ba4296c91c2505

Reported-by: Eric Dumazet <eric.dumazet@gmail.com>
Suggested-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Harold Huang <baymaxhuang@gmail.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Link: https://lore.kernel.org/r/20220303022441.383865-1-baymaxhuang@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
drivers/net/tap.c
drivers/net/tun.c
drivers/vhost/net.c

index f285422a8071734e01711fc40ff5997e52df07f5..f870d08bb1f8685022c015998883b07b46a495c2 100644 (file)
@@ -1214,7 +1214,8 @@ static int tap_sendmsg(struct socket *sock, struct msghdr *m,
        struct xdp_buff *xdp;
        int i;
 
-       if (ctl && (ctl->type == TUN_MSG_PTR)) {
+       if (m->msg_controllen == sizeof(struct tun_msg_ctl) &&
+           ctl && ctl->type == TUN_MSG_PTR) {
                for (i = 0; i < ctl->num; i++) {
                        xdp = &((struct xdp_buff *)ctl->ptr)[i];
                        tap_get_user_xdp(q, xdp);
index 10211ea60514005e50c7a6af22df86acd3330a85..d9993884a97d9919a386dfe3dd5bef3f240a2e05 100644 (file)
@@ -2561,7 +2561,8 @@ static int tun_sendmsg(struct socket *sock, struct msghdr *m, size_t total_len)
        if (!tun)
                return -EBADFD;
 
-       if (ctl && (ctl->type == TUN_MSG_PTR)) {
+       if (m->msg_controllen == sizeof(struct tun_msg_ctl) &&
+           ctl && ctl->type == TUN_MSG_PTR) {
                struct tun_page tpage;
                int n = ctl->num;
                int flush = 0;
index cec9173aac6f532d5c867e529a54796d6a520960..1058aba8d57343ae4e5d3c6624bf15c8c92ca09c 100644 (file)
@@ -472,6 +472,7 @@ static void vhost_tx_batch(struct vhost_net *net,
                goto signal_used;
 
        msghdr->msg_control = &ctl;
+       msghdr->msg_controllen = sizeof(ctl);
        err = sock->ops->sendmsg(sock, msghdr, 0);
        if (unlikely(err < 0)) {
                vq_err(&nvq->vq, "Fail to batch sending packets\n");