From: netdev-bot+sashiko@kernel.org
To: david@kernel.org
Cc: davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
pabeni@redhat.com, horms@kernel.org, akpm@linux-foundation.org,
kas@kernel.org, songliubraving@fb.com, hannes@cmpxchg.org,
riel@surriel.com, willy@infradead.org, ncardwell@google.com,
kuniyu@google.com, pfalcato@suse.de, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
stable@vger.kernel.org
Subject: Re: [PATCH net 1/4] net: skbuff: limit folio refcount when copying skb frag references
Date: Sun, 22 Nov 2026 09:19:35 +0000 [thread overview]
Message-ID: <179533917558.3135.17684828734142496084@kernel.org> (raw)
In-Reply-To: <20261118-skb_refcount_overflow-v1-1-5551b4954c3f@kernel.org>
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_frag_try_ref() (include/linux/skbuff_ref.h) sends every frag
page that is neither page_pool nor net_iov through try_get_page() ->…
- [Low] The patch is tagged Cc: stable with Fixes tags going back to v4.8
(800d8c63b2e9).
--
net: skbuff: limit folio refcount when copying skb frag references
This patch adds skb_frag_try_ref() and skb_frags_try_ref(). They take
non-page_pool frag page references through try_get_page(), so the folio
refcount limit is enforced. pskb_expand_head(), __pskb_copy_fclone(),
skb_zerocopy() and pskb_carve_inside_*() now use them and fail when a
reference is refused.
> diff --git a/include/linux/skbuff_ref.h b/include/linux/skbuff_ref.h
> index b6f6da556ee90..560ddc863bbec 100644
> --- a/include/linux/skbuff_ref.h
> +++ b/include/linux/skbuff_ref.h
> @@ -44,6 +44,33 @@ static __always_inline void skb_frag_ref(struct sk_buff *skb, int f)
> skb->pp_recycle);
> }
>
> +/**
> + * skb_frag_try_ref - try to acquire a reference on a paged fragment of an skb
> + * @skb: the buffer
> + * @f: the fragment offset
> + *
> + * Like skb_frag_ref(), but acquires non-page_pool page references using
> + * try_get_page(), refusing additional references to a page whose refcount is
> + * at its limit.
[Severity: Low]
This isn't a bug in mainline, but the refusal described here only works
because try_get_page() enforces the refcount limit. That check was added
by commit c6c9a4c1c9a1 ("mm: limit pagecache folio refcount when splicing
into pipes"), which builds on 26b8f029ce52 ("mm: limit pagecache folio
refcount when mapping pages").
Before those commits, try_get_page() had no upper bound:
page = compound_head(page);
if (WARN_ON_ONCE(page_ref_count(page) <= 0))
return false;
page_ref_inc(page);
return true;
This patch has Cc: stable and Fixes tags back to 800d8c63b2e9. A backport
to a tree without the prerequisites would still compile. There,
skb_frag_try_ref() would never refuse a reference and would only warn
after the refcount has wrapped.
Could the commit message state this dependency, for example with a
"# depends on" note on the stable tag?
> + *
> + * Return: True if a reference was acquired, otherwise false.
> + */
> +static __always_inline __must_check bool skb_frag_try_ref(struct sk_buff *skb,
> + int f)
> +{
> + netmem_ref netmem = skb_frag_netmem(&skb_shinfo(skb)->frags[f]);
> +
> +#ifdef CONFIG_PAGE_POOL
> + if (skb->pp_recycle && napi_pp_get_page(netmem))
> + return true;
> +#endif
> + if (netmem_is_net_iov(netmem)) {
> + net_iov_inc_ref(netmem_to_net_iov(netmem));
> + return true;
> + }
> + return try_get_page(netmem_to_page(netmem));
[Severity: High]
Can this make the converted paths fail on every packet for drivers that
deliberately keep RX page refcounts near INT_MAX?
Every frag that is neither page_pool nor net_iov now goes through
try_get_page()->folio_get_checked()->__folio_ref_count_over_limit(). That
check applies to any folio, not just pagecache folios.
The gve driver uses GQI RDA/QPL and DQO-QPL, and none of these use
page_pool. It biases its RX pages up to INT_MAX:
drivers/net/ethernet/google/gve/gve_rx.c:gve_setup_rx_buffer() {
...
/* The page already has 1 ref */
page_ref_add(page, INT_MAX - 1);
page_info->pagecnt_bias = INT_MAX;
}
The qpl_copy_pool setup in gve_rx.c and gve_alloc_qpl_page_dqo() do the
same thing.
Handing a frag to the stack only decrements the private bias. When the
bias runs out, the page count is raised back to INT_MAX:
drivers/net/ethernet/google/gve/gve_utils.c:gve_dec_pagecnt_bias() {
page_info->pagecnt_bias--;
if (page_info->pagecnt_bias == 0) {
int pagecount = page_count(page_info->page);
...
page_ref_add(page_info->page, INT_MAX - pagecount);
}
}
So for roughly the first 33M frees of each ring page, page_count() stays
at or above FOLIO_REF_COUNT_ADMIN_LIMIT. For roughly the first 67M it
stays at or above FOLIO_REF_COUNT_LIMIT.
In that range folio_ref_count_over_limit_slowpath() refuses the reference:
if (ref_count >= FOLIO_REF_COUNT_ADMIN_LIMIT)
goto over_limit;
...
if (!in_task())
goto over_limit;
It refuses unconditionally above the admin limit, and always in softirq.
Each refusal also prints the ratelimited "reached refcount limit" warning.
If that's right, these paths would fail every time for gve RX skbs that
carry page frags, i.e. packets larger than rx_copybreak:
nfqnl_build_packet_message()->skb_zerocopy()
(NFQUEUE copy-packet mode, the packet is dropped)
queue_userspace_packet()->skb_zerocopy()
(OVS upcall fails)
___pskb_trim()->pskb_expand_head() on a cloned skb
(AF_PACKET with snaplen < len)
skb_unclone()/skb_cow()->pskb_expand_head() after a tap cloned the skb
__pskb_copy_fclone()
(pskb_copy users such as nft dup)
pskb_carve_inside_header()/pskb_carve_inside_nonlinear()
Before this patch these paths only failed when a GFP_ATOMIC allocation
failed, because get_page() kept incrementing without a check.
Later patches in the series apply the same check to skb_segment(),
skb_try_coalesce(), skb_shift(), tcp_clone_payload() and spd_fill_page().
That would also affect software GSO of forwarded GRO packets. splice()
from TCP and AF_UNIX sockets would return -EFAULT on gve-received data.
The kernel-doc for __folio_ref_count_over_limit() in include/linux/mm.h
says "Checking other folios does no harm.". That doesn't seem to hold for
drivers that bias refcounts this way.
There is also a more speculative issue. folio_get_checked() has an
unconditional WARN_ON_ONCE(ref_count <= 0). If any remaining unchecked
get_page() wraps such a page to INT_MIN, a later skb_frag_try_ref() on it
would fire a real WARN. One example is iptfs_skb_add_frags() in
xfrm_iptfs on RX outer-packet frags. Under panic_on_warn, a remote sender
could trigger that WARN.
Since this is Cc: stable, would it be better to restrict the check to
pagecache folios in these net paths? Alternatively, gve could stop biasing
to INT_MAX, with that change backported as a prerequisite.
> +}
> +
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118-skb_refcount_overflow-v1-0-5551b4954c3f%40kernel.org
next prev parent reply other threads:[~2026-11-22 9:19 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 8:32 [PATCH net 0/4] net: skbuff: limit pagecache folio refcount David Hildenbrand (Arm)
2026-11-18 8:32 ` [PATCH net 1/4] net: skbuff: limit folio refcount when copying skb frag references David Hildenbrand (Arm)
2026-11-19 13:53 ` David Hildenbrand (Arm)
2026-11-20 16:21 ` Stanislav Fomichev
2026-11-20 21:01 ` David Hildenbrand (Arm)
2026-11-22 9:19 ` netdev-bot+sashiko [this message]
2026-11-18 8:32 ` [PATCH net 2/4] net: skbuff: limit folio refcount when rearranging skb frags David Hildenbrand (Arm)
2026-11-22 9:19 ` netdev-bot+sashiko
2026-11-18 8:32 ` [PATCH net 3/4] net: skbuff: limit folio refcount when splicing pages into skbs David Hildenbrand (Arm)
2026-11-22 9:19 ` netdev-bot+sashiko
2026-11-18 8:32 ` [PATCH net 4/4] net: skbuff: limit folio refcount when splicing from sockets David Hildenbrand (Arm)
2026-11-22 9:19 ` netdev-bot+sashiko
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=179533917558.3135.17684828734142496084@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=davem@davemloft.net \
--cc=david@kernel.org \
--cc=edumazet@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=horms@kernel.org \
--cc=kas@kernel.org \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pfalcato@suse.de \
--cc=riel@surriel.com \
--cc=songliubraving@fb.com \
--cc=stable@vger.kernel.org \
--cc=willy@infradead.org \
/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
all inboxes | Powered by JetHome®