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 2/7] net: devmem: prevent mixing TX bindings and reject non-devmem xmit
Date: Fri, 20 Nov 2026 20:14:03 +0000 [thread overview]
Message-ID: <20261120201408.3445445-3-almasrymina@google.com> (raw)
In-Reply-To: <20261120201408.3445445-1-almasrymina@google.com>
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
next prev parent 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 [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 [this message]
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-3-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