From: sashiko-bot@kernel.org
To: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v2 01/21] bpf: Stop a load only when the loader is killed or has to freeze
Date: Mon, 16 Nov 2026 16:15:50 +0000 [thread overview]
Message-ID: <sashiko-outbox-217351@kernel.org> (raw)
In-Reply-To: <20261116152626.4032587-2-alexei.starovoitov@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] bpf: bpf_log_attr_finalize() overwrites -EINTR on
bpf_must_abort()
- [Medium] bpf: stale map->user state across restart on blinding abort
in bpf_check()
--
commit 595bfc06524fa376713bc6415b648b32cc04152d
Author: Alexei Starovoitov <ast@kernel.org>
bpf: Stop a load only when the loader is killed or has to freeze
This commit replaces signal_pending() and fatal_signal_pending() checks across
verifier passes with a unified bpf_must_abort() helper that aborts with -EINTR
only when the loader has a fatal signal or needs to freeze, and restarts
BPF_PROG_LOAD, BPF_BTF_LOAD, and BPF_MAP_CREATE via -ERESTARTNOINTR.
> diff --git a/kernel/bpf/fixups.c b/kernel/bpf/fixups.c
> index 1d33a78d93739..735932392a87f 100644
> --- a/kernel/bpf/fixups.c
> +++ b/kernel/bpf/fixups.c
[ ... ]
> @@ -190,7 +176,7 @@ struct bpf_insn *bpf_patch_list_add(struct bpf_verifier_env *env, u32 off,
> struct bpf_patch_list *pl = &env->patch_list;
> struct bpf_insn_patch *p = pl->cnt ? &pl->patches[pl->cnt - 1] : NULL;
>
> - if (bpf_rewrite_must_abort())
> + if (bpf_must_abort())
> return ERR_PTR(-EINTR);
[Severity: Medium]
Can aborting on a non-fatal freezer request here leave mutated map state
behind when BPF_PROG_LOAD restarts?
For a single-subprog program, bpf_check() runs bpf_fixup_call_args() ->
bpf_jit_subprogs() -> resolve_func_ptrs(), which sets BPF_MAP_USER_PATCHED on
ptr->map->user and zeroes dead function-pointer slots in the frozen read-only
map, and then populates env->prog->aux->used_maps before calling
__bpf_prog_select_runtime():
kernel/bpf/verifier.c:bpf_check() {
...
env->prog = __bpf_prog_select_runtime(env, env->prog, &ret);
err_release_maps:
err = bpf_log_attr_finalize(attr_log, &env->log);
if (err)
ret = err;
if (ret)
release_insn_arrays(env);
if (!env->prog->aux->used_maps)
release_maps(env);
...
}
If constant blinding inside __bpf_prog_select_runtime() ->
bpf_prog_jit_compile() -> bpf_jit_blind_constants() hits bpf_must_abort() in
bpf_patch_list_add(), it returns -EINTR after the map was already modified and
with env->prog->aux->used_maps already set. Synchronous release_maps() is
skipped, __bpf_free_used_maps() is deferred to a workqueue (and its
cmpxchg(&map->user, (unsigned long)aux, 0) cannot clear BPF_MAP_USER_PATCHED),
and when the thawed task restarts BPF_PROG_LOAD via -ERESTARTNOINTR,
bpf_map_claim() either fails with -EBUSY or races with the deferred map
release work.
[ ... ]
> diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> index 04a3b3c80c74e..70caab9648d67 100644
> --- a/kernel/bpf/syscall.c
> +++ b/kernel/bpf/syscall.c
> @@ -6604,7 +6604,14 @@ static int __sys_bpf(enum bpf_cmd cmd, bpfptr_t uattr, unsigned int size,
> SYSCALL_DEFINE5(bpf, int, cmd, union bpf_attr __user *, uattr, unsigned int, size,
> struct bpf_common_attr __user *, uattr_common, unsigned int, size_common)
> {
> - return __sys_bpf(cmd, USER_BPFPTR(uattr), size, USER_BPFPTR(uattr_common), size_common);
> + int err = __sys_bpf(cmd, USER_BPFPTR(uattr), size, USER_BPFPTR(uattr_common), size_common);
> +
> + cmd &= ~BPF_COMMON_ATTRS;
> + /* bpf_must_abort() ended the command, nothing of it is left */
> + if (err == -EINTR && task_sigpending(current) &&
> + (cmd == BPF_PROG_LOAD || cmd == BPF_BTF_LOAD || cmd == BPF_MAP_CREATE))
> + return -ERESTARTNOINTR;
> + return err;
> }
[Severity: Medium]
Does bpf_log_attr_finalize() overwrite -EINTR with -ENOSPC and prevent the
syscall from restarting after freezing?
When bpf_check() aborts with ret = -EINTR, its cleanup path still finalizes
the verifier log:
kernel/bpf/verifier.c:bpf_check() {
...
err_release_maps:
err = bpf_log_attr_finalize(attr_log, &env->log);
if (err)
ret = err;
...
}
If the user supplied a log buffer and log->len_max > log->len_total (for
example, a rolling log buffer, or under BPF_LOG_LEVEL1 where do_check() calls
bpf_flow_print_way() on err == -EINTR and do_check_common() skips
bpf_vlog_reset()), bpf_log_attr_finalize() returns -ENOSPC and clobbers
ret = -EINTR. SYSCALL_DEFINE5(bpf) then sees err == -ENOSPC instead of
-EINTR and returns -ENOSPC to user space after thawing instead of
-ERESTARTNOINTR.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116152626.4032587-1-alexei.starovoitov@gmail.com?part=1
next prev parent reply other threads:[~2026-11-16 16:15 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 15:26 [PATCH bpf-next v2 00/21] bpf: Remove the limits on maps, kfuncs, subprogs and special fields Alexei Starovoitov
2026-11-16 15:26 ` [PATCH bpf-next v2 01/21] bpf: Stop a load only when the loader is killed or has to freeze Alexei Starovoitov
2026-11-16 16:15 ` sashiko-bot [this message]
2026-11-16 15:26 ` [PATCH bpf-next v2 02/21] bpf: Fail the load when there is no memory Alexei Starovoitov
2026-11-16 16:06 ` bot+bpf-ci
2026-11-16 15:26 ` [PATCH bpf-next v2 03/21] bpf: Give a syscall program the largest context when it does tail calls Alexei Starovoitov
2026-11-16 15:26 ` [PATCH bpf-next v2 04/21] bpf: Do not inline bpf_loop() when its callback is dead code Alexei Starovoitov
2026-11-16 15:26 ` [PATCH bpf-next v2 05/21] bpf: Dump programs that have more than 524288 insns Alexei Starovoitov
2026-11-16 15:26 ` [PATCH bpf-next v2 06/21] bpf: Resolve BTF structs and arrays first Alexei Starovoitov
2026-11-16 17:40 ` sashiko-bot
2026-11-16 15:26 ` [PATCH bpf-next v2 07/21] bpf: Remove the limits on maps, BTFs and fd_array of a program Alexei Starovoitov
2026-11-16 15:26 ` [PATCH bpf-next v2 08/21] bpf: Do not scan all maps for each insn and each subprog Alexei Starovoitov
2026-11-16 15:26 ` [PATCH bpf-next v2 09/21] bpf: Remove the limits on kfuncs of a program Alexei Starovoitov
2026-11-16 15:26 ` [PATCH bpf-next v2 10/21] bpf: Remove the limits on tables of functions Alexei Starovoitov
2026-11-16 15:26 ` [PATCH bpf-next v2 11/21] libbpf: Size the tables of the loader program from the object Alexei Starovoitov
2026-11-16 16:06 ` bot+bpf-ci
2026-11-16 15:26 ` [PATCH bpf-next v2 12/21] bpf: Relax jumps that patches push out of range Alexei Starovoitov
2026-11-16 15:26 ` [PATCH bpf-next v2 13/21] bpf: Keep the call graph in lists of edges Alexei Starovoitov
2026-11-16 19:21 ` sashiko-bot
2026-11-16 15:26 ` [PATCH bpf-next v2 14/21] bpf: Find the effects of callees on the call graph Alexei Starovoitov
2026-11-16 15:26 ` [PATCH bpf-next v2 15/21] bpf: Link the decl tags of a type Alexei Starovoitov
2026-11-16 15:26 ` [PATCH bpf-next v2 16/21] bpf: Remove BPF_MAX_SUBPROGS Alexei Starovoitov
2026-11-16 15:26 ` [PATCH bpf-next v2 17/21] bpf: Walk each type once when looking for special fields Alexei Starovoitov
2026-11-16 15:26 ` [PATCH bpf-next v2 18/21] bpf: Raise the limit on the length of BTF names Alexei Starovoitov
2026-11-16 15:26 ` [PATCH bpf-next v2 19/21] bpf: Find dominators in O(n log n) Alexei Starovoitov
2026-11-16 15:26 ` [PATCH bpf-next v2 20/21] selftests/bpf: Test programs above the old limits Alexei Starovoitov
2026-11-16 15:26 ` [PATCH bpf-next v2 21/21] selftests/bpf: Test limits of the load with raw programs Alexei Starovoitov
2026-11-16 21:17 ` sashiko-bot
2026-11-16 19:00 ` [PATCH bpf-next v2 00/21] bpf: Remove the limits on maps, kfuncs, subprogs and special fields patchwork-bot+netdevbpf
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=sashiko-outbox-217351@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=alexei.starovoitov@gmail.com \
--cc=bpf@vger.kernel.org \
--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 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.