Netdev List
 help / color / mirror / Atom feed
* [PATCH net-next v6 0/7] net: prevent mixing incompatible memory providers in skbs
@ 2026-11-20 20:14 Mina Almasry
  2026-11-20 20:14 ` [PATCH net-next v6 1/7] net: fix skb->unreadable propagation in skb_split() and skb_shift() Mina Almasry
                   ` (6 more replies)
  0 siblings, 7 replies; 17+ messages in thread
From: Mina Almasry @ 2026-11-20 20:14 UTC (permalink / raw)
  To: netdev
  Cc: Mina Almasry, Eric Dumazet, Neal Cardwell, Kuniyuki Iwashima,
	David S. Miller, Jakub Kicinski, Paolo Abeni, Simon Horman,
	Stanislav Fomichev, Kaiyuan Zhang, Willem de Bruijn,
	Daniel Borkmann, Josef Bacik, Stanislav Fomichev, Dragos Tatulea,
	Pavel Begunkov, Bobby Eshleman

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


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH net-next v6 1/7] net: fix skb->unreadable propagation in skb_split() and skb_shift()
  2026-11-20 20:14 [PATCH net-next v6 0/7] net: prevent mixing incompatible memory providers in skbs Mina Almasry
@ 2026-11-20 20:14 ` 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
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 17+ messages in thread
From: Mina Almasry @ 2026-11-20 20:14 UTC (permalink / raw)
  To: netdev
  Cc: Mina Almasry, Eric Dumazet, Neal Cardwell, Kuniyuki Iwashima,
	David S. Miller, Jakub Kicinski, Paolo Abeni, Simon Horman,
	Stanislav Fomichev, Kaiyuan Zhang, Willem de Bruijn,
	Daniel Borkmann, Josef Bacik, Stanislav Fomichev, Dragos Tatulea,
	Pavel Begunkov, Bobby Eshleman

skb_split() and skb_shift() do not accurately maintain skb->unreadable
when moving fragments between skbs:

- skb_split_inside_header() moves all fragments out of skb into skb1
  (leaving skb with nr_frags == 0 and only host-readable linear memory),
  but leaves skb->unreadable set on skb.
- skb_split_no_header() unconditionally copies skb->unreadable to skb1
  even if 0 fragments were moved to skb1 (k == 0), and leaves
  skb->unreadable set on skb when splitting at skb_headlen(skb) moves
  all fragments into skb1 (!skb_shinfo(skb)->nr_frags).
- skb_shift() does not clear skb->unreadable after all fragments are
  shifted out of skb.

Fix all three cases so skb->unreadable accurately tracks whether the
remaining fragments in each skb are unreadable.

This issue is theoretical and was found by manual code inspection and
LLM review; it was not triggered in production. Verified with the
net_core KUnit test suite; not tested on real hardware.

Fixes: 65249feb6b3d ("net: add support for skbs with unreadable frags")
Signed-off-by: Mina Almasry <almasrymina@google.com>
Acked-by: Stanislav Fomichev <sdf@fomichev.me>
---
 net/core/skbuff.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 1c921383aed9..aac61fbe419f 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -4508,6 +4508,7 @@ static inline void skb_split_inside_header(struct sk_buff *skb,
 
 	skb_shinfo(skb1)->nr_frags = skb_shinfo(skb)->nr_frags;
 	skb1->unreadable	   = skb->unreadable;
+	skb->unreadable		   = 0;
 	skb_shinfo(skb)->nr_frags  = 0;
 	skb1->data_len		   = skb->data_len;
 	skb1->len		   += skb1->data_len;
@@ -4556,7 +4557,10 @@ static inline void skb_split_no_header(struct sk_buff *skb,
 	}
 	skb_shinfo(skb1)->nr_frags = k;
 
-	skb1->unreadable = skb->unreadable;
+	if (k)
+		skb1->unreadable = skb->unreadable;
+	if (!skb_shinfo(skb)->nr_frags)
+		skb->unreadable = 0;
 }
 
 /**
@@ -4730,6 +4734,8 @@ int skb_shift(struct sk_buff *tgt, struct sk_buff *skb, int shiftlen)
 	skb->ip_summed = CHECKSUM_PARTIAL;
 
 	skb_shinfo(tgt)->flags |= skb_shinfo(skb)->flags & SKBFL_SHARED_FRAG;
+	if (!skb_shinfo(skb)->nr_frags && !skb_has_frag_list(skb))
+		skb->unreadable = 0;
 
 	skb_len_add(skb, -shiftlen);
 	skb_len_add(tgt, shiftlen);
-- 
2.56.1.750.gf70dc682cf-goog


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH net-next v6 2/7] net: devmem: prevent mixing TX bindings and reject non-devmem xmit
  2026-11-20 20:14 [PATCH net-next v6 0/7] net: prevent mixing incompatible memory providers in skbs Mina Almasry
  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 ` Mina Almasry
  2026-11-23 17:29   ` Stanislav Fomichev
  2026-11-20 20:14 ` [PATCH net-next v6 3/7] tcp: fix unreadable net_iov handling in tcp_clone_payload() Mina Almasry
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 17+ messages in thread
From: Mina Almasry @ 2026-11-20 20:14 UTC (permalink / raw)
  To: netdev
  Cc: Mina Almasry, Eric Dumazet, Neal Cardwell, Kuniyuki Iwashima,
	David S. Miller, Jakub Kicinski, Paolo Abeni, Simon Horman,
	Stanislav Fomichev, Kaiyuan Zhang, Willem de Bruijn,
	Daniel Borkmann, Josef Bacik, Stanislav Fomichev, Dragos Tatulea,
	Pavel Begunkov, Bobby Eshleman

Two devmem TX paths do not validate the fragment memory provider or
binding strictly enough:

- When sending with MSG_ZEROCOPY and SCM_DEVMEM_DMABUF across multiple
  devmem TX bindings on the same TCP socket, tcp_sendmsg_locked() and
  zerocopy_fill_skb_from_devmem() only check skb_frags_readable(skb),
  allowing fragments from two different devmem TX bindings to be
  appended into the same skb.
- validate_xmit_unreadable_skb() checks the binding direction and
  target device only when net_is_devmem_iov(niov) is true, allowing
  unreadable skbs backed by non-devmem net_iov providers (such as
  forwarded io_uring zcrx RX skbs) to bypass validation on
  NETMEM_TX_DMA devices. Using netmem_to_net_iov() also assumes
  frags[0] is a net_iov without checking first.

Add net_devmem_skb_binding() to return the devmem binding of an skb's
first fragment (all fragments in an skb share the same memory source).
In tcp_sendmsg_locked(), check net_devmem_skb_binding(skb) != binding
only when a devmem binding is active so normal non-devmem TX keeps a
single unlikely(!skb_frags_readable(skb)) check with no extra taken
branch. In zerocopy_fill_skb_from_devmem(), check
net_devmem_skb_binding(skb) != binding and return -EMSGSIZE instead of
-EFAULT so tcp_sendmsg_locked() starts a new segment instead of
aborting the send with an error. In validate_xmit_unreadable_skb(), use
skb_frag_net_iov() and drop unreadable skbs on NETMEM_TX_DMA devices
unless frags[0] is a DMA_TO_DEVICE devmem net_iov bound to dev.

This issue is theoretical and was found by manual code inspection and
LLM review; it was not triggered in production. Compile-tested and
boot-tested with the net_core KUnit test suite; not tested on real
hardware.

Fixes: bd61848900bf ("net: devmem: Implement TX path")
Fixes: ae28cb114727 ("net: check for driver support in netmem TX")
Signed-off-by: Mina Almasry <almasrymina@google.com>
---
 net/core/datagram.c |  4 ++--
 net/core/dev.c      |  8 ++++----
 net/core/devmem.h   | 22 ++++++++++++++++++++++
 net/ipv4/tcp.c      |  4 +++-
 4 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/net/core/datagram.c b/net/core/datagram.c
index 489d92fe6dae..9d4192b1042e 100644
--- a/net/core/datagram.c
+++ b/net/core/datagram.c
@@ -712,8 +712,8 @@ zerocopy_fill_skb_from_devmem(struct sk_buff *skb, struct iov_iter *from,
 	size_t virt_addr, size, off;
 	struct net_iov *niov;
 
-	if (i && skb_frags_readable(skb))
-		return -EFAULT;
+	if (i && net_devmem_skb_binding(skb) != binding)
+		return -EMSGSIZE;
 
 	/* Devmem filling works by taking an IOVEC from the user where the
 	 * iov_addrs are interpreted as an offset in bytes into the dma-buf to
diff --git a/net/core/dev.c b/net/core/dev.c
index 1a63f6b939f7..5bb300083b7b 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -4189,10 +4189,10 @@ static struct sk_buff *validate_xmit_unreadable_skb(struct sk_buff *skb,
 
 	/* All net_iovs in an unreadable skb share the same binding. */
 	if (shinfo->nr_frags > 0) {
-		niov = netmem_to_net_iov(skb_frag_netmem(&shinfo->frags[0]));
-		if (net_is_devmem_iov(niov) &&
-		    (net_devmem_iov_binding(niov)->direction != DMA_TO_DEVICE ||
-		     READ_ONCE(net_devmem_iov_binding(niov)->dev) != dev))
+		niov = skb_frag_net_iov(&shinfo->frags[0]);
+		if (!niov || !net_is_devmem_iov(niov) ||
+		    net_devmem_iov_binding(niov)->direction != DMA_TO_DEVICE ||
+		    READ_ONCE(net_devmem_iov_binding(niov)->dev) != dev)
 			goto out_free;
 	}
 
diff --git a/net/core/devmem.h b/net/core/devmem.h
index c4f476947dfa..c685288f5021 100644
--- a/net/core/devmem.h
+++ b/net/core/devmem.h
@@ -10,6 +10,7 @@
 #ifndef _NET_DEVMEM_H
 #define _NET_DEVMEM_H
 
+#include <linux/skbuff.h>
 #include <net/net_namespace.h>
 #include <net/netmem.h>
 #include <net/netdev_netlink.h>
@@ -117,6 +118,21 @@ net_devmem_iov_binding(const struct net_iov *niov)
 			    struct net_devmem_dmabuf_binding, area);
 }
 
+static inline struct net_devmem_dmabuf_binding *
+net_devmem_skb_binding(const struct sk_buff *skb)
+{
+	struct net_iov *niov;
+
+	if (skb_frags_readable(skb) || !skb_shinfo(skb)->nr_frags)
+		return NULL;
+
+	niov = skb_frag_net_iov(&skb_shinfo(skb)->frags[0]);
+	if (!niov || !net_is_devmem_iov(niov))
+		return NULL;
+
+	return net_devmem_iov_binding(niov);
+}
+
 static inline u32 net_devmem_iov_binding_id(const struct net_iov *niov)
 {
 	return net_devmem_iov_binding(niov)->id;
@@ -250,6 +266,12 @@ net_devmem_iov_binding(const struct net_iov *niov)
 {
 	return NULL;
 }
+
+static inline struct net_devmem_dmabuf_binding *
+net_devmem_skb_binding(const struct sk_buff *skb)
+{
+	return NULL;
+}
 #endif
 
 #endif /* _NET_DEVMEM_H */
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index d510e982dcea..94dee9f1017a 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -1254,7 +1254,9 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size)
 		trace_tcp_sendmsg_locked(sk, msg, skb, size_goal);
 
 		if (copy <= 0 || !tcp_skb_can_collapse_to(skb) ||
-		    unlikely(skb_frags_readable(skb) != !binding)) {
+		    (unlikely(binding) ?
+		     net_devmem_skb_binding(skb) != binding :
+		     unlikely(!skb_frags_readable(skb)))) {
 			bool first_skb;
 
 new_segment:
-- 
2.56.1.750.gf70dc682cf-goog


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH net-next v6 3/7] tcp: fix unreadable net_iov handling in tcp_clone_payload()
  2026-11-20 20:14 [PATCH net-next v6 0/7] net: prevent mixing incompatible memory providers in skbs Mina Almasry
  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 ` Mina Almasry
  2026-11-23 17:29   ` Stanislav Fomichev
  2026-11-24  8:14   ` netdev-bot+sashiko
  2026-11-20 20:14 ` [PATCH net-next v6 4/7] tcp: propagate skb_zcopy() uarg in tcp_mtu_probe() Mina Almasry
                   ` (3 subsequent siblings)
  6 siblings, 2 replies; 17+ messages in thread
From: Mina Almasry @ 2026-11-20 20:14 UTC (permalink / raw)
  To: netdev
  Cc: Mina Almasry, Eric Dumazet, Neal Cardwell, Kuniyuki Iwashima,
	David S. Miller, Jakub Kicinski, Paolo Abeni, Simon Horman,
	Stanislav Fomichev, Kaiyuan Zhang, Willem de Bruijn,
	Daniel Borkmann, Josef Bacik, Stanislav Fomichev, Dragos Tatulea,
	Pavel Begunkov, Bobby Eshleman

tcp_clone_payload() clones fragments from the TCP write queue into an
MTU probe skb, but does not propagate skb->unreadable and compares
adjacent fragments using skb_frag_page(). On devmem TX skbs backed by
unreadable net_iovs, skb_frag_page() returns NULL for every fragment,
causing distinct net_iovs with contiguous offsets to compare equal as
NULL == NULL and be merged incorrectly, while leaving to->unreadable
clear on the resulting probe skb.

Propagate skb->unreadable to the probe skb and compare fragments via
skb_frag_netmem().

This issue is theoretical and was found by manual code inspection and
LLM review; it was not triggered in production. Verified with the
net_core KUnit test suite; not tested on real hardware.

Fixes: bd61848900bf ("net: devmem: Implement TX path")
Signed-off-by: Mina Almasry <almasrymina@google.com>
---
 net/ipv4/tcp_output.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 08d0d4a639fe..19059d03152e 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -2696,8 +2696,10 @@ static int tcp_clone_payload(struct sock *sk, struct sk_buff *to,
 				     probe_size - len);
 			len += todo;
 			skb_shinfo(to)->flags |= skb_shinfo(skb)->flags & SKBFL_SHARED_FRAG;
+			to->unreadable |= skb->unreadable;
 			if (lastfrag &&
-			    skb_frag_page(fragfrom) == skb_frag_page(lastfrag) &&
+			    skb_frag_netmem(fragfrom) ==
+			    skb_frag_netmem(lastfrag) &&
 			    skb_frag_off(fragfrom) == skb_frag_off(lastfrag) +
 						      skb_frag_size(lastfrag)) {
 				skb_frag_size_add(lastfrag, todo);
-- 
2.56.1.750.gf70dc682cf-goog


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH net-next v6 4/7] tcp: propagate skb_zcopy() uarg in tcp_mtu_probe()
  2026-11-20 20:14 [PATCH net-next v6 0/7] net: prevent mixing incompatible memory providers in skbs Mina Almasry
                   ` (2 preceding siblings ...)
  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 ` Mina Almasry
  2026-11-24  8:14   ` netdev-bot+sashiko
  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
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 17+ messages in thread
From: Mina Almasry @ 2026-11-20 20:14 UTC (permalink / raw)
  To: netdev
  Cc: Mina Almasry, Eric Dumazet, Neal Cardwell, Kuniyuki Iwashima,
	David S. Miller, Jakub Kicinski, Paolo Abeni, Simon Horman,
	Stanislav Fomichev, Kaiyuan Zhang, Willem de Bruijn,
	Daniel Borkmann, Josef Bacik, Stanislav Fomichev, Dragos Tatulea,
	Pavel Begunkov, Bobby Eshleman

tcp_clone_payload() takes references on source skb fragments when
building an MTU probe skb, but never attaches the source skb's zerocopy
ubuf_info (uarg) to the probe skb. When tcp_mtu_probe() subsequently
frees fully consumed source skbs via tcp_eat_one_skb(), skb_release_data()
drops their uarg references and can deliver the zerocopy completion to
userspace while the unacknowledged probe skb still references the user
buffers.

Additionally, tcp_can_coalesce_send_queue_head() only checks
skb_pure_zcopy_same() (which compares SKBFL_PURE_ZEROCOPY), allowing
adjacent zerocopy skbs with different uargs (or a mixed-zerocopy skb and
a non-zerocopy skb) to be coalesced into a single probe skb that can
only hold one destructor_arg.

Reject coalescing across different skb_zcopy() uargs in
tcp_can_coalesce_send_queue_head() and propagate the uarg to the probe
skb via skb_zcopy_set() in tcp_clone_payload().

This is a pre-existing issue found by manual code inspection and LLM
review; it was not triggered in production. Verified with the net_core
KUnit test suite; not tested on real hardware.

Fixes: 736013292e3c ("tcp: let tcp_mtu_probe() build headless packets")
Signed-off-by: Mina Almasry <almasrymina@google.com>
Acked-by: Stanislav Fomichev <sdf@fomichev.me>
---
 net/ipv4/tcp_output.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 19059d03152e..bedf828cc0e0 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -2664,7 +2664,9 @@ static bool tcp_can_coalesce_send_queue_head(struct sock *sk, int len)
 		if (len <= skb->len)
 			break;
 
-		if (tcp_has_tx_tstamp(skb) || !tcp_skb_can_collapse(skb, next))
+		if (tcp_has_tx_tstamp(skb) ||
+		    !tcp_skb_can_collapse(skb, next) ||
+		    skb_zcopy(skb) != skb_zcopy(next))
 			return false;
 
 		len -= skb->len;
@@ -2718,6 +2720,7 @@ static int tcp_clone_payload(struct sock *sk, struct sk_buff *to,
 	WARN_ON_ONCE(len != probe_size);
 	for (i = 0; i < nr_frags; i++)
 		skb_frag_ref(to, i);
+	skb_zcopy_set(to, skb_zcopy(tcp_send_head(sk)), NULL);
 
 	skb_shinfo(to)->nr_frags = nr_frags;
 	to->truesize += probe_size;
-- 
2.56.1.750.gf70dc682cf-goog


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH net-next v6 5/7] net: kunit: attach net_iov frags to target skbs in unreadable tests
  2026-11-20 20:14 [PATCH net-next v6 0/7] net: prevent mixing incompatible memory providers in skbs Mina Almasry
                   ` (3 preceding siblings ...)
  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 ` Mina Almasry
  2026-11-23 17:29   ` Stanislav Fomichev
  2026-11-24  8:14   ` netdev-bot+sashiko
  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
  6 siblings, 2 replies; 17+ messages in thread
From: Mina Almasry @ 2026-11-20 20:14 UTC (permalink / raw)
  To: netdev
  Cc: Mina Almasry, Eric Dumazet, Neal Cardwell, Kuniyuki Iwashima,
	David S. Miller, Jakub Kicinski, Paolo Abeni, Simon Horman,
	Stanislav Fomichev, Kaiyuan Zhang, Willem de Bruijn,
	Daniel Borkmann, Josef Bacik, Stanislav Fomichev, Dragos Tatulea,
	Pavel Begunkov, Bobby Eshleman

In netmem_ref_test_net_iov(), the target skb passed to skb_shift() has
no fragments and unreadable == 0 while shifting from an unreadable
net_iov skb. In netmem_ref_test_try_coalesce(), subtest 3 manually sets
to->unreadable = 1 on a linear skb with nr_frags == 0, which cannot
occur in real code where skb->unreadable tracks unreadable fragments.

Give both target skbs an initial net_iov fragment from the same binding
before shifting or coalescing so the tests remain valid once memory
provider compatibility is enforced across skb_shift() and
skb_try_coalesce().

Signed-off-by: Mina Almasry <almasrymina@google.com>
---
 net/core/net_test.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/net/core/net_test.c b/net/core/net_test.c
index 19f422300d9c..1cfa947c11f2 100644
--- a/net/core/net_test.c
+++ b/net/core/net_test.c
@@ -1099,6 +1099,9 @@ static void netmem_ref_test_net_iov(struct kunit *test)
 	copy = alloc_skb(0, GFP_KERNEL);
 	KUNIT_ASSERT_NOT_NULL(test, copy);
 	copy->pp_recycle = 1;
+	skb_fill_netmem_desc(copy, 0, netmem, 64, 16);
+	copy->len = 16;
+	copy->data_len = 16;
 	KUNIT_EXPECT_EQ(test, skb_shift(copy, skb, 16), 16);
 	KUNIT_EXPECT_EQ(test, atomic_long_read(&niov.desc.pp_ref_count), 3L);
 	KUNIT_EXPECT_EQ(test, atomic_long_read(&binding.ref.data->count),
@@ -1730,18 +1733,19 @@ static void netmem_ref_test_try_coalesce(struct kunit *test)
 	from = alloc_skb(0, GFP_KERNEL);
 	KUNIT_ASSERT_NOT_NULL(test, to);
 	KUNIT_ASSERT_NOT_NULL(test, from);
-	skb_put(to, skb_tailroom(to));
 	to->pp_recycle = 1;
-	to->unreadable = 1;
 	from->pp_recycle = 1;
-	skb_add_rx_frag_netmem(from, 0, niov_nm, 0, 64, PAGE_SIZE);
+	skb_add_rx_frag_netmem(to, 0, niov_nm, 0, 32, PAGE_SIZE);
+	napi_pp_get_page(niov_nm);
+	skb_add_rx_frag_netmem(from, 0, niov_nm, 32, 64, PAGE_SIZE);
 	napi_pp_get_page(niov_nm);
 
 	clone = skb_clone(from, GFP_KERNEL);
 	KUNIT_ASSERT_NOT_NULL(test, clone);
 	KUNIT_EXPECT_TRUE(test, skb_try_coalesce(to, from, &fragstolen,
 						 &delta));
-	KUNIT_EXPECT_EQ(test, atomic_long_read(&niov.desc.pp_ref_count), 4L);
+	KUNIT_EXPECT_TRUE(test, to->unreadable);
+	KUNIT_EXPECT_EQ(test, atomic_long_read(&niov.desc.pp_ref_count), 5L);
 	KUNIT_EXPECT_EQ(test, atomic_long_read(&binding.ref.data->count),
 			base_iov_ref);
 	consume_skb(from);
-- 
2.56.1.750.gf70dc682cf-goog


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH net-next v6 6/7] net: prevent mixing frags from different memory providers or bindings
  2026-11-20 20:14 [PATCH net-next v6 0/7] net: prevent mixing incompatible memory providers in skbs Mina Almasry
                   ` (4 preceding siblings ...)
  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 ` Mina Almasry
  2026-11-23 17:30   ` Stanislav Fomichev
  2026-11-24  8:14   ` netdev-bot+sashiko
  2026-11-20 20:14 ` [PATCH net-next v6 7/7] net: kunit: test incompatible memory provider rejection Mina Almasry
  6 siblings, 2 replies; 17+ messages in thread
From: Mina Almasry @ 2026-11-20 20:14 UTC (permalink / raw)
  To: netdev
  Cc: Mina Almasry, Eric Dumazet, Neal Cardwell, Kuniyuki Iwashima,
	David S. Miller, Jakub Kicinski, Paolo Abeni, Simon Horman,
	Stanislav Fomichev, Kaiyuan Zhang, Willem de Bruijn,
	Daniel Borkmann, Josef Bacik, Stanislav Fomichev, Dragos Tatulea,
	Pavel Begunkov, Bobby Eshleman

Prevent coalescing, segmenting, or shifting skb fragments from
incompatible memory providers or different devmem bindings.

Add skb_mem_provider_compat() with an inline fast path checking only
skb_frags_readable() on both skbs (unreadable lives in
struct_group(headers, ...) alongside header flags already loaded in GRO
and TCP coalescing/collapse paths) and an out-of-line slow path
__skb_mem_provider_compat() comparing the net_iov provider instance
(net_iov_owner() for devmem bindings, niov->desc.pp for other net_iov
providers such as io_uring zcrx). Enforce compatibility across
skb_try_coalesce(), skb_gro_receive(), skb_gro_receive_list(),
skb_segment(), and tcp_skb_can_collapse(), and add a
DEBUG_NET_WARN_ON_ONCE() check in skb_shift() matching the existing
pp_recycle and decrypted assertions.

This issue is theoretical and was found by manual code inspection and
LLM review; it was not triggered in production. Verified with the
net_core KUnit test suite; not tested on real hardware.

Fixes: 65249feb6b3d ("net: add support for skbs with unreadable frags")
Signed-off-by: Mina Almasry <almasrymina@google.com>
---
 include/linux/skbuff.h | 18 ++++++++++++++++
 include/net/tcp.h      |  2 +-
 net/core/gro.c         |  6 ++++++
 net/core/skbuff.c      | 49 +++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 73 insertions(+), 2 deletions(-)

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 0c69b66af8f0..979aab031096 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -1890,6 +1890,24 @@ static inline bool skb_frags_readable(const struct sk_buff *skb)
 	return !skb->unreadable;
 }
 
+bool __skb_mem_provider_compat(const struct sk_buff *skb1,
+			       const struct sk_buff *skb2);
+
+/* Return true if the memory providers of @skb1 and @skb2 are compatible
+ * for coalescing. For any struct page-backed provider (the buddy allocator
+ * or a future provider handing out struct pages), coalescing is assumed
+ * feasible. For net_iov-backed providers, the provider instance pointer
+ * must match.
+ */
+static inline bool skb_mem_provider_compat(const struct sk_buff *skb1,
+					   const struct sk_buff *skb2)
+{
+	if (likely(skb_frags_readable(skb1) && skb_frags_readable(skb2)))
+		return true;
+
+	return __skb_mem_provider_compat(skb1, skb2);
+}
+
 static inline void skb_mark_not_on_list(struct sk_buff *skb)
 {
 	skb->next = NULL;
diff --git a/include/net/tcp.h b/include/net/tcp.h
index 0b896319aaf5..e2bb07a54a98 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -1285,7 +1285,7 @@ static inline bool tcp_skb_can_collapse(const struct sk_buff *to,
 		      mptcp_skb_can_collapse(to, from) &&
 		      !skb_cmp_decrypted(to, from) &&
 		      skb_pure_zcopy_same(to, from) &&
-		      skb_frags_readable(to) == skb_frags_readable(from));
+		      skb_mem_provider_compat(to, from));
 }
 
 static inline bool tcp_skb_can_collapse_rx(const struct sk_buff *to,
diff --git a/net/core/gro.c b/net/core/gro.c
index c093fe388dfe..6852b19e4840 100644
--- a/net/core/gro.c
+++ b/net/core/gro.c
@@ -109,6 +109,9 @@ int skb_gro_receive(struct sk_buff *p, struct sk_buff *skb)
 	if (p->pp_recycle != skb->pp_recycle)
 		return -ETOOMANYREFS;
 
+	if (!skb_mem_provider_compat(p, skb))
+		return -ETOOMANYREFS;
+
 	if (skb_zcopy(p) || skb_zcopy(skb))
 		return -ETOOMANYREFS;
 
@@ -233,6 +236,9 @@ int skb_gro_receive(struct sk_buff *p, struct sk_buff *skb)
 
 int skb_gro_receive_list(struct sk_buff *p, struct sk_buff *skb)
 {
+	if (!skb_mem_provider_compat(p, skb))
+		return -ETOOMANYREFS;
+
 	/* make sure to check flush flag and to not merge */
 	if (unlikely(p->len + skb->len >= 65536 ||
 		     NAPI_GRO_CB(skb)->flush))
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index aac61fbe419f..212d76ef9672 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -4630,6 +4630,7 @@ int skb_shift(struct sk_buff *tgt, struct sk_buff *skb, int shiftlen)
 
 	DEBUG_NET_WARN_ON_ONCE(tgt->pp_recycle != skb->pp_recycle);
 	DEBUG_NET_WARN_ON_ONCE(skb_cmp_decrypted(tgt, skb));
+	DEBUG_NET_WARN_ON_ONCE(!skb_mem_provider_compat(tgt, skb));
 
 	todo = shiftlen;
 	from = 0;
@@ -5277,6 +5278,10 @@ struct sk_buff *skb_segment(struct sk_buff *head_skb,
 				err = -EINVAL;
 				goto err;
 			}
+			if (!skb_mem_provider_compat(head_skb, list_skb)) {
+				err = -EINVAL;
+				goto err;
+			}
 
 			nskb = skb_clone(list_skb, GFP_ATOMIC);
 			if (unlikely(!nskb))
@@ -5398,6 +5403,11 @@ struct sk_buff *skb_segment(struct sk_buff *head_skb,
 					goto err;
 				}
 
+				if (!skb_mem_provider_compat(head_skb,
+							     list_skb)) {
+					err = -EINVAL;
+					goto err;
+				}
 				if (skb_shinfo(nskb)->nr_frags &&
 				    nskb->pp_recycle != list_skb->pp_recycle) {
 					nskb->data_len = pos - offset - hsize;
@@ -6588,6 +6598,43 @@ void kfree_skb_partial(struct sk_buff *skb, bool head_stolen)
 }
 EXPORT_SYMBOL(kfree_skb_partial);
 
+/* Return an opaque pointer identifying the memory provider instance of @skb's
+ * net_iov fragments:
+ * - For devmem (NET_IOV_DMABUF), net_iov_owner(niov) (&binding->area, 1:1 with
+ *   the binding across RX queues and TX).
+ * - For other net_iov providers (e.g., io_uring zcrx), niov->desc.pp (shared
+ *   across all areas of an io_zcrx_ifq).
+ */
+static void *skb_net_iov_provider(const struct sk_buff *skb)
+{
+	struct net_iov *niov;
+
+	if (!skb_shinfo(skb)->nr_frags)
+		return NULL;
+
+	niov = skb_frag_net_iov(&skb_shinfo(skb)->frags[0]);
+	if (!niov)
+		return NULL;
+
+	if (net_is_devmem_iov(niov))
+		return net_iov_owner(niov);
+
+	return niov->desc.pp;
+}
+
+bool __skb_mem_provider_compat(const struct sk_buff *skb1,
+			       const struct sk_buff *skb2)
+{
+	void *p1;
+
+	if (skb_frags_readable(skb1) != skb_frags_readable(skb2))
+		return false;
+
+	p1 = skb_net_iov_provider(skb1);
+	return p1 && p1 == skb_net_iov_provider(skb2);
+}
+EXPORT_SYMBOL(__skb_mem_provider_compat);
+
 /**
  * skb_try_coalesce - try to merge skb to prior one
  * @to: prior buffer
@@ -6620,7 +6667,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
 	 * belong to the same memory provider instance; do not coalesce skbs
 	 * that would mix them.
 	 */
-	if (skb_frags_readable(from) != skb_frags_readable(to))
+	if (!skb_mem_provider_compat(to, from))
 		return false;
 
 	if (len <= skb_tailroom(to) && skb_frags_readable(from)) {
-- 
2.56.1.750.gf70dc682cf-goog


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH net-next v6 7/7] net: kunit: test incompatible memory provider rejection
  2026-11-20 20:14 [PATCH net-next v6 0/7] net: prevent mixing incompatible memory providers in skbs Mina Almasry
                   ` (5 preceding siblings ...)
  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 ` Mina Almasry
  2026-11-23 17:31   ` Stanislav Fomichev
  6 siblings, 1 reply; 17+ messages in thread
From: Mina Almasry @ 2026-11-20 20:14 UTC (permalink / raw)
  To: netdev
  Cc: Mina Almasry, Eric Dumazet, Neal Cardwell, Kuniyuki Iwashima,
	David S. Miller, Jakub Kicinski, Paolo Abeni, Simon Horman,
	Stanislav Fomichev, Kaiyuan Zhang, Willem de Bruijn,
	Daniel Borkmann, Josef Bacik, Stanislav Fomichev, Dragos Tatulea,
	Pavel Begunkov, Bobby Eshleman

Add KUnit subtests in netmem_ref_test_try_coalesce() verifying that:

- skb_try_coalesce() rejects coalescing two NET_IOV_DMABUF skbs
  belonging to different bindings, and
- skb_try_coalesce() rejects coalescing a NET_IOV_DMABUF skb with a
  NET_IOV_IOURING skb.

Signed-off-by: Mina Almasry <almasrymina@google.com>
---
 net/core/net_test.c | 49 +++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 47 insertions(+), 2 deletions(-)

diff --git a/net/core/net_test.c b/net/core/net_test.c
index 1cfa947c11f2..3efff3f5368a 100644
--- a/net/core/net_test.c
+++ b/net/core/net_test.c
@@ -1639,9 +1639,10 @@ static void netmem_ref_test_try_coalesce(struct kunit *test)
 		.nid = NUMA_NO_NODE,
 	};
 	struct sk_buff *to, *from, *clone;
-	struct net_iov niov = {};
+	struct net_iov_area area2 = {};
+	struct net_iov niov = {}, niov2 = {};
 	struct page *pp_page, *reg_page;
-	netmem_ref pp_nm, niov_nm;
+	netmem_ref pp_nm, niov_nm, niov2_nm;
 	struct page_pool *pool;
 	long base_pp_ref, base_iov_ref;
 	int base_pp_page_ref, base_reg_ref;
@@ -1753,6 +1754,50 @@ static void netmem_ref_test_try_coalesce(struct kunit *test)
 	consume_skb(to);
 	KUNIT_EXPECT_EQ(test, atomic_long_read(&niov.desc.pp_ref_count), 2L);
 
+	/* 4. Reject coalescing net_iov skbs from different bindings. */
+	net_iov_init(&niov2, &area2, NET_IOV_DMABUF);
+	niov2_nm = net_iov_to_netmem(&niov2);
+	netmem_set_pp(niov2_nm, pool);
+	netmem_or_pp_magic(niov2_nm, PP_SIGNATURE);
+	atomic_long_set(&niov2.desc.pp_ref_count, 2);
+	to = alloc_skb(0, GFP_KERNEL);
+	from = alloc_skb(0, GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, to);
+	KUNIT_ASSERT_NOT_NULL(test, from);
+	to->pp_recycle = 1;
+	from->pp_recycle = 1;
+	skb_add_rx_frag_netmem(to, 0, niov_nm, 0, 32, PAGE_SIZE);
+	napi_pp_get_page(niov_nm);
+	skb_add_rx_frag_netmem(from, 0, niov2_nm, 0, 32, PAGE_SIZE);
+	napi_pp_get_page(niov2_nm);
+	KUNIT_EXPECT_FALSE(test, skb_try_coalesce(to, from, &fragstolen,
+						  &delta));
+	consume_skb(from);
+	consume_skb(to);
+	KUNIT_EXPECT_EQ(test, atomic_long_read(&niov.desc.pp_ref_count), 2L);
+	KUNIT_EXPECT_EQ(test, atomic_long_read(&niov2.desc.pp_ref_count), 2L);
+
+	/* 5. Reject coalescing net_iov skbs from different providers. */
+	net_iov_init(&niov2, NULL, NET_IOV_IOURING);
+	to = alloc_skb(0, GFP_KERNEL);
+	from = alloc_skb(0, GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, to);
+	KUNIT_ASSERT_NOT_NULL(test, from);
+	to->pp_recycle = 1;
+	from->pp_recycle = 1;
+	skb_add_rx_frag_netmem(to, 0, niov_nm, 0, 32, PAGE_SIZE);
+	napi_pp_get_page(niov_nm);
+	skb_add_rx_frag_netmem(from, 0, niov2_nm, 0, 32, PAGE_SIZE);
+	napi_pp_get_page(niov2_nm);
+	KUNIT_EXPECT_FALSE(test, skb_try_coalesce(to, from, &fragstolen,
+						  &delta));
+	consume_skb(from);
+	consume_skb(to);
+	KUNIT_EXPECT_EQ(test, atomic_long_read(&niov.desc.pp_ref_count), 2L);
+	KUNIT_EXPECT_EQ(test, atomic_long_read(&niov2.desc.pp_ref_count), 2L);
+	netmem_clear_pp_magic(niov2_nm);
+	netmem_set_pp(niov2_nm, NULL);
+
 	page_pool_put_full_page(pool, pp_page, false);
 	page_pool_put_full_page(pool, pp_page, false);
 	__free_page(reg_page);
-- 
2.56.1.750.gf70dc682cf-goog


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH net-next v6 2/7] net: devmem: prevent mixing TX bindings and reject non-devmem xmit
  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-23 17:29   ` Stanislav Fomichev
  0 siblings, 0 replies; 17+ messages in thread
From: Stanislav Fomichev @ 2026-11-23 17:29 UTC (permalink / raw)
  To: Mina Almasry
  Cc: netdev, Eric Dumazet, Neal Cardwell, Kuniyuki Iwashima,
	David S. Miller, Jakub Kicinski, Paolo Abeni, Simon Horman,
	Stanislav Fomichev, Kaiyuan Zhang, Willem de Bruijn,
	Daniel Borkmann, Josef Bacik, Dragos Tatulea, Pavel Begunkov,
	Bobby Eshleman

On 11/20, Mina Almasry wrote:
> Two devmem TX paths do not validate the fragment memory provider or
> binding strictly enough:
> 
> - When sending with MSG_ZEROCOPY and SCM_DEVMEM_DMABUF across multiple
>   devmem TX bindings on the same TCP socket, tcp_sendmsg_locked() and
>   zerocopy_fill_skb_from_devmem() only check skb_frags_readable(skb),
>   allowing fragments from two different devmem TX bindings to be
>   appended into the same skb.
> - validate_xmit_unreadable_skb() checks the binding direction and
>   target device only when net_is_devmem_iov(niov) is true, allowing
>   unreadable skbs backed by non-devmem net_iov providers (such as
>   forwarded io_uring zcrx RX skbs) to bypass validation on
>   NETMEM_TX_DMA devices. Using netmem_to_net_iov() also assumes
>   frags[0] is a net_iov without checking first.
> 
> Add net_devmem_skb_binding() to return the devmem binding of an skb's
> first fragment (all fragments in an skb share the same memory source).
> In tcp_sendmsg_locked(), check net_devmem_skb_binding(skb) != binding
> only when a devmem binding is active so normal non-devmem TX keeps a
> single unlikely(!skb_frags_readable(skb)) check with no extra taken
> branch. In zerocopy_fill_skb_from_devmem(), check
> net_devmem_skb_binding(skb) != binding and return -EMSGSIZE instead of
> -EFAULT so tcp_sendmsg_locked() starts a new segment instead of
> aborting the send with an error. In validate_xmit_unreadable_skb(), use
> skb_frag_net_iov() and drop unreadable skbs on NETMEM_TX_DMA devices
> unless frags[0] is a DMA_TO_DEVICE devmem net_iov bound to dev.
> 
> This issue is theoretical and was found by manual code inspection and
> LLM review; it was not triggered in production. Compile-tested and
> boot-tested with the net_core KUnit test suite; not tested on real
> hardware.
> 
> Fixes: bd61848900bf ("net: devmem: Implement TX path")
> Fixes: ae28cb114727 ("net: check for driver support in netmem TX")
> Signed-off-by: Mina Almasry <almasrymina@google.com>

Acked-by: Stanislav Fomichev <sdf@fomichev.me>

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH net-next v6 3/7] tcp: fix unreadable net_iov handling in tcp_clone_payload()
  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-23 17:29   ` Stanislav Fomichev
  2026-11-24  8:14   ` netdev-bot+sashiko
  1 sibling, 0 replies; 17+ messages in thread
From: Stanislav Fomichev @ 2026-11-23 17:29 UTC (permalink / raw)
  To: Mina Almasry
  Cc: netdev, Eric Dumazet, Neal Cardwell, Kuniyuki Iwashima,
	David S. Miller, Jakub Kicinski, Paolo Abeni, Simon Horman,
	Stanislav Fomichev, Kaiyuan Zhang, Willem de Bruijn,
	Daniel Borkmann, Josef Bacik, Dragos Tatulea, Pavel Begunkov,
	Bobby Eshleman

On 11/20, Mina Almasry wrote:
> tcp_clone_payload() clones fragments from the TCP write queue into an
> MTU probe skb, but does not propagate skb->unreadable and compares
> adjacent fragments using skb_frag_page(). On devmem TX skbs backed by
> unreadable net_iovs, skb_frag_page() returns NULL for every fragment,
> causing distinct net_iovs with contiguous offsets to compare equal as
> NULL == NULL and be merged incorrectly, while leaving to->unreadable
> clear on the resulting probe skb.
> 
> Propagate skb->unreadable to the probe skb and compare fragments via
> skb_frag_netmem().
> 
> This issue is theoretical and was found by manual code inspection and
> LLM review; it was not triggered in production. Verified with the
> net_core KUnit test suite; not tested on real hardware.
> 
> Fixes: bd61848900bf ("net: devmem: Implement TX path")
> Signed-off-by: Mina Almasry <almasrymina@google.com>

Acked-by: Stanislav Fomichev <sdf@fomichev.me>

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH net-next v6 5/7] net: kunit: attach net_iov frags to target skbs in unreadable tests
  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-23 17:29   ` Stanislav Fomichev
  2026-11-24  8:14   ` netdev-bot+sashiko
  1 sibling, 0 replies; 17+ messages in thread
From: Stanislav Fomichev @ 2026-11-23 17:29 UTC (permalink / raw)
  To: Mina Almasry
  Cc: netdev, Eric Dumazet, Neal Cardwell, Kuniyuki Iwashima,
	David S. Miller, Jakub Kicinski, Paolo Abeni, Simon Horman,
	Stanislav Fomichev, Kaiyuan Zhang, Willem de Bruijn,
	Daniel Borkmann, Josef Bacik, Dragos Tatulea, Pavel Begunkov,
	Bobby Eshleman

On 11/20, Mina Almasry wrote:
> In netmem_ref_test_net_iov(), the target skb passed to skb_shift() has
> no fragments and unreadable == 0 while shifting from an unreadable
> net_iov skb. In netmem_ref_test_try_coalesce(), subtest 3 manually sets
> to->unreadable = 1 on a linear skb with nr_frags == 0, which cannot
> occur in real code where skb->unreadable tracks unreadable fragments.
> 
> Give both target skbs an initial net_iov fragment from the same binding
> before shifting or coalescing so the tests remain valid once memory
> provider compatibility is enforced across skb_shift() and
> skb_try_coalesce().
> 
> Signed-off-by: Mina Almasry <almasrymina@google.com>

Acked-by: Stanislav Fomichev <sdf@fomichev.me>

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH net-next v6 6/7] net: prevent mixing frags from different memory providers or bindings
  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-23 17:30   ` Stanislav Fomichev
  2026-11-24  8:14   ` netdev-bot+sashiko
  1 sibling, 0 replies; 17+ messages in thread
From: Stanislav Fomichev @ 2026-11-23 17:30 UTC (permalink / raw)
  To: Mina Almasry
  Cc: netdev, Eric Dumazet, Neal Cardwell, Kuniyuki Iwashima,
	David S. Miller, Jakub Kicinski, Paolo Abeni, Simon Horman,
	Stanislav Fomichev, Kaiyuan Zhang, Willem de Bruijn,
	Daniel Borkmann, Josef Bacik, Dragos Tatulea, Pavel Begunkov,
	Bobby Eshleman

On 11/20, Mina Almasry wrote:
> Prevent coalescing, segmenting, or shifting skb fragments from
> incompatible memory providers or different devmem bindings.
> 
> Add skb_mem_provider_compat() with an inline fast path checking only
> skb_frags_readable() on both skbs (unreadable lives in
> struct_group(headers, ...) alongside header flags already loaded in GRO
> and TCP coalescing/collapse paths) and an out-of-line slow path
> __skb_mem_provider_compat() comparing the net_iov provider instance
> (net_iov_owner() for devmem bindings, niov->desc.pp for other net_iov
> providers such as io_uring zcrx). Enforce compatibility across
> skb_try_coalesce(), skb_gro_receive(), skb_gro_receive_list(),
> skb_segment(), and tcp_skb_can_collapse(), and add a
> DEBUG_NET_WARN_ON_ONCE() check in skb_shift() matching the existing
> pp_recycle and decrypted assertions.
> 
> This issue is theoretical and was found by manual code inspection and
> LLM review; it was not triggered in production. Verified with the
> net_core KUnit test suite; not tested on real hardware.
> 
> Fixes: 65249feb6b3d ("net: add support for skbs with unreadable frags")
> Signed-off-by: Mina Almasry <almasrymina@google.com>

Acked-by: Stanislav Fomichev <sdf@fomichev.me>

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH net-next v6 7/7] net: kunit: test incompatible memory provider rejection
  2026-11-20 20:14 ` [PATCH net-next v6 7/7] net: kunit: test incompatible memory provider rejection Mina Almasry
@ 2026-11-23 17:31   ` Stanislav Fomichev
  0 siblings, 0 replies; 17+ messages in thread
From: Stanislav Fomichev @ 2026-11-23 17:31 UTC (permalink / raw)
  To: Mina Almasry
  Cc: netdev, Eric Dumazet, Neal Cardwell, Kuniyuki Iwashima,
	David S. Miller, Jakub Kicinski, Paolo Abeni, Simon Horman,
	Stanislav Fomichev, Kaiyuan Zhang, Willem de Bruijn,
	Daniel Borkmann, Josef Bacik, Dragos Tatulea, Pavel Begunkov,
	Bobby Eshleman

On 11/20, Mina Almasry wrote:
> Add KUnit subtests in netmem_ref_test_try_coalesce() verifying that:
> 
> - skb_try_coalesce() rejects coalescing two NET_IOV_DMABUF skbs
>   belonging to different bindings, and
> - skb_try_coalesce() rejects coalescing a NET_IOV_DMABUF skb with a
>   NET_IOV_IOURING skb.
> 
> Signed-off-by: Mina Almasry <almasrymina@google.com>

Acked-by: Stanislav Fomichev <sdf@fomichev.me>

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH net-next v6 3/7] tcp: fix unreadable net_iov handling in tcp_clone_payload()
  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-23 17:29   ` Stanislav Fomichev
@ 2026-11-24  8:14   ` netdev-bot+sashiko
  1 sibling, 0 replies; 17+ messages in thread
From: netdev-bot+sashiko @ 2026-11-24  8:14 UTC (permalink / raw)
  To: almasrymina
  Cc: netdev, edumazet, ncardwell, kuniyu, davem, kuba, pabeni, horms,
	sdf, kaiyuanz, willemb, daniel, josef, sdf.kernel, dtatulea,
	asml.silence, bobbyeshleman

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The commit message explains how the bug works but not what it
  does to users, and it calls the bug "theoretical".
- [Low] The commit message says the fix was "Verified with the net_core
  KUnit test suite".

--

tcp: fix unreadable net_iov handling in tcp_clone_payload()

This patch makes tcp_clone_payload() copy skb->unreadable from the write
queue skbs into the MTU probe skb. It also changes the frag merge check
from skb_frag_page() to skb_frag_netmem(), so that two different
unreadable net_iovs no longer compare equal as NULL == NULL.

> This issue is theoretical and was found by manual code inspection and
> LLM review; it was not triggered in production. Verified with the
> net_core KUnit test suite; not tested on real hardware.

[Severity: Low]
The message explains how the bug happens and calls it theoretical, but it
does not say what users would see. Could it describe the impact, so that
stable maintainers can judge how urgent the fix is?

Before this patch, the probe skb built by tcp_clone_payload() could hold
devmem net_iov frags while to->unreadable stayed 0. In
validate_xmit_unreadable_skb() in net/core/dev.c:

	if (likely(skb_frags_readable(skb) ||
		   dev->netmem_tx == NETMEM_TX_NO_DMA))
		goto out;

So the probe would skip the NETMEM_TX_NONE drop and the binding device
check. Other software paths that use skb_frags_readable() as their gate
would also treat the net_iov frags as pages, and skb_frag_page() returns
NULL for those.

The NULL == NULL check could also merge two different net_iovs into one
frag. This happens when one frag ends at offset X in niov A and the next
frag starts at offset X in niov B. zerocopy_fill_skb_from_devmem() takes
these offsets from the user's dmabuf iov addresses. A user can therefore
set this up, even with two iovs in a single sendmsg().

In that case, wouldn't the probe send the bytes that follow in niov A
instead of niov B's bytes? That would corrupt the TCP payload and send
dmabuf bytes the user never asked to send.

[Severity: Low]
Can the net_core KUnit suite actually run this change? tcp_clone_payload()
is static in net/ipv4/tcp_output.c. Its only call path is:

tcp_write_xmit()->tcp_mtu_probe()->tcp_clone_payload()

The only TCP test in net/core/net_test.c looks like
netmem_ref_test_tcp_devmem_recv(). It covers devmem receive and never
calls tcp_mtu_probe().

Would it be more accurate to say that the changed path was not run? The
other option would be to add a test that drives tcp_mtu_probe() with
devmem skbs.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120201408.3445445-1-almasrymina%40google.com

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH net-next v6 4/7] tcp: propagate skb_zcopy() uarg in tcp_mtu_probe()
  2026-11-20 20:14 ` [PATCH net-next v6 4/7] tcp: propagate skb_zcopy() uarg in tcp_mtu_probe() Mina Almasry
@ 2026-11-24  8:14   ` netdev-bot+sashiko
  0 siblings, 0 replies; 17+ messages in thread
From: netdev-bot+sashiko @ 2026-11-24  8:14 UTC (permalink / raw)
  To: almasrymina
  Cc: netdev, edumazet, ncardwell, kuniyu, davem, kuba, pabeni, horms,
	sdf, kaiyuanz, willemb, daniel, josef, sdf.kernel, dtatulea,
	asml.silence, bobbyeshleman

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The commit message for "tcp: propagate skb_zcopy() uarg in
  tcp_mtu_probe()" says "Verified with the net_core KUnit test suite".

--

tcp: propagate skb_zcopy() uarg in tcp_mtu_probe()

This commit attaches the source skb's zerocopy uarg to the MTU probe skb
in tcp_clone_payload(). It also makes tcp_can_coalesce_send_queue_head()
refuse to coalesce skbs whose skb_zcopy() uargs differ. Together these
stop the zerocopy completion from reaching userspace while the probe skb
still references the user buffers.

> This is a pre-existing issue found by manual code inspection and LLM
> review; it was not triggered in production. Verified with the net_core
> KUnit test suite; not tested on real hardware.

[Severity: Low]
Is the "Verified with the net_core KUnit test suite" statement accurate
for this change?

The net_core suite in net/core/net_test.c contains these cases:
gso_test_func, ip_tunnel_flags_test_run, netmem_ref_test_page,
netmem_ref_test_pp_page, netmem_ref_test_net_iov,
netmem_ref_test_release_data, netmem_ref_test_skb_segment,
netmem_ref_test_try_coalesce and netmem_ref_test_tcp_devmem_recv.

The only TCP case, netmem_ref_test_tcp_devmem_recv, covers the receive
side. It queues skbs on sk_receive_queue and calls kernel_recvmsg() with
MSG_SOCK_DEVMEM.

None of the cases transmit through tcp_write_xmit()->tcp_mtu_probe(). As
a result, neither of the static helpers changed here,
tcp_can_coalesce_send_queue_head() and tcp_clone_payload(), is ever
called. No case sends MSG_ZEROCOPY or other uarg-bearing skbs through TCP
either.

This is still the case at the end of the series. The two later KUnit
patches don't add a test for this path. net_test.c has no references to
tcp_mtu_probe, tcp_clone_payload, tcp_can_coalesce_send_queue_head or
MSG_ZEROCOPY. Its only skb_zcopy* use is a skb_zcopy_init() in an
unrelated skb_zerocopy() rollback test.

Could the message say the change was only compile and regression tested?
Alternatively, it could cite a MSG_ZEROCOPY test with tcp_mtu_probing
enabled that actually reaches tcp_mtu_probe().

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120201408.3445445-1-almasrymina%40google.com

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH net-next v6 5/7] net: kunit: attach net_iov frags to target skbs in unreadable tests
  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-23 17:29   ` Stanislav Fomichev
@ 2026-11-24  8:14   ` netdev-bot+sashiko
  1 sibling, 0 replies; 17+ messages in thread
From: netdev-bot+sashiko @ 2026-11-24  8:14 UTC (permalink / raw)
  To: almasrymina
  Cc: netdev, edumazet, ncardwell, kuniyu, davem, kuba, pabeni, horms,
	sdf, kaiyuanz, willemb, daniel, josef, sdf.kernel, dtatulea,
	asml.silence, bobbyeshleman

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] In net/core/net_test.c, netmem_ref_test_try_coalesce() subtest 3,
  the patch adds `KUNIT_EXPECT_TRUE(test, to->unreadable)` after…

--

net: kunit: attach net_iov frags to target skbs in unreadable tests

This commit changes two netmem KUnit tests so that the target skb gets an
initial net_iov fragment from the same binding before the operation runs.
In netmem_ref_test_net_iov(), that operation is skb_shift(). In
netmem_ref_test_try_coalesce(), it is skb_try_coalesce(). The goal is to
keep both tests valid once memory provider compatibility is enforced in
those functions.

> diff --git a/net/core/net_test.c b/net/core/net_test.c
> index 19f422300d9c8..1cfa947c11f2c 100644
> --- a/net/core/net_test.c
> +++ b/net/core/net_test.c

[ ... ]

> @@ -1730,18 +1733,19 @@ static void netmem_ref_test_try_coalesce(struct kunit *test)
>  	from = alloc_skb(0, GFP_KERNEL);
>  	KUNIT_ASSERT_NOT_NULL(test, to);
>  	KUNIT_ASSERT_NOT_NULL(test, from);
> -	skb_put(to, skb_tailroom(to));
>  	to->pp_recycle = 1;
> -	to->unreadable = 1;
>  	from->pp_recycle = 1;
> -	skb_add_rx_frag_netmem(from, 0, niov_nm, 0, 64, PAGE_SIZE);
> +	skb_add_rx_frag_netmem(to, 0, niov_nm, 0, 32, PAGE_SIZE);
> +	napi_pp_get_page(niov_nm);
> +	skb_add_rx_frag_netmem(from, 0, niov_nm, 32, 64, PAGE_SIZE);
>  	napi_pp_get_page(niov_nm);
>  
>  	clone = skb_clone(from, GFP_KERNEL);
>  	KUNIT_ASSERT_NOT_NULL(test, clone);
>  	KUNIT_EXPECT_TRUE(test, skb_try_coalesce(to, from, &fragstolen,
>  						 &delta));
> -	KUNIT_EXPECT_EQ(test, atomic_long_read(&niov.desc.pp_ref_count), 4L);
> +	KUNIT_EXPECT_TRUE(test, to->unreadable);

[Severity: Low]
Can this new assertion ever fail?

The new skb_add_rx_frag_netmem(to, ...) call above already sets
to->unreadable before skb_try_coalesce() runs. The call chain is
skb_add_rx_frag_netmem()->skb_fill_netmem_desc()->__skb_fill_netmem_desc():

include/linux/skbuff.h:__skb_fill_netmem_desc() {
    ...
	if (netmem_is_net_iov(netmem)) {
		skb->unreadable = true;
		return;
	}
    ...
}

skb_try_coalesce() never writes to->unreadable. At this commit it only
compares skb_frags_readable(from) with skb_frags_readable(to). Later in the
series that comparison is replaced by skb_mem_provider_compat(to, from).
The rest of the function copies frags, takes frag references and updates
len/data_len/truesize. The one frag fill inside it is skb_fill_page_desc()
for a page-backed head, and that does not touch unreadable.

So the check reads back a flag the test itself set. It would still pass if
skb_try_coalesce() mishandled the unreadable state of the merged frags.

The assertion is also unchanged at the end of the series. The later commit
"net: kunit: test incompatible memory provider rejection" adds rejection
subtests for different bindings and providers, but leaves this check as it
is.

Should the assertion be dropped, or changed to check something that
skb_try_coalesce() actually changes, such as nr_frags on the target skb?

> +	KUNIT_EXPECT_EQ(test, atomic_long_read(&niov.desc.pp_ref_count), 5L);
>  	KUNIT_EXPECT_EQ(test, atomic_long_read(&binding.ref.data->count),
>  			base_iov_ref);
>  	consume_skb(from);

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120201408.3445445-1-almasrymina%40google.com

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH net-next v6 6/7] net: prevent mixing frags from different memory providers or bindings
  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-23 17:30   ` Stanislav Fomichev
@ 2026-11-24  8:14   ` netdev-bot+sashiko
  1 sibling, 0 replies; 17+ messages in thread
From: netdev-bot+sashiko @ 2026-11-24  8:14 UTC (permalink / raw)
  To: almasrymina
  Cc: netdev, edumazet, ncardwell, kuniyu, davem, kuba, pabeni, horms,
	sdf, kaiyuanz, willemb, daniel, josef, sdf.kernel, dtatulea,
	asml.silence, bobbyeshleman

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] skb_mem_provider_compat() is now called in skb_try_coalesce()
  and skb_gro_receive(), but both functions can still move a struct page…
- [Low] The commit message calls the issue 'theoretical' and only talks
  about mixing provider instances or devmem bindings.

--

net: prevent mixing frags from different memory providers or bindings

This adds skb_mem_provider_compat(). Two skbs count as compatible when
both are readable, or when both are unreadable and frags[0] of each
resolves to the same net_iov provider instance. The check is enforced in
skb_try_coalesce(), skb_gro_receive(), skb_gro_receive_list(),
skb_segment() and tcp_skb_can_collapse(), and skb_shift() gets a debug
assertion.

> diff --git a/net/core/gro.c b/net/core/gro.c
> index c093fe388dfe8..6852b19e48408 100644
> --- a/net/core/gro.c
> +++ b/net/core/gro.c
> @@ -109,6 +109,9 @@ int skb_gro_receive(struct sk_buff *p, struct sk_buff *skb)
>  	if (p->pp_recycle != skb->pp_recycle)
>  		return -ETOOMANYREFS;
>  
> +	if (!skb_mem_provider_compat(p, skb))
> +		return -ETOOMANYREFS;
> +
>  	if (skb_zcopy(p) || skb_zcopy(skb))
>  		return -ETOOMANYREFS;
>  

[Severity: Low]
This isn't a bug, but could the commit message say more about what this
hunk fixes? The message says:

    This issue is theoretical and was found by manual code inspection and
    LLM review; it was not triggered in production.

It only describes the problem as mixing provider instances or devmem
bindings.

Before this patch, skb_gro_receive() and skb_gro_receive_list() did not
check readable against unreadable at all. skb_gro_receive() only compared
pp_recycle, which is 1 for both normal page_pool pages and net_iov
page_pool memory. It also never set p->unreadable.

So the headlen <= offset frags path could merge an unreadable skb into a
readable p. The result would be a readable skb holding net_iov frags.
__skb_datagram_iter() only checks skb_frags_readable() before doing:

	skb_frag_foreach_page(frag, ...) {
		vaddr = kmap_local_page(p);

Here skb_frag_page() returns NULL for a net_iov.

skb_try_coalesce() and tcp_skb_can_collapse() already compared
readability, so for those paths this patch only tightens the check. The
GRO hunks close a much larger gap.

Could the message mention this, so stable maintainers can judge the
impact?

[ ... ]

> diff --git a/net/core/skbuff.c b/net/core/skbuff.c
> index aac61fbe419f2..212d76ef9672e 100644
> --- a/net/core/skbuff.c
> +++ b/net/core/skbuff.c

[ ... ]

> @@ -6620,7 +6667,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
>  	 * belong to the same memory provider instance; do not coalesce skbs
>  	 * that would mix them.
>  	 */
> -	if (skb_frags_readable(from) != skb_frags_readable(to))
> +	if (!skb_mem_provider_compat(to, from))
>  		return false;
>  
>  	if (len <= skb_tailroom(to) && skb_frags_readable(from)) {

[Severity: High]
Can a struct page still end up in an unreadable skb's frag array after
this check passes?

If to and from are both unreadable and share a provider,
skb_mem_provider_compat() returns true. Suppose from carries payload in
its linear area. The tailroom copy is skipped because
skb_frags_readable(from) is false.

If from also has head_frag set and is not cloned, skb_head_is_locked() is
false, so the head gets stolen:

net/core/skbuff.c:skb_try_coalesce() {
    ...
	if (skb_headlen(from) != 0) {
		struct page *page = virt_to_head_page(from->head);
		unsigned int offset;

		offset = from->data - (unsigned char *)page_address(page);
		skb_fill_page_desc(to, to_shinfo->nr_frags,
				   page, offset, skb_headlen(from));
		*fragstolen = true;
	}

	memcpy(to_shinfo->frags + to_shinfo->nr_frags,
	       from_shinfo->frags, ...
    ...
}

skb_gro_receive() seems to do the same after its new check when
headlen > skb_gro_offset(skb):

net/core/gro.c:skb_gro_receive() {
    ...
	} else if (skb->head_frag) {
		...
		struct page *page = virt_to_head_page(skb->head);
		...
		skb_frag_fill_page_desc(frag, page, first_offset, first_size);

		memcpy(frag + 1, skbinfo->frags, sizeof(*frag) * skbinfo->nr_frags);
    ...
}

Either way, the skb has unreadable set but its frags mix a page_pool
header page with net_iovs. That goes against the comment right above the
new check: "All frags in an skb must either all be struct page-backed or
all belong to the same memory provider instance".

skb_zerocopy() already rejects this layout:

	if (!skb_frags_readable(from) && j > 0 && len) {
		skb_frag_unref(to, 0);
		return -EFAULT;
	}

Documentation/networking/devmem.rst says payload lands in the linear area
when the NIC can't split the packet at the header boundary. The remote
peer controls the shape of those packets.

A devmem receiver would then reach this in tcp_recvmsg_dmabuf():

			if (!skb_frag_net_iov(frag)) {
				net_err_ratelimited("Found non-dmabuf skb with net_iov");
				err = -ENODEV;
				goto out;
			}

The skb is never consumed. Wouldn't every later recvmsg() on that socket
fail the same way?

Also, skb_net_iov_provider() only looks at frags[0], so later merges
won't catch a mixed skb once it exists. Nothing later in the series
appears to touch these paths.

Should skb_try_coalesce() and skb_gro_receive() refuse to steal the head
of an unreadable skb, the way skb_zerocopy() does?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120201408.3445445-1-almasrymina%40google.com

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2026-11-24  8:14 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 20:14 [PATCH net-next v6 0/7] net: prevent mixing incompatible memory providers in skbs Mina Almasry
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-23 17:29   ` Stanislav Fomichev
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-23 17:29   ` Stanislav Fomichev
2026-11-24  8:14   ` netdev-bot+sashiko
2026-11-20 20:14 ` [PATCH net-next v6 4/7] tcp: propagate skb_zcopy() uarg in tcp_mtu_probe() Mina Almasry
2026-11-24  8:14   ` netdev-bot+sashiko
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-23 17:29   ` Stanislav Fomichev
2026-11-24  8:14   ` netdev-bot+sashiko
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-23 17:30   ` Stanislav Fomichev
2026-11-24  8:14   ` netdev-bot+sashiko
2026-11-20 20:14 ` [PATCH net-next v6 7/7] net: kunit: test incompatible memory provider rejection Mina Almasry
2026-11-23 17:31   ` Stanislav Fomichev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox