BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Yiyang Chen" <chenyy23@mails.tsinghua.edu.cn>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf v3 1/2] bpf: Fix packet pointer invalidation for skb dynptr writes
Date: Mon, 15 Jun 2026 14:35:01 +0000	[thread overview]
Message-ID: <20260615143501.837A01F000E9@smtp.kernel.org> (raw)
In-Reply-To: <baea5363a0e35d1dc16d41b972d9a9e89cc85b46.1781531784.git.chenyy23@mails.tsinghua.edu.cn>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [Critical] The `bpf_dynptr_write` helper fails to invalidate packet pointers in global subprograms, leading to a Use-After-Free vulnerability.
--

commit a8b2f9ebe5479e8968087326226bb472f13ee1e0
Author: Yiyang Chen <chenyy23@mails.tsinghua.edu.cn>

bpf: Fix packet pointer invalidation for skb dynptr writes

This patch ensures that skb-backed dynptr writer kfuncs invalidate checked
direct packet pointers, following the same rule as the bpf_dynptr_write()
helper. It updates the CFG analysis to mark these kfuncs as packet-changing
and invalidates packet pointers when the dynptr might be skb-backed.

[ ... ]

> diff --git a/kernel/bpf/cfg.c b/kernel/bpf/cfg.c
> index 26d37066465f3..7ed6bdd986bc8 100644
> --- a/kernel/bpf/cfg.c
> +++ b/kernel/bpf/cfg.c
> @@ -516,7 +516,7 @@ static int visit_insn(int t, struct bpf_verifier_env *env)
>  			 */
>  			if (ret == 0 && bpf_is_kfunc_sleepable(&meta))
>  				mark_subprog_might_sleep(env, t);
> -			if (ret == 0 && bpf_is_kfunc_pkt_changing(&meta))
> +			if (ret == 0 && bpf_kfunc_may_change_pkt_data(&meta))
>  				mark_subprog_changes_pkt_data(env, t);

[Severity: Critical]
This is a pre-existing issue, but since this patch aims to make kfuncs
follow the same rule as the bpf_dynptr_write() helper, could there be a
similar regression with the helper itself?

When bpf_dynptr_write() is called within a global subprogram using an
unspecialized LOCAL dynptr argument that is actually backed by an skb,
does it fail to invalidate packet pointers?

In cfg.c:visit_insn(), CFG analysis appears to miss the side-effect of
bpf_dynptr_write() because the helper cannot be included in
bpf_helper_changes_pkt_data() without triggering a verifier bug in
check_helper_call() (due to its arg1_type being ARG_PTR_TO_DYNPTR
instead of ARG_PTR_TO_CTX).

Furthermore, during the normal verification path in verifier.c:
check_helper_call(), does the check:

	if (dynptr_type == BPF_DYNPTR_TYPE_SKB ||
	    dynptr_type == BPF_DYNPTR_TYPE_SKB_META)
		changes_data = true;

fail to identify BPF_DYNPTR_TYPE_LOCAL arguments from global subprograms
that may be skb-backed? 

If packet pointers are not invalidated, writing to the dynptr might pull
the skb and reallocate the packet buffer, leaving old packet pointers
pointing to freed memory and resulting in a use-after-free.

>  			if (ret == 0 && bpf_is_throw_kfunc(insn))
>  				mark_subprog_might_throw(env, t);

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1781531784.git.chenyy23@mails.tsinghua.edu.cn?part=1

  reply	other threads:[~2026-06-15 14:35 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-15 12:28 [PATCH bpf v2 0/2] bpf: Fix packet pointer invalidation for skb dynptr writes Yiyang Chen
2026-06-15 12:28 ` [PATCH bpf v2 1/2] " Yiyang Chen
2026-06-15 12:53   ` sashiko-bot
2026-06-15 12:28 ` [PATCH bpf v2 2/2] selftests/bpf: Add skb dynptr writer packet invalidation tests Yiyang Chen
2026-06-15 14:14 ` [PATCH bpf v3 0/2] bpf: Fix packet pointer invalidation for skb dynptr writes Yiyang Chen
2026-06-15 14:14   ` [PATCH bpf v3 1/2] " Yiyang Chen
2026-06-15 14:35     ` sashiko-bot [this message]
2026-06-15 15:52     ` Alexei Starovoitov
2026-06-15 16:46       ` Yiyang Chen
2026-06-15 17:30         ` Alexei Starovoitov
2026-06-15 17:59           ` Yiyang Chen
2026-06-15 14:14   ` [PATCH bpf v3 2/2] selftests/bpf: Add skb dynptr writer packet invalidation tests Yiyang Chen
2026-06-15 15:15   ` [PATCH bpf v4 0/2] bpf: Fix packet pointer invalidation for skb dynptr writes Yiyang Chen
2026-06-15 15:15     ` [PATCH bpf v4 1/2] " Yiyang Chen
2026-06-15 15:39       ` sashiko-bot
2026-06-15 15:15     ` [PATCH bpf v4 2/2] selftests/bpf: Add skb dynptr writer packet invalidation tests Yiyang Chen
2026-06-15 16:26       ` bot+bpf-ci
2026-06-15 17:49     ` [PATCH bpf v5 0/2] bpf: Fix packet pointer invalidation for skb dynptr writes Yiyang Chen
2026-06-15 17:49       ` [PATCH bpf v5 1/2] " Yiyang Chen
2026-06-15 17:52         ` Alexei Starovoitov
2026-06-15 22:10         ` sashiko-bot
2026-06-15 17:49       ` [PATCH bpf v5 2/2] selftests/bpf: Add skb dynptr writer packet invalidation tests Yiyang Chen
2026-06-15 18:39         ` bot+bpf-ci

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=20260615143501.837A01F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=chenyy23@mails.tsinghua.edu.cn \
    --cc=sashiko-reviews@lists.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