net: core: check skb_frags_readable before uncloning in skb_copy_ubufs
Subsystems (2)
PATCH 1/2 net: core: check skb_frags_readable before uncloning in skb_copy_ubufs
skb_copy_ubufs drops clones and modifies the SKB via pskb_expand_head() before checking for !skb_frags_readable(skb). This alters the SKB geometry prior to throwing an -EFAULT on an invalid SKB. Check readability first.
---
Note to sashiko: if you find pre-existing issues, mark them clearly as pre-existing.
--- net/core/skbuff.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/core/skbuff.c +3 -3
@@ -2001,12 +2001,12 @@ int skb_copy_ubufs(struct sk_buff *skb, gfp_t gfp_mask)int i, order, psize, new_frags;u32 d_off; -if (skb_shared (skb) ||skb_unclone (skb, gfp_mask)) -return -EINVAL ; -if (!skb_frags_readable (skb))return -EFAULT ; +if (skb_shared (skb) ||skb_unclone (skb, gfp_mask)) +return -EINVAL ; +if (!num_frags) goto release;
base-commit: 7cbfb180945ce529608e4d4e24a6d483699fab1e
Signature · 1 line
2.55.0.766.g2966f0265a-goog
PATCH 2/2 net: core: fix head-page leak in skb_zerocopy
When skb_orphan_frags() throws -ENOMEM, skb_copy_ubufs() may have already reallocated and replaced 'from->head'. Accessing from->head to drop the old refcount leaks the original head page, and erroneously puts an unrelated new buffer. Use the local 'page' tracker variable instead to drop the reference properly.
---
Note to sashiko: if you find pre-existing issues, mark them clearly as pre-existing.
--- net/core/skbuff.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/core/skbuff.c +2 -2
@@ -3907,7 +3907,7 @@ skb_zerocopy(struct sk_buff *to, struct sk_buff *from, int len, int hlen) }if (!skb_frags_readable (from) && j >0 && len) { -put_page (virt_to_head_page (from->head)); +put_page (page);return -EFAULT ; }
@@ -3916,7 +3916,7 @@ skb_zerocopy(struct sk_buff *to, struct sk_buff *from, int len, int hlen)if (unlikely (skb_orphan_frags (from,GFP_ATOMIC ))) {skb_tx_error (from);if (j >0 ) -put_page (virt_to_head_page (from->head)); +put_page (page);return -ENOMEM ; }skb_zerocopy_clone (to, from,GFP_ATOMIC );
Signature · 1 line
2.55.0.766.g2966f0265a-goog
Paolo Abeni
maintainerRe: [PATCH net v1 2/2] net: core: fix head-page leak in skb_zerocopy
Quoted 9 lines · Mina Almasry
When
skb_orphan_frags()throws-ENOMEM,skb_copy_ubufs()may have already reallocated and replaced 'from->head'. Accessingfrom->headto drop the old refcount leaks the original head page, and erroneously puts an unrelated new buffer. Use the local 'page' tracker variable instead to drop the reference properly.Fixes 36d5fe6a0007 ("core, nfqueue, openvswitch: Orphan frags in skb_zerocopy and handle errors")Signed-off-by Mina Almasry <[email protected]>
Note that there must be no empty lines in the tag area; no need to repost, I'll fix it while applying.
/P
This series was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:
Quoted 8 lines · On Sun, 23 Aug 2026 18:36:01 +0000 you wrote:
skb_copy_ubufsdrops clones and modifies the SKB viapskb_expand_head()before checking for !skb_frags_readable(skb). This alters the SKB geometry prior to throwing an-EFAULTon an invalid SKB. Check readability first.Fixes 65249feb6b3d ("net: add support for skbs with unreadable frags")[...]
Here is the summary with links:
- [net,v1,1/2] net: core: check skb_frags_readable before uncloning in skb_copy_ubufs
https://git.kernel.org/netdev/net/c/00e11ee9831b - [net,v1,2/2] net: core: fix head-page leak in skb_zerocopy https://git.kernel.org/netdev/net/c/97148bcb7511
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html