From: netdev-bot+sashiko@kernel.org
To: almasrymina@google.com
Cc: netdev@vger.kernel.org, edumazet@kernel.org,
ncardwell@google.com, kuniyu@google.com, davem@davemloft.net,
kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
sdf@fomichev.me, kaiyuanz@google.com, willemb@google.com,
daniel@iogearbox.net, josef@toxicpanda.com, sdf.kernel@gmail.com,
dtatulea@nvidia.com, asml.silence@gmail.com,
bobbyeshleman@meta.com
Subject: Re: [PATCH net-next v6 6/7] net: prevent mixing frags from different memory providers or bindings
Date: Tue, 24 Nov 2026 08:14:30 +0000 [thread overview]
Message-ID: <179550807001.3135.15837206052330880112@kernel.org> (raw)
In-Reply-To: <20261120201408.3445445-7-almasrymina@google.com>
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
next prev parent reply other threads:[~2026-11-24 8:14 UTC|newest]
Thread overview: 17+ 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 ` [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 [this message]
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
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=179550807001.3135.15837206052330880112@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=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;
as well as URLs for NNTP newsgroup(s).