🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
1 messages
1 total messages Started by netdev-bot+sashiko Tue, 24 Nov 2026 08:14
Re: [PATCH net-next v6 6/7] net: prevent mixing frags from different memory providers or bindings
#21593
Author: netdev-bot+sashiko
Date: Tue, 24 Nov 2026 08:14
173 lines
13981 bytes
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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads