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] This patch can free a page_pool page through the page
allocator.
- [Low] The commit message describes a live bug that no in-tree driver
path has been shown to reach, and it carries two Fixes: tags that will…
--
net: gro: reset unreadable and pp_recycle in napi_reuse_skb
This patch clears skb->unreadable and skb->pp_recycle in napi_reuse_skb().
The goal is to stop that state carrying over from a cached napi->skb onto
later packets. It carries Fixes: tags for the page_pool recycling hint and
unreadable frags commits.
> When an unreadable or page_pool-backed skb is
> cached and later reused for a normal readable packet (for instance across
> queue reconfiguration or shared NAPI instances), leaving skb->unreadable
> and skb->pp_recycle set on napi->skb leaks stale state onto subsequent
> packets, corrupting readability checks and causing skb_gro_receive() to
> refuse GRO merges due to mismatched pp_recycle state.
[Severity: Low]
Is there an in-tree driver path that reaches this state?
For unreadable, gve is the only driver that uses napi_get_frags() together
with unreadable netmem. gve_rx_dqo() reaches napi_get_frags() only when the
first frag is the data buffer, which is a net_iov on a devmem queue.
For such an skb, skb_gro_reset_offset() leaves frag0_len at 0. The Ethernet
pull in napi_frags_skb() then fails, because __pskb_pull_tail() returns NULL
when !skb_frags_readable(). With the earlier patch in this series ("net: gro:
free skb on napi_frags_skb() header pull failure"), the skb is freed. It
never reaches napi_reuse_skb() with unreadable set.
For queue reconfiguration, napi->skb is freed on this path, so nothing
cached survives:
gve_rx_stop_ring_dqo()
gve_remove_napi()
netif_napi_del()
napi_free_frags()
For pp_recycle, gve_rx_dqo() marks every napi_get_frags() skb again:
if (rx->dqo.page_pool)
skb_mark_for_recycle(rx->ctx.skb_head);
The other producer that leaves pp_recycle set on napi->skb is tun's XDP COW
path. There the flag is correct (see the comment on the diff below).
The KUnit test added later in the series ("net: kunit: test unreadable
net_iov napi_gro_frags") builds this state by hand. It doesn't show a driver
path that produces it.
Should this be described as hardening, with the Fixes: tags reconsidered
since they would send it to stable? Or could the message name a concrete
in-tree driver sequence that triggers it?
> diff --git a/net/core/gro.c b/net/core/gro.c
> index fb730017fd3ba..c1d07bca1b4eb 100644
> --- a/net/core/gro.c
> +++ b/net/core/gro.c
> @@ -697,6 +697,8 @@ static void napi_reuse_skb(struct napi_struct *napi, struct sk_buff *skb)
>
> skb->encapsulation = 0;
> skb->ip_summed = CHECKSUM_NONE;
> + skb->unreadable = 0;
> + skb->pp_recycle = 0;
^^^^
[Severity: Medium]
Can clearing pp_recycle here free a page_pool head through the page
allocator?
napi_reuse_skb() keeps skb->head. This reset assumes the head of every skb
cached on napi->skb is not page_pool memory. That holds for
napi_get_frags(), but tun can store a different skb in napi.skb. This
happens in tun_get_user() with IFF_NAPI_FRAGS and a generic XDP program
attached:
drivers/net/tun.c:tun_get_user() {
...
ret = do_xdp_generic(xdp_prog, &skb);
...
if (frags && skb != tfile->napi.skb)
tfile->napi.skb = skb;
...
}
The frags skb is always nonlinear, so do_xdp_generic() can replace it:
do_xdp_generic()
netif_receive_generic_xdp()
netif_skb_check_for_xdp()
skb_cow_data_for_xdp()
skb_pp_cow_data()
skb_pp_cow_data() builds the new head with page_pool_dev_alloc_va() and
napi_build_skb(), so head_frag is 1. It then calls skb_mark_for_recycle().
Suppose skb_gro_receive() merges that skb with headlen <= offset. It sets
NAPI_GRO_CB(skb)->free = NAPI_GRO_FREE, and napi_frags_finish() passes the
skb to napi_reuse_skb(). pp_recycle is then cleared while skb->head is still
a page_pool page.
The cached skb can be freed next in several ways:
- consume_skb() in skb_pp_cow_data() on the next XDP COW
- napi_free_frags() from netif_napi_del()
- a tun drop path
In each case skb_free_head() would take the non-recycle branch:
net/core/skbuff.c:skb_free_head() {
...
if (skb->head_frag) {
if (skb_pp_recycle(skb, head))
return;
skb_free_frag(head);
...
}
Wouldn't that return the page_pool page to the buddy allocator? It would
then trip the page_pool_page_is_pp() bad page check and throw off
page_pool's in-flight accounting.
Before this patch, pp_recycle stayed set across reuse and the head was
recycled correctly. Mixing it with tun's non-page_pool frags was fine,
because napi_pp_put_page() falls back for non-pp netmem.
Reaching this needs all of the following:
- CAP_NET_ADMIN
- an XDP program with frags support on the tun device
- deferred NAPI completion (napi_defer_hard_irqs or gro_flush_timeout)
- a merge where the linear length exactly matches the GRO header offset
Could pp_recycle be cleared only when the head is not page_pool memory? For
example:
!skb->head_frag ||
!page_pool_page_is_pp(virt_to_head_page(skb->head))
Checking !head_frag alone wouldn't be enough, because napi_alloc_skb() can
also return head_frag skbs.
Other options would be to drop the pp_recycle reset, or to make sure
napi->skb only ever comes from napi_get_frags().
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cove…%40google.com