Skip to content

Commit 1fd819e

Browse files
mstsirkindavem330
authored andcommitted
skbuff: skb_segment: orphan frags before copying
skb_segment copies frags around, so we need to copy them carefully to avoid accessing user memory after reporting completion to userspace through a callback. skb_segment doesn't normally happen on datapath: TSO needs to be disabled - so disabling zero copy in this case does not look like a big deal. Signed-off-by: Michael S. Tsirkin <[email protected]> Acked-by: Herbert Xu <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 1a4ceda commit 1fd819e

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

net/core/skbuff.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2854,6 +2854,7 @@ struct sk_buff *skb_segment(struct sk_buff *head_skb,
28542854
skb_frag_t *frag = skb_shinfo(head_skb)->frags;
28552855
unsigned int mss = skb_shinfo(head_skb)->gso_size;
28562856
unsigned int doffset = head_skb->data - skb_mac_header(head_skb);
2857+
struct sk_buff *frag_skb = head_skb;
28572858
unsigned int offset = doffset;
28582859
unsigned int tnl_hlen = skb_tnl_header_len(head_skb);
28592860
unsigned int headroom;
@@ -2898,6 +2899,7 @@ struct sk_buff *skb_segment(struct sk_buff *head_skb,
28982899
i = 0;
28992900
nfrags = skb_shinfo(list_skb)->nr_frags;
29002901
frag = skb_shinfo(list_skb)->frags;
2902+
frag_skb = list_skb;
29012903
pos += skb_headlen(list_skb);
29022904

29032905
while (pos < offset + len) {
@@ -2985,6 +2987,7 @@ struct sk_buff *skb_segment(struct sk_buff *head_skb,
29852987
i = 0;
29862988
nfrags = skb_shinfo(list_skb)->nr_frags;
29872989
frag = skb_shinfo(list_skb)->frags;
2990+
frag_skb = list_skb;
29882991

29892992
BUG_ON(!nfrags);
29902993

@@ -2999,6 +3002,9 @@ struct sk_buff *skb_segment(struct sk_buff *head_skb,
29993002
goto err;
30003003
}
30013004

3005+
if (unlikely(skb_orphan_frags(frag_skb, GFP_ATOMIC)))
3006+
goto err;
3007+
30023008
*nskb_frag = *frag;
30033009
__skb_frag_ref(nskb_frag);
30043010
size = skb_frag_size(nskb_frag);

0 commit comments

Comments
 (0)