Netdev List
 help / color / mirror / Atom feed
From: Mina Almasry <almasrymina@google.com>
To: netdev@vger.kernel.org
Cc: Mina Almasry <almasrymina@google.com>,
	Eric Dumazet <edumazet@kernel.org>,
	 Neal Cardwell <ncardwell@google.com>,
	Kuniyuki Iwashima <kuniyu@google.com>,
	 "David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	 Simon Horman <horms@kernel.org>,
	Stanislav Fomichev <sdf@fomichev.me>,
	Kaiyuan Zhang <kaiyuanz@google.com>,
	 Willem de Bruijn <willemb@google.com>,
	Daniel Borkmann <daniel@iogearbox.net>,
	 Josef Bacik <josef@toxicpanda.com>,
	Stanislav Fomichev <sdf.kernel@gmail.com>,
	 Dragos Tatulea <dtatulea@nvidia.com>,
	Pavel Begunkov <asml.silence@gmail.com>,
	 Bobby Eshleman <bobbyeshleman@meta.com>
Subject: [PATCH net-next v6 0/7] net: prevent mixing incompatible memory providers in skbs
Date: Fri, 20 Nov 2026 20:14:01 +0000	[thread overview]
Message-ID: <20261120201408.3445445-1-almasrymina@google.com> (raw)

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 <sdf@fomichev.me> 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


             reply	other threads:[~2026-11-20 20:14 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 20:14 Mina Almasry [this message]
2026-11-20 20:14 ` [PATCH net-next v6 1/7] net: fix skb->unreadable propagation in skb_split() and skb_shift() Mina Almasry
2026-11-20 20:14 ` [PATCH net-next v6 2/7] net: devmem: prevent mixing TX bindings and reject non-devmem xmit Mina Almasry
2026-11-20 20:14 ` [PATCH net-next v6 3/7] tcp: fix unreadable net_iov handling in tcp_clone_payload() Mina Almasry
2026-11-20 20:14 ` [PATCH net-next v6 4/7] tcp: propagate skb_zcopy() uarg in tcp_mtu_probe() Mina Almasry
2026-11-20 20:14 ` [PATCH net-next v6 5/7] net: kunit: attach net_iov frags to target skbs in unreadable tests Mina Almasry
2026-11-20 20:14 ` [PATCH net-next v6 6/7] net: prevent mixing frags from different memory providers or bindings Mina Almasry
2026-11-20 20:14 ` [PATCH net-next v6 7/7] net: kunit: test incompatible memory provider rejection Mina Almasry

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261120201408.3445445-1-almasrymina@google.com \
    --to=almasrymina@google.com \
    --cc=asml.silence@gmail.com \
    --cc=bobbyeshleman@meta.com \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=dtatulea@nvidia.com \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=josef@toxicpanda.com \
    --cc=kaiyuanz@google.com \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=ncardwell@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sdf.kernel@gmail.com \
    --cc=sdf@fomichev.me \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox