From: netdev-bot+sashiko@kernel.org
To: almasrymina@google.com
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-rdma@vger.kernel.org, bpf@vger.kernel.org,
ayush.sawal@chelsio.com, andrew+netdev@lunn.ch,
davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
pabeni@redhat.com, tariqt@nvidia.com, horms@kernel.org,
steffen.klassert@secunet.com, herbert@gondor.apana.org.au,
ncardwell@google.com, kuniyu@google.com,
john.fastabend@gmail.com, sd@queasysnail.net,
ebiggers@kernel.org, kees@kernel.org,
aleksandr.loktionov@intel.com, petrm@nvidia.com,
u.kleine-koenig@baylibre.com, j.raczynski@samsung.com,
wang.zhan@smartx.com, willemb@google.com
Subject: Re: [PATCH net-next v3 4/6] net: skbuff: replace __skb_frag_ref() with symmetric skb_netmem_ref()
Date: Thu, 15 Oct 2026 20:37:42 +0000 [thread overview]
Message-ID: <179209666252.434549.1850964039919625643@kernel.org> (raw)
In-Reply-To: <20261014173945.373295-5-almasrymina@google.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · 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).
- [Medium] The commit fixes reachable page_pool refcount imbalances but
has no Fixes: tag, so the fix will not be picked up for stable.
- [Low] In the new skb_segment() linearize branch, the bytes being
linearized are counted twice in nskb->truesize: 1) The code does…
--
net: skbuff: replace __skb_frag_ref() with symmetric skb_netmem_ref()
This patch replaces __skb_frag_ref() with skb_netmem_ref(netmem, recycle).
The new helper takes a pp_ref_count reference when recycle is set and the
netmem is page_pool backed, so it mirrors skb_netmem_unref(). The patch
also stops clearing skb->pp_recycle in skb_release_data() and propagates
pp_recycle to the destination skb in the copy, split, shift and segment
paths. It also linearizes skb_segment() output segments when frag_list
skbs have different pp_recycle bits.
Link: https://lore.kernel.org/netdev/xfrm-iptfs-pp_ref_count-underflow-v4-1-912fa72106f0@secunet.com/
> Previously, __skb_frag_ref() and skb_frag_ref() unconditionally
> incremented the non-pp backing refcount via get_netmem(), while
> skb_frag_unref() decremented pp_ref_count whenever skb->pp_recycle was
> set. Ref-ing a page_pool fragment into a pp_recycle=1 SKB (or clearing
> pp_recycle=0 on an uncloned SKB while clones still held pp_recycle=1)
> leaked the backing non-pp refcount and underflowed pp_ref_count across
> IP-TFS, skb_split(), skb_shift(), and cloned unclone paths.
[Severity: Medium]
Should this patch have a Fixes: tag so stable picks it up?
In the base tree, iptfs_skb_add_frags() takes a raw page reference on
each frag it adds. The destination skb only needs to have the same
pp_recycle as the walk, so it can be a pp_recycle=1 skb:
__skb_frag_ref(tofrag); -> get_netmem() -> get_page()
Those references are later dropped through napi_pp_put_page(), which
underflows pp_ref_count. The page can then go back to the pool while the
source skb still points at it. That code came from:
Fixes: 5f2b6a909574 ("xfrm: iptfs: add skb-fragment sharing code")
The commit message also covers only one direction of the imbalance.
The reverse case is reachable through skb_split() from batman-adv:
batadv_frag_create()
skb_fragment allocated with dev_alloc_skb() /* pp_recycle = 0 */
skb_split(skb, skb_fragment, skb->len - fragment_size)
skb_split_inside_header() /* moves frags, takes no refs */
If the forwarded RX skb has pp_recycle=1, its page_pool frags end up in a
pp_recycle=0 skb. When skb_fragment is freed, put_page() runs on them and
drops a page reference that page_pool owns.
Both directions look like they can cause a use-after-free of the page,
not just a refcount leak. Could the commit message describe the
skb_split() case and its consequence more precisely?
> diff --git a/net/core/skbuff.c b/net/core/skbuff.c
> index 980bbe9166393..96088289c234d 100644
> --- a/net/core/skbuff.c
> +++ b/net/core/skbuff.c
[ ... ]
> @@ -5057,6 +5049,16 @@ struct sk_buff *skb_segment(struct sk_buff *head_skb,
>
> while (pos < offset + len) {
> if (i >= nfrags) {
> + if (skb_shinfo(nskb)->nr_frags &&
> + nskb->pp_recycle != list_skb->pp_recycle) {
> + nskb->data_len = pos - offset - hsize;
> + nskb->len += nskb->data_len;
> + nskb->truesize += nskb->data_len;
^^^^
[Severity: Low]
Are the linearized bytes counted twice in nskb->truesize here?
nskb was allocated with only hsize + doffset + headroom, so
__skb_linearize() will usually need to grow the head:
__skb_linearize()
__pskb_pull_tail()
pskb_expand_head(skb, 0, eat + 128, ...)
nskb->sk is NULL during segmentation, so pskb_expand_head() also adds the
head growth to truesize:
if (!skb->sk || skb->destructor == sock_edemux)
skb->truesize += size - osize;
If tailroom was already enough, the head was accounted at allocation time,
so the explicit add over-counts in that case too.
hsize is reset after linearizing, so skip_fraglist only adds the remaining
frag bytes. The final truesize then looks inflated by about the
linearized byte count for each straddling segment.
Is the truesize update needed here? Would adjusting data_len and len be
enough to keep the skb consistent for __pskb_pull_tail()?
> + if (__skb_linearize(nskb))
> + goto err;
> + hsize = pos - offset;
> + nskb_frag = skb_shinfo(nskb)->frags;
> + }
> if (skb_orphan_frags(list_skb, GFP_ATOMIC) ||
> skb_zerocopy_clone(nskb, list_skb,
> GFP_ATOMIC))
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261014173945.373295-1-almasrymina%40google.com
next prev parent reply other threads:[~2026-10-15 20:37 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-14 17:37 [PATCH net-next v3 0/6] net: unify symmetric netmem and page_pool refcounting Mina Almasry
2026-10-14 17:37 ` [PATCH net-next v3 1/6] netmem: rename __get/__put_netmem() to get/put_net_iov() Mina Almasry
2026-10-15 20:37 ` netdev-bot+sashiko
2026-10-14 17:37 ` [PATCH net-next v3 2/6] net: skbuff: add napi_pp_get_page() and use it in tcp_recvmsg_dmabuf() Mina Almasry
2026-10-15 20:37 ` netdev-bot+sashiko
2026-10-14 17:37 ` [PATCH net-next v3 3/6] net: skbuff: replace skb_page_unref() and __skb_frag_unref() with skb_netmem_unref() Mina Almasry
2026-10-14 21:25 ` Stanislav Fomichev
2026-10-14 22:05 ` Mina Almasry
2026-10-14 22:39 ` Stanislav Fomichev
2026-10-15 20:37 ` netdev-bot+sashiko
2026-10-14 17:37 ` [PATCH net-next v3 4/6] net: skbuff: replace __skb_frag_ref() with symmetric skb_netmem_ref() Mina Almasry
2026-10-15 20:37 ` netdev-bot+sashiko [this message]
2026-10-14 17:37 ` [PATCH net-next v3 5/6] net: skbuff: use skb_frag_ref() in skb_try_coalesce() Mina Almasry
2026-10-14 17:37 ` [PATCH net-next v3 6/6] net: kunit: test netmem, page_pool, and skb frag refcounting Mina Almasry
2026-10-15 20:37 ` netdev-bot+sashiko
2026-10-15 21:36 ` [PATCH net-next v3 0/6] net: unify symmetric netmem and page_pool refcounting 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=179209666252.434549.1850964039919625643@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=aleksandr.loktionov@intel.com \
--cc=almasrymina@google.com \
--cc=andrew+netdev@lunn.ch \
--cc=ayush.sawal@chelsio.com \
--cc=bpf@vger.kernel.org \
--cc=davem@davemloft.net \
--cc=ebiggers@kernel.org \
--cc=edumazet@kernel.org \
--cc=herbert@gondor.apana.org.au \
--cc=horms@kernel.org \
--cc=j.raczynski@samsung.com \
--cc=john.fastabend@gmail.com \
--cc=kees@kernel.org \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=petrm@nvidia.com \
--cc=sd@queasysnail.net \
--cc=steffen.klassert@secunet.com \
--cc=tariqt@nvidia.com \
--cc=u.kleine-koenig@baylibre.com \
--cc=wang.zhan@smartx.com \
--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