From: Yonghong Song <yonghong.song@linux.dev>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>,
bot+bpf-ci@kernel.org, bpf@vger.kernel.org
Cc: ast@kernel.org, andrii@kernel.org, daniel@iogearbox.net,
eddyz87@gmail.com, kernel-team@fb.com, martin.lau@kernel.org,
mason@kernel.org, ihor.solodrai@linux.dev
Subject: Re: [PATCH bpf-next v2 03/20] bpf: Add lookups for exception cleanup resumes and landing pads
Date: Sat, 19 Sep 2026 10:42:41 -0700 [thread overview]
Message-ID: <b26afda4-a84a-4aa9-bd8e-0d56d1daafb8@linux.dev> (raw)
In-Reply-To: <DLJ0XC51BJVC.3P80YCN4K6KP6@gmail.com>
On 9/18/26 9:55 PM, Alexei Starovoitov wrote:
> On Fri Sep 18, 2026 at 5:44 AM UTC, bot+bpf-ci wrote:
>>> diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h
>>> index c08505b9ba821..f9bccd3e0f4db 100644
>>> --- a/include/linux/bpf_verifier.h
>>> +++ b/include/linux/bpf_verifier.h
>>> @@ -681,6 +681,11 @@ struct bpf_insn_aux_data {
>>> bool needs_zext; /* alu op needs to clear upper bits */
>>> bool non_sleepable; /* helper/kfunc may be called from non-sleepable context */
>>> bool is_iter_next; /* bpf_iter_<type>_next() kfunc call */
>>> + /*
>>> + * 1 + the instruction index of the exception cleanup landing pad this
>>> + * call site unwinds to, or 0 for none.
>>> + */
>>> + u32 cleanup_pad;
>>> bool call_with_percpu_alloc_ptr; /* {this,per}_cpu_ptr() with prog percpu alloc */
>>> u8 alu_state; /* used in combination with alu_limit */
>> [ ... ]
>>
>>> diff --git a/kernel/bpf/fixups.c b/kernel/bpf/fixups.c
>>> index 2add8001c3ec3..82b00fac6bd6a 100644
>>> --- a/kernel/bpf/fixups.c
>>> +++ b/kernel/bpf/fixups.c
>>> @@ -261,6 +261,11 @@ static void adjust_insn_aux_data(struct bpf_verifier_env *env,
>>> }
>>> }
>>>
>>> + if (env->cleanup_info_cnt)
>>> + for (i = 0; i < prog_len; i++)
>>> + if (data[i].cleanup_pad > off + 1)
>>> + data[i].cleanup_pad += cnt - 1;
>>> +
>> [ ... ]
>>
>>> @@ -549,6 +554,7 @@ static int verifier_remove_insns(struct bpf_verifier_env *env, u32 off, u32 cnt)
>>> struct bpf_insn_aux_data *aux_data = env->insn_aux_data;
>>> unsigned int orig_prog_len = env->prog->len;
>>> int err;
>>> + u32 i;
>>>
>>> if (bpf_prog_is_offloaded(env->prog->aux))
>>> bpf_prog_offload_remove_insns(env, off, cnt);
>>> @@ -573,6 +579,17 @@ static int verifier_remove_insns(struct bpf_verifier_env *env, u32 off, u32 cnt)
>>> sizeof(*aux_data) * (orig_prog_len - off - cnt));
>>> env->insn_aux_data_len -= cnt;
>>>
>>> + if (env->cleanup_info_cnt) {
>>> + for (i = 0; i < env->insn_aux_data_len; i++) {
>>> + u32 pad = aux_data[i].cleanup_pad;
>>> +
>>> + if (pad > off + cnt)
>>> + aux_data[i].cleanup_pad = pad - cnt;
>>> + else if (pad > off)
>>> + aux_data[i].cleanup_pad = 0;
>>> + }
>>> + }
>>> +
>>> return 0;
>>> }
>> Can this logic handle NOP removal correctly? When bpf_opt_remove_nops()
>> calls verifier_remove_insns(env, i, 1) to remove a single fall-through
>> goto +0, if a cleanup record names that instruction as its landing pad,
>> then pad == off + 1, so pad > off is true and cleanup_pad becomes 0.
>>
>> But removing the NOP leaves the pad's next instruction at the same
>> index, so the correct landing pad index stays unchanged rather than
>> being zeroed. For example:
>>
>> off: some_call with cleanup_pad = off+1
>> off+1: goto +0 (NOP landing pad)
>> off+2: actual cleanup code
>>
>> After removing the NOP at off+1:
>>
>> off: some_call (cleanup_pad should still be off+1)
>> off+1: actual cleanup code (was at off+2)
>>
>> The `else if (pad > off)` arm erases the record instead of preserving
>> it. Nothing rejects NOP landing pads during validation - a goto +0 has
>> code 0x05, not 0x00, so check_cleanup_info() accepts it.
>>
>> The ordering makes the loss escape validation: bpf_check_cleanup_exceptions()
>> runs before bpf_opt_remove_nops(), so the verifier proves the cleanup
>> path releases acquired references, but then the NOP removal zeroes
>> cleanup_pad, and later cleanup_info_for_subprog() sees `if (!pad)
>> continue;` and omits the record from the runtime table. The program is
>> accepted but bpf_throw() finds no pad for that call site and skips the
>> cleanup, leaking whatever the pad was supposed to release.
>>
>> Does the `else if (pad > off)` arm need to distinguish removals that
>> consume the landing pad instruction itself versus removals that happen
>> before it?
> bot is correct here.
> pls fix
Agree with bot about for two different cases. Will fix.
>
> pw-bot: cr
next prev parent reply other threads:[~2026-09-19 17:42 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-18 4:41 [PATCH bpf-next v2 00/20] bpf: Run exception cleanup landing pads when bpf_throw() unwinds Yonghong Song
2026-09-18 4:42 ` [PATCH bpf-next v2 01/20] bpf: Accept the compiler's exception cleanup table at program load Yonghong Song
2026-09-18 4:42 ` [PATCH bpf-next v2 02/20] bpf: Add the bpf_unwind_resume() kfunc Yonghong Song
2026-09-18 4:42 ` [PATCH bpf-next v2 03/20] bpf: Add lookups for exception cleanup resumes and landing pads Yonghong Song
2026-09-18 5:44 ` bot+bpf-ci
2026-09-19 4:55 ` Alexei Starovoitov
2026-09-19 17:42 ` Yonghong Song [this message]
2026-09-18 4:42 ` [PATCH bpf-next v2 04/20] bpf: Mark the call sites an exception cleanup table covers Yonghong Song
2026-09-18 4:42 ` [PATCH bpf-next v2 05/20] bpf: Make exception landing pads reachable in the CFG Yonghong Song
2026-09-18 4:59 ` sashiko-bot
2026-09-19 19:17 ` Yonghong Song
2026-09-18 5:44 ` bot+bpf-ci
2026-09-19 19:32 ` Yonghong Song
2026-09-18 4:42 ` [PATCH bpf-next v2 06/20] bpf: Explore the landing pads no call site reaches Yonghong Song
2026-09-18 5:44 ` bot+bpf-ci
2026-09-19 19:32 ` Yonghong Song
2026-09-18 4:42 ` [PATCH bpf-next v2 07/20] bpf: Refuse exception cleanup shapes bpf_throw() cannot dispatch Yonghong Song
2026-09-18 4:42 ` [PATCH bpf-next v2 08/20] bpf: Walk the exception unwind in the verifier Yonghong Song
2026-09-18 4:42 ` [PATCH bpf-next v2 09/20] bpf: Refuse a private stack for a program with an exception cleanup table Yonghong Song
2026-09-18 5:44 ` bot+bpf-ci
2026-09-19 19:37 ` Yonghong Song
2026-09-18 4:42 ` [PATCH bpf-next v2 10/20] bpf: Dispatch exception cleanup pads from bpf_throw() Yonghong Song
2026-09-18 5:58 ` bot+bpf-ci
2026-09-19 19:54 ` Yonghong Song
2026-09-18 4:42 ` [PATCH bpf-next v2 11/20] bpf, x86: Dispatch exception cleanup pads at run time Yonghong Song
2026-09-18 5:03 ` sashiko-bot
2026-09-19 20:00 ` Yonghong Song
2026-09-18 5:44 ` bot+bpf-ci
2026-09-19 20:04 ` Yonghong Song
2026-09-18 4:43 ` [PATCH bpf-next v2 12/20] bpf, arm64: " Yonghong Song
2026-09-18 5:44 ` bot+bpf-ci
2026-09-19 20:07 ` Yonghong Song
2026-09-18 4:43 ` [PATCH bpf-next v2 13/20] libbpf: Resolve the compiler's _Unwind_Resume to the kernel's kfunc Yonghong Song
2026-09-18 4:43 ` [PATCH bpf-next v2 14/20] libbpf: Add cleanup_info to bpf_prog_load_opts Yonghong Song
2026-09-18 4:57 ` sashiko-bot
2026-09-19 20:18 ` Yonghong Song
2026-09-18 4:43 ` [PATCH bpf-next v2 15/20] libbpf: Collect .bpf_cleanup records and pass them to the kernel Yonghong Song
2026-09-18 5:00 ` sashiko-bot
2026-09-19 20:21 ` Yonghong Song
2026-09-18 4:43 ` [PATCH bpf-next v2 16/20] libbpf: Carry the exception cleanup table through the light skeleton Yonghong Song
2026-09-18 5:02 ` sashiko-bot
2026-09-19 20:27 ` Yonghong Song
2026-09-18 4:43 ` [PATCH bpf-next v2 17/20] libbpf: Let the static linker carry .bpf_cleanup relocations Yonghong Song
2026-09-18 5:01 ` sashiko-bot
2026-09-19 20:31 ` Yonghong Song
2026-09-18 5:44 ` bot+bpf-ci
2026-09-19 20:32 ` Yonghong Song
2026-09-18 4:43 ` [PATCH bpf-next v2 18/20] selftests/bpf: Add an end-to-end .bpf_cleanup exception test Yonghong Song
2026-09-18 4:59 ` sashiko-bot
2026-09-18 5:58 ` bot+bpf-ci
2026-09-19 20:34 ` Yonghong Song
2026-09-18 4:43 ` [PATCH bpf-next v2 19/20] selftests/bpf: Cover the exception cleanup shapes the chain does not reach Yonghong Song
2026-09-18 5:01 ` sashiko-bot
2026-09-18 5:44 ` bot+bpf-ci
2026-09-19 21:13 ` Yonghong Song
2026-09-18 4:43 ` [PATCH bpf-next v2 20/20] selftests/bpf: Load an exception cleanup program from a light skeleton Yonghong Song
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=b26afda4-a84a-4aa9-bd8e-0d56d1daafb8@linux.dev \
--to=yonghong.song@linux.dev \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bot+bpf-ci@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=ihor.solodrai@linux.dev \
--cc=kernel-team@fb.com \
--cc=martin.lau@kernel.org \
--cc=mason@kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.