From: sashiko-bot@kernel.org
To: "Yiyang Chen" <chenyy23@mails.tsinghua.edu.cn>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf v2 1/2] bpf: Fix packet pointer invalidation for skb dynptr writes
Date: Mon, 15 Jun 2026 12:53:32 +0000 [thread overview]
Message-ID: <20260615125333.42DDE1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <72711041414b27e996c6a25f6fd72903acee589f.1781525896.git.chenyy23@mails.tsinghua.edu.cn>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Static CFG analysis incorrectly assumes dynptr writers do not change packet data, leading to Use-After-Free via global subprograms and freplace.
--
commit 1c2eddecfcf22d7859e70204534b70a21c8883bc
Author: Yiyang Chen <chenyy23@mails.tsinghua.edu.cn>
bpf: Fix packet pointer invalidation for skb dynptr writes
This patch modifies the verifier to treat skb dynptr writer kfuncs as
packet-changing operations, ensuring that direct packet pointers are
invalidated after calls like bpf_dynptr_copy or bpf_dynptr_memset.
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 2abc79dbf281c..5ea51bd284f84 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
[ ... ]
> @@ -11229,7 +11260,33 @@ static bool is_kfunc_bpf_preempt_enable(struct bpf_kfunc_call_arg_meta *meta)
>
> bool bpf_is_kfunc_pkt_changing(struct bpf_kfunc_call_arg_meta *meta)
> {
> - return meta->func_id == special_kfunc_list[KF_bpf_xdp_pull_data];
> + return meta->func_id == special_kfunc_list[KF_bpf_xdp_pull_data] ||
> + meta->pkt_dynptr_write;
> +}
[Severity: High]
Does this modification cause issues during the control flow graph analysis
phase?
Looking at kernel/bpf/cfg.c, check_cfg() calls bpf_is_kfunc_pkt_changing()
using a statically fetched meta where register states are not yet available:
kernel/bpf/cfg.c:check_cfg() {
...
if (ret == 0 && bpf_is_kfunc_pkt_changing(&meta))
mark_subprog_changes_pkt_data(env, t);
...
}
Since pkt_dynptr_write is only evaluated later during check_kfunc_args()
based on register states, will it always be false during CFG analysis?
If so, it seems this might leave the changes_pkt_data flag incorrectly set
to false for subprograms mutating packets via dynptr writers.
Could this lead to use-after-free scenarios with global subprograms or
freplace? For example, if a global subprogram's dynptr argument is
defaulted to BPF_DYNPTR_TYPE_LOCAL in btf_prepare_func_args():
kernel/bpf/verifier.c:btf_prepare_func_args() {
...
} else if (arg->arg_type == ARG_PTR_TO_DYNPTR) {
__mark_dynptr_reg(reg, BPF_DYNPTR_TYPE_LOCAL, true, ++env->id_gen, 0);
...
}
Will the dynptr write evade detection entirely, leaving the caller with
stale, uninvalidated packet pointers?
> +
> +static bool dynptr_type_pkt_data(enum bpf_dynptr_type type)
> +{
> + return type == BPF_DYNPTR_TYPE_SKB ||
> + type == BPF_DYNPTR_TYPE_SKB_META;
> +}
[ ... ]
> @@ -12214,6 +12271,9 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_kfunc_call_
> &meta->ref_obj, &meta->dynptr);
> if (ret < 0)
> return ret;
> + if (is_kfunc_pkt_dynptr_writer(meta, i) &&
> + dynptr_type_pkt_data(meta->dynptr.type))
> + meta->pkt_dynptr_write = true;
> break;
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1781525896.git.chenyy23@mails.tsinghua.edu.cn?part=1
next prev parent reply other threads:[~2026-06-15 12:53 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 [this message]
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
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=20260615125333.42DDE1F000E9@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