Skip to content

Commit 268b790

Browse files
wdebruijdavem330
authored andcommitted
skbuff: orphan frags before zerocopy clone
Call skb_zerocopy_clone after skb_orphan_frags, to avoid duplicate calls to skb_uarg(skb)->callback for the same data. skb_zerocopy_clone associates skb_shinfo(skb)->uarg from frag_skb with each segment. This is only safe for uargs that do refcounting, which is those that pass skb_orphan_frags without dropping their shared frags. For others, skb_orphan_frags drops the user frags and sets the uarg to NULL, after which sock_zerocopy_clone has no effect. Qemu hangs were reported due to duplicate vhost_net_zerocopy_callback calls for the same data causing the vhost_net_ubuf_ref_>refcount to drop below zero. Link: http://lkml.kernel.org/r/<CAF=yD-LWyCD4Y0aJ9O0e_CHLR+3JOeKicRRTEVCPxgw4XOcqGQ@mail.gmail.com> Fixes: 1f8b977 ("sock: enable MSG_ZEROCOPY") Reported-by: Andreas Hartmann <[email protected]> Reported-by: David Hill <[email protected]> Signed-off-by: Willem de Bruijn <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 513674b commit 268b790

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

net/core/skbuff.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3654,8 +3654,6 @@ struct sk_buff *skb_segment(struct sk_buff *head_skb,
36543654

36553655
skb_shinfo(nskb)->tx_flags |= skb_shinfo(head_skb)->tx_flags &
36563656
SKBTX_SHARED_FRAG;
3657-
if (skb_zerocopy_clone(nskb, head_skb, GFP_ATOMIC))
3658-
goto err;
36593657

36603658
while (pos < offset + len) {
36613659
if (i >= nfrags) {
@@ -3681,6 +3679,8 @@ struct sk_buff *skb_segment(struct sk_buff *head_skb,
36813679

36823680
if (unlikely(skb_orphan_frags(frag_skb, GFP_ATOMIC)))
36833681
goto err;
3682+
if (skb_zerocopy_clone(nskb, frag_skb, GFP_ATOMIC))
3683+
goto err;
36843684

36853685
*nskb_frag = *frag;
36863686
__skb_frag_ref(nskb_frag);

0 commit comments

Comments
 (0)