# \[PATCH net-next v6 0/7\] net: prevent mixing incompatible memory providers in skbs

- From: Mina Almasry \<hidden\>
- Date: 2026-11-20 20:14:10 
- List: netdev
- Page: https://ratatoskr.run/netdev/2026/11/17995161
- Thread: https://ratatoskr.run/netdev/2026/11/17995161/t.md

```text
Enforce that all fragments in a nonlinear skb come from compatible
memory providers (and for devmem, the exact same binding).

Patch 1 fixes skb->unreadable propagation in skb_split() and skb_shift().
Patch 2 adds net_devmem_skb_binding() to prevent mixing different devmem
bindings in TX skbs (tcp_sendmsg_locked() and
zerocopy_fill_skb_from_devmem()) and rejects non-devmem unreadable
net_iovs (such as forwarded io_uring zcrx RX skbs) in
validate_xmit_unreadable_skb().
Patch 3 fixes skb->unreadable propagation and netmem comparison in
tcp_clone_payload().
Patch 4 propagates the skb_zcopy() uarg in tcp_mtu_probe() /
tcp_clone_payload() and rejects coalescing across different uargs.
Patch 5 updates existing KUnit tests so target skbs carry a realistic
compatible net_iov fragment before shifting or coalescing.
Patch 6 adds skb_mem_provider_compat() to prevent mixing incompatible
memory providers or devmem bindings across skb_try_coalesce(),
skb_gro_receive(), skb_gro_receive_list(), skb_segment(),
tcp_skb_can_collapse(), and skb_shift().
Patch 7 adds KUnit coverage verifying rejection of cross-binding and
cross-provider coalescing.

Fast-path and cacheline analysis:
skb->unreadable is a 1-bit flag inside struct_group(headers, ...)
alongside ip_summed, remcsum_offload, encapsulation, decrypted,
slow_gro, csum, and hash. Depending on Kconfig (e.g. CONFIG_NF_CONNTRACK
and CONFIG_SKB_EXTENSIONS), struct_group(headers, ...) starts in
cacheline 1 or cacheline 2 of struct sk_buff, and in all configs those
header fields are already loaded on both skbs in GRO and TCP
coalescing/collapse/sendmsg paths. skb_mem_provider_compat() checks only
likely(skb_frags_readable(skb1) && skb_frags_readable(skb2)) inline and
moves all skb_shinfo/frags[0]/net_iov inspection out-of-line into
__skb_mem_provider_compat(), so readable-only traffic loads zero extra
cachelines and avoids icache bloat:

- skb_try_coalesce() and tcp_skb_can_collapse(): already check
  skb_frags_readable() on both skbs (0 extra cachelines; unreadable
  provider check stays out-of-line).
- tcp_skb_can_collapse_rx(): untouched (all callers already guard
  readability or immediately call skb_try_coalesce()).
- skb_shift(): uses DEBUG_NET_WARN_ON_ONCE() alongside the existing
  pp_recycle and decrypted checks (0 instructions when
  CONFIG_DEBUG_NET=n; all callers already check tcp_skb_can_collapse()).
- tcp_sendmsg_locked(): checks unlikely(binding) before calling
  net_devmem_skb_binding(), keeping normal TX (binding == NULL)
  straight-line with 0 extra taken branches and 0 extra cachelines.
- skb_gro_receive() and skb_gro_receive_list(): adds two bit tests on
  skb->unreadable in the already-loaded headers group cacheline
  (0 extra cachelines).

v5 -> v6:
- Rebase onto net-next/main after the net -> net-next merge, resolving
  the net/core/net_test.c conflict (Jakub Kicinski).
- Split devmem TX binding & validate_xmit_unreadable_skb() fixes
  (patch 2), tcp_clone_payload() unreadable net_iov fix (patch 3), and
  KUnit test changes (patches 5 and 7) into separate patches
  (Jakub Kicinski).
- Keep shinfo and niov locals in validate_xmit_unreadable_skb() to keep
  the diff minimal (Stanislav Fomichev).
- Minimize fast-path impact: move unreadable provider comparison
  out-of-line into __skb_mem_provider_compat(), drop redundant
  tcp_skb_can_collapse_rx() check and skb_frags_can_coalesce() wrapper,
  use DEBUG_NET_WARN_ON_ONCE() in skb_shift(), and keep
  tcp_sendmsg_locked() non-devmem path branch-minimal (Jakub Kicinski).
- Also reject mixing incompatible frag_list providers in skb_segment().
- Drop the head_frag-on-unreadable rejection hunks from
  skb_try_coalesce() and skb_gro_receive() to address in a separate
  follow-up series.
- Add fast-path and cacheline analysis above.
- Collect Acked-by: Stanislav Fomichev [ref] on unchanged
  patches 1 and 4.
- v5: https://lore.kernel.org/netdev/20261115004003.3695475-1-almasrymina@google.com/

v4 -> v5:
- Drop skb_has_net_iovs() and check skb_frags_readable() and
  skb_shinfo(skb)->nr_frags directly in skb_net_iov_provider() and
  net_devmem_skb_binding().
- Add patch 3 to propagate the skb_zcopy() uarg in tcp_mtu_probe() /
  tcp_clone_payload().
- v4: https://lore.kernel.org/netdev/20261108013838.1454450-1-almasrymina@google.com/

v3 -> v4:
- Fold skb_shinfo(skb)->nr_frags into skb_has_net_iovs() and drop
  redundant nr_frags checks in skb_net_iov_provider() and
  net_devmem_skb_binding() (Stanislav Fomichev).
- Remove the empty-skb check and redundant !skb_has_net_iovs(skb1)
  branch from skb_mem_provider_compat(), and add a comment on the
  early skb_has_net_iovs() check (Stanislav Fomichev).
- Propagate skb->unreadable and compare skb_frag_netmem() directly in
  tcp_clone_payload() instead of rejecting unreadable skbs in
  tcp_can_coalesce_send_queue_head().
- v3: https://lore.kernel.org/netdev/20261104042521.3979880-1-almasrymina@google.com/

v2 -> v3:
- Drop patch 2 ("netmem: store memory provider private pointer directly
  in struct net_iov") and compare net_iov_owner(niov) (for devmem) /
  niov->desc.pp (for other net_iov providers) directly in
  skb_mem_provider_compat() (Stanislav Fomichev).
- Squash the skb_frags_can_coalesce() helper patch into its caller patch
  (Stanislav Fomichev).
- v2: https://lore.kernel.org/netdev/20261102231827.4088254-1-almasrymina@google.com/

v1 -> v2:
- Generalize the check across TX, TCP collapse, GRO, IP defrag,
  skb_shift(), and skb_try_coalesce() by storing mp_priv directly in
  struct net_iov and introducing skb_frags_can_coalesce().
- Fix skb->unreadable propagation in skb_split() and skb_shift().
- Add KUnit coverage for cross-provider and cross-binding rejection.
- v1: https://lore.kernel.org/netdev/20261008034027.1403188-1-almasrymina@google.com/

Mina Almasry (7):
  net: fix skb->unreadable propagation in skb_split() and skb_shift()
  net: devmem: prevent mixing TX bindings and reject non-devmem xmit
  tcp: fix unreadable net_iov handling in tcp_clone_payload()
  tcp: propagate skb_zcopy() uarg in tcp_mtu_probe()
  net: kunit: attach net_iov frags to target skbs in unreadable tests
  net: prevent mixing frags from different memory providers or bindings
  net: kunit: test incompatible memory provider rejection

 include/linux/skbuff.h | 18 +++++++++++++
 include/net/tcp.h      |  2 +-
 net/core/datagram.c    |  4 +--
 net/core/dev.c         |  8 +++---
 net/core/devmem.h      | 22 +++++++++++++++
 net/core/gro.c         |  6 +++++
 net/core/net_test.c    | 61 +++++++++++++++++++++++++++++++++++++-----
 net/core/skbuff.c      | 57 +++++++++++++++++++++++++++++++++++++--
 net/ipv4/tcp.c         |  4 ++-
 net/ipv4/tcp_output.c  |  9 +++++--
 10 files changed, 173 insertions(+), 18 deletions(-)


base-commit: 2208ab00f4f213ade91ab775e7f8c4dacdcc856e
-- 
2.56.1.750.gf70dc682cf-goog

```
