Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Slawomir Stepien <sst@poczta.fm>
To: bot+bpf-ci@kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, davem@davemloft.net,
	kuba@kernel.org, hawk@kernel.org, john.fastabend@gmail.com,
	sdf@fomichev.me, bpf@vger.kernel.org, netdev@vger.kernel.org,
	maciej.fijalkowski@intel.com, tianyi@cloudflare.com,
	tavip@google.com, toke@redhat.com, aleksander.lobakin@intel.com,
	ilias.apalodimas@linaro.org, lorenzo@kernel.org,
	magnus.karlsson@intel.com, ihor.solodrai@linux.dev,
	edumazet@kernel.org, pabeni@redhat.com, andrew+netdev@lunn.ch,
	horms@kernel.org, andrii@kernel.org, martin.lau@linux.dev,
	eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev,
	jolsa@kernel.org, memxor@gmail.com, shuah@kernel.org,
	linux-kselftest@vger.kernel.org,
	syzbot+ff145014d6b0ce64a173@syzkaller.appspotmail.com,
	stable@vger.kernel.org, martin.lau@kernel.org, mason@kernel.org
Subject: Re: [PATCH v7 bpf 2/5] xdp: introduce xdp_convert_skb_to_buff()
Date: Fri, 20 Nov 2026 09:45:30 +0100	[thread overview]
Message-ID: <awAIqhZWK9mr_zGQ@nr200> (raw)
In-Reply-To: <fd9b43958f6297b0031158bd33bdc6cc54f3c9338a4ee2e30bd6e50acf775a60@mail.kernel.org>

On lis 19, 2026 14:11, bot+bpf-ci@kernel.org wrote:
> > xdp: introduce xdp_convert_skb_to_buff()
> 
> TL;DR:
> - Commit message calls the bug a page leak; it may be a use-after-free of
>   page_pool pages
> - Stable Cc 6.4.x predates the Fixes: tag (v6.9)
> - kdoc may overstate mem type usage (nit)
> 
> > Then when bpf_xdp_adjust_tail() calls
> > __xdp_return(), it acts incorrectly due to mem type not being set to
> > MEM_TYPE_PAGE_POOL and causes a page leak.
> 
> Is "causes a page leak" the full impact?
> 
> The mechanism is bpf_xdp_adjust_tail() -> bpf_xdp_frags_shrink_tail() ->
> bpf_xdp_shrink_data() -> __xdp_return(netmem, MEM_TYPE_PAGE_SHARED) ->
> page_frag_free().  That ends in put_page_testzero() on a page_pool page.
> 
> With page checks enabled this is reported as "page_pool leak" and the page
> is not freed.  Without them, page_pool keeps _refcount at 1 and counts
> fragment users in pp_ref_count, and skb_pp_cow_data() allocates
> fragment-sized chunks.  A single page_frag_free() can therefore hand back
> to the buddy allocator a page that other skbs or pool->frag_page still
> use, which looks like a use-after-free rather than only a leak.
> 
> Could the commit message describe that?

Yes, I will add that do commit message in v8.

> > Cc: <stable@vger.kernel.org> # 6.4.x
> 
> The Fixes: tag points at e6d5dbdd20aa, which first landed in v6.9.  Before
> that, generic XDP linearized every skb and never set the frags flag, so
> this bug cannot occur on 6.4 through 6.8.
> 
> The later veth patch in this series (1d3541dbf827) appears to be why 6.4.x
> is listed, since it uses this helper and needs it as a backport
> prerequisite.  Could the commit message either say that, or align the
> stable range with the Fixes: tag?

Sure, v8 will describe that in v8.

> > diff --git a/include/net/xdp.h b/include/net/xdp.h
> > --- a/include/net/xdp.h
> > +++ b/include/net/xdp.h
> 
> [ ... ]
> 
> > +/**
> > + * xdp_convert_skb_to_buff - build an xdp_buff on top of an skb
> > + * @skb: skb to describe, packet data is taken from its MAC header onwards
> > + * @xdp: xdp_buff to initialize
> > + * @xdp_rxq: Rx queue info to attach to @xdp
> > + *
> > + * The memory type set on @xdp_rxq is only used to release fragments that
> > + * the XDP program consumes; the head can not be freed from under the skb.
> > + * A non-linear @skb is expected to have gone through skb_pp_cow_data(), so
> > + * all of its fragments are page_pool backed.
> > + */
> 
> This isn't a bug, but is the "only used to release fragments" statement a
> property of this helper, or of its current caller?
> 
> It holds for generic XDP.  However, the veth patch later in this series
> (1d3541dbf827) converts the xdp_buff to an xdp_frame on XDP_TX and
> XDP_REDIRECT, where the head is released through the same mem type, and it
> has to overwrite rq->xdp_rxq.mem after calling this helper.

True, will add that info to commit message in v8.

> The kdoc also does not mention that the mem type stays set on the caller's
> possibly shared @xdp_rxq after the call.  Should the kdoc say that these
> properties depend on the caller?

Yes I agree. Will add in v8.

-- 
Slawomir Stepien

  reply	other threads:[~2026-11-20  8:45 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 13:30 [PATCH v7 bpf 0/5] xdp: fix page_pool leaks Slawomir Stepien
2026-11-19 13:30 ` [PATCH v7 bpf 1/5] bpf: test_run: Use a private rxq info for XDP test runs Slawomir Stepien
2026-11-19 13:30 ` [PATCH v7 bpf 2/5] xdp: introduce xdp_convert_skb_to_buff() Slawomir Stepien
2026-11-19 14:11   ` bot+bpf-ci
2026-11-20  8:45     ` Slawomir Stepien [this message]
2026-11-19 13:30 ` [PATCH v7 bpf 3/5] veth: use the frame mem type when running XDP on an xdp_frame Slawomir Stepien
2026-11-19 13:54   ` bot+bpf-ci
2026-11-19 14:24     ` Tianyi Gao
2026-11-20  8:56       ` Slawomir Stepien
2026-11-19 13:30 ` [PATCH v7 bpf 4/5] veth: update mem type in xdp_buff Slawomir Stepien
2026-11-19 13:30 ` [PATCH v7 bpf 5/5] selftests/bpf: Shrink test_run frags after generic XDP ran on lo Slawomir Stepien

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=awAIqhZWK9mr_zGQ@nr200 \
    --to=sst@poczta.fm \
    --cc=aleksander.lobakin@intel.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bot+bpf-ci@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=eddyz87@gmail.com \
    --cc=edumazet@kernel.org \
    --cc=hawk@kernel.org \
    --cc=horms@kernel.org \
    --cc=ihor.solodrai@linux.dev \
    --cc=ilias.apalodimas@linaro.org \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=lorenzo@kernel.org \
    --cc=maciej.fijalkowski@intel.com \
    --cc=magnus.karlsson@intel.com \
    --cc=martin.lau@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mason@kernel.org \
    --cc=memxor@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=syzbot+ff145014d6b0ce64a173@syzkaller.appspotmail.com \
    --cc=tavip@google.com \
    --cc=tianyi@cloudflare.com \
    --cc=toke@redhat.com \
    --cc=yonghong.song@linux.dev \
    /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