]> git.proxmox.com Git - mirror_ubuntu-disco-kernel.git/commitdiff
net: correct zerocopy refcnt with udp MSG_MORE
authorWillem de Bruijn <willemb@google.com>
Thu, 30 May 2019 22:01:21 +0000 (18:01 -0400)
committerStefan Bader <stefan.bader@canonical.com>
Tue, 13 Aug 2019 12:11:36 +0000 (14:11 +0200)
BugLink: https://bugs.launchpad.net/bugs/1837518
[ Upstream commit 100f6d8e09905c59be45b6316f8f369c0be1b2d8 ]

TCP zerocopy takes a uarg reference for every skb, plus one for the
tcp_sendmsg_locked datapath temporarily, to avoid reaching refcnt zero
as it builds, sends and frees skbs inside its inner loop.

UDP and RAW zerocopy do not send inside the inner loop so do not need
the extra sock_zerocopy_get + sock_zerocopy_put pair. Commit
52900d22288ed ("udp: elide zerocopy operation in hot path") introduced
extra_uref to pass the initial reference taken in sock_zerocopy_alloc
to the first generated skb.

But, sock_zerocopy_realloc takes this extra reference at the start of
every call. With MSG_MORE, no new skb may be generated to attach the
extra_uref to, so refcnt is incorrectly 2 with only one skb.

Do not take the extra ref if uarg && !tcp, which implies MSG_MORE.
Update extra_uref accordingly.

This conditional assignment triggers a false positive may be used
uninitialized warning, so have to initialize extra_uref at define.

Changes v1->v2: fix typo in Fixes SHA1

Fixes: 52900d22288e7 ("udp: elide zerocopy operation in hot path")
Reported-by: syzbot <syzkaller@googlegroups.com>
Diagnosed-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
net/core/skbuff.c
net/ipv4/ip_output.c
net/ipv6/ip6_output.c

index 40796b8bf820450f5d0cce38986bd29137e2fd05..e5bfd42fd083b5a8743246a2ad8c1d1c766ce115 100644 (file)
@@ -1001,7 +1001,11 @@ struct ubuf_info *sock_zerocopy_realloc(struct sock *sk, size_t size,
                        uarg->len++;
                        uarg->bytelen = bytelen;
                        atomic_set(&sk->sk_zckey, ++next);
-                       sock_zerocopy_get(uarg);
+
+                       /* no extra ref when appending to datagram (MSG_MORE) */
+                       if (sk->sk_type == SOCK_STREAM)
+                               sock_zerocopy_get(uarg);
+
                        return uarg;
                }
        }
index e8bb2e85c5a471f018193b8a08735606ec7f0526..ac770940adb949f285b3514e734191fca27bc90f 100644 (file)
@@ -883,7 +883,7 @@ static int __ip_append_data(struct sock *sk,
        int csummode = CHECKSUM_NONE;
        struct rtable *rt = (struct rtable *)cork->dst;
        unsigned int wmem_alloc_delta = 0;
-       bool paged, extra_uref;
+       bool paged, extra_uref = false;
        u32 tskey = 0;
 
        skb = skb_peek_tail(queue);
@@ -923,7 +923,7 @@ static int __ip_append_data(struct sock *sk,
                uarg = sock_zerocopy_realloc(sk, length, skb_zcopy(skb));
                if (!uarg)
                        return -ENOBUFS;
-               extra_uref = true;
+               extra_uref = !skb;      /* only extra ref if !MSG_MORE */
                if (rt->dst.dev->features & NETIF_F_SG &&
                    csummode == CHECKSUM_PARTIAL) {
                        paged = true;
index e71227390becb7cc80f489ff44bb244ab9718142..de16c2e343ef9d02a69ede3c7920bdabcdc024b8 100644 (file)
@@ -1269,7 +1269,7 @@ static int __ip6_append_data(struct sock *sk,
        int csummode = CHECKSUM_NONE;
        unsigned int maxnonfragsize, headersize;
        unsigned int wmem_alloc_delta = 0;
-       bool paged, extra_uref;
+       bool paged, extra_uref = false;
 
        skb = skb_peek_tail(queue);
        if (!skb) {
@@ -1338,7 +1338,7 @@ emsgsize:
                uarg = sock_zerocopy_realloc(sk, length, skb_zcopy(skb));
                if (!uarg)
                        return -ENOBUFS;
-               extra_uref = true;
+               extra_uref = !skb;      /* only extra ref if !MSG_MORE */
                if (rt->dst.dev->features & NETIF_F_SG &&
                    csummode == CHECKSUM_PARTIAL) {
                        paged = true;