tcp: reject net_iov in zerocopy receive mapping hints
Subsystems (3)
PATCH 1/1 tcp: reject net_iov in zerocopy receive mapping hints
After copying a readable prefix, receive_fallback_to_copy() asks tcp_zerocopy_set_hint_for_skb() where page mapping can resume. If the next skb is unreadable, find_next_mappable_frag() passes its net_iov fragment to can_map_frag().
skb_frag_page() returns NULL for a net_iov, but can_map_frag() dereferences it in PageCompound(). A v7.2 KASAN run on a connected TCP socket with 64 readable bytes followed by a 4096-byte NET_IOV_DMABUF fragment reported:
BUG: KASAN: null-ptr-deref in can_map_frag tcp_zerocopy_receive -> can_map_frag Kernel panic - not syncing: KASAN: panic_on_warn set
The diagnostic inserted the net_iov directly because the test host has no devmem-capable NIC. Hardware end-to-end reachability remains untested and requires CONFIG_NET_DEVMEM plus a supported DMA-buf-bound RX queue.
Reject all net_iov fragments before skb_frag_page(). This covers both DMABUF and IOURING net_iov types while leaving page-backed checks unchanged. With the guard, the same queue copied the readable prefix, returned a 4096-byte skip hint, and completed without a fault.
---
Affected since v6.12-rc1; present in v7.2 and the pinned 2026-09-30 Torvalds, net, net-next and linux-next snapshots.
The existing combined fixed v7.2 build was warning-free. No isolated kernel build was run. Tested config SHA-256:f992c9fdb881ca95c467896791c52554719f6204cf06268cd92ac37c14c14f83
The reproducer is available privately on request and is omitted from this public AI-assisted report.
--- net/ipv4/tcp.c | 2 ++ 1 file changed, 2 insertions(+)
net/ipv4/tcp.c +2 -0
@@ -1908,6 +1908,8 @@ static bool can_map_frag(const skb_frag_t *frag)if (skb_frag_size (frag) !=PAGE_SIZE ||skb_frag_off (frag))return false; +if (skb_frag_is_net_iov (frag)) +return false; page =skb_frag_page (frag);
base-commit: 54518e0e827f4ca9229ae657022c60bf60f5c1bf
Signature · 1 line
2.55.0
Quoted 47 lines · Daehyeon Ko
After copying a readable prefix,
receive_fallback_to_copy()askstcp_zerocopy_set_hint_for_skb()where page mapping can resume. If the next skb is unreadable,find_next_mappable_frag()passes itsnet_iovfragment tocan_map_frag().
skb_frag_page()returns NULL for anet_iov, butcan_map_frag()dereferences it inPageCompound(). A v7.2 KASAN run on a connected TCP socket with 64 readable bytes followed by a 4096-byteNET_IOV_DMABUFfragment reported:BUG: KASAN: null-ptr-deref in can_map_frag tcp_zerocopy_receive -> can_map_frag Kernel panic - not syncing: KASAN: panic_on_warn setThe diagnostic inserted the
net_iovdirectly because the test host has no devmem-capable NIC. Hardware end-to-end reachability remains untested and requiresCONFIG_NET_DEVMEMplus a supported DMA-buf-bound RX queue.Reject all
net_iovfragments beforeskb_frag_page(). This covers both DMABUF and IOURINGnet_iovtypes while leaving page-backed checks unchanged. With the guard, the same queue copied the readable prefix, returned a 4096-byte skip hint, and completed without a fault.Fixes 9f6b619edf2e ("net: support non paged skb frags")Assisted-by LLMSigned-off-by Daehyeon Ko <[email protected]>---
Affected since v6.12-rc1; present in v7.2 and the pinned 2026-09-30 Torvalds, net, net-next and linux-next snapshots.The existing combined fixed v7.2 build was warning-free. No isolated kernel build was run. Tested config SHA-256:
f992c9fdb881ca95c467896791c52554719f6204cf06268cd92ac37c14c14f83The reproducer is available privately on request and is omitted from this public AI-assisted report.
--- net/ipv4/tcp.c | 2 ++ 1 file changed, 2 insertions(+)net/ipv4/tcp.c +0
-0
net/ipv4/tcp.c static bool can_map_frag(const skb_frag_t *frag) · line 1912
Quoted 5 lines
net/ipv4/tcp.c +2
-0@@ -1908,6 +1908,8 @@ static bool can_map_frag(const skb_frag_t *frag)if (skb_frag_size (frag) !=PAGE_SIZE ||skb_frag_off (frag))return false; +if (skb_frag_is_net_iov (frag)) +return false;
I think this should use skb_is_readable(). But you don't need this helper for frags. I wonder if we should add a readable helper for frags? I'm still holding out that in the future someone will add a net_iov type that is actually kmappable and readable.
But this is good enough.
Signature · 2 lines
Thanks, Mina
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 11 lines · On Wed, 30 Sep 2026 19:25:24 +0900 you wrote:
After copying a readable prefix,
receive_fallback_to_copy()askstcp_zerocopy_set_hint_for_skb()where page mapping can resume. If the next skb is unreadable,find_next_mappable_frag()passes itsnet_iovfragment tocan_map_frag().
skb_frag_page()returns NULL for anet_iov, butcan_map_frag()dereferences it inPageCompound(). A v7.2 KASAN run on a connected TCP socket with 64 readable bytes followed by a 4096-byteNET_IOV_DMABUFfragment reported:[...]
Here is the summary with links:
- [net] tcp: reject net_iov in zerocopy receive mapping hints
https://git.kernel.org/netdev/net/c/8b1f0af1fd5f
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html