net: Fix potential deadloop in skb_copy_ubufs()
Quoted 17 lines · Willem de Bruijn
Quoted 6 lines · linmiaohe
From: Miaohe Lin <[email protected]>
We could be trapped in deadloop when we try to copy userspace skb frags buffers to kernel with a cloned skb:
Reproduce code snippet:Quoted 7 lines
skb = alloc_skb(UBUF_DATA_LEN, GFP_ATOMIC); clone = skb_clone(skb, GFP_ATOMIC); skb_zcopy_set_nouarg(clone, NULL); pskb_expand_head(skb, 0, 0, GFP_ATOMIC);Catch this unexpected case and return
-EINVALinskb_orphan_frags()before we callskb_copy_ubufs()to fix it.Is this a hypothetical codepath?
Quoted 8 lines
skb zerocopy carefully tracks clone calls where necessary. See the call to
skb_orphan_fragsinskb_clone, and the implementation of that callee.The only caller of skb zerocopy with nouarg is
tpacket_fill_skb, as of commit5cd8d46ea156("packet: copy user buffers before orphan or clone").As the commit subject indicates, this sets
skb_zcopy_set_nouargexactly to be sure that any clone will trigger a copy of "zerocopy" user data to private kernel memory.No clone must happen between
alloc_skbandskb_zcopy_set_nouarg, indeed. But AFAIK, none exists.
Since we always call skb_orphan_frags in skb_clone, is it unnecessary to call skb_orphan_frags in pskb_expand_head when skb is cloned ?
Thanks.
Quoted 21 lines · linmiaohe
Quoted 19 lines · Willem de Bruijn
Quoted 6 lines · linmiaohe
From: Miaohe Lin <[email protected]>
We could be trapped in deadloop when we try to copy userspace skb frags buffers to kernel with a cloned skb:
Reproduce code snippet:Quoted 7 lines
skb = alloc_skb(UBUF_DATA_LEN, GFP_ATOMIC); clone = skb_clone(skb, GFP_ATOMIC); skb_zcopy_set_nouarg(clone, NULL); pskb_expand_head(skb, 0, 0, GFP_ATOMIC);Catch this unexpected case and return
-EINVALinskb_orphan_frags()before we callskb_copy_ubufs()to fix it.Is this a hypothetical codepath?
skb zerocopy carefully tracks clone calls where necessary. See the call to
skb_orphan_fragsinskb_clone, and the implementation of that callee.
Quoted 8 lines
Quoted 6 lines
The only caller of skb zerocopy with nouarg is
tpacket_fill_skb, as of commit5cd8d46ea156("packet: copy user buffers before orphan or clone").As the commit subject indicates, this sets
skb_zcopy_set_nouargexactly to be sure that any clone will trigger a copy of "zerocopy" user data to private kernel memory.No clone must happen between
alloc_skbandskb_zcopy_set_nouarg, indeed. But AFAIK, none exists.Since we always call
skb_orphan_fragsinskb_clone, is it unnecessary to callskb_orphan_fragsinpskb_expand_headwhen skb is cloned ?
Please give us a real case.
I fear that your patches are coming directly from some kind of automated tool, that really misses how the code is really used from _current_ code base, not _hypothetical_ one.
This is very time consuming. Please provide evidence first.
Thank you.