BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 02/21] bpf: Fail the load when there is no memory
Date: Mon, 16 Nov 2026 06:29:12 +0000	[thread overview]
Message-ID: <sashiko-outbox-216279@kernel.org> (raw)
In-Reply-To: <20261116055638.4171529-3-alexei.starovoitov@gmail.com>

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 2 related pre-existing issues it does not
introduce:
- [Critical] bpf: kernel map pointer leak in bpf_prog_calc_tag() [1]
- [Medium] bpf: unjoined spills in compute_subprog_args() cause false
  FM_MUST_WRITE [2]
--

commit 7ed141586457177ae6d6a4df96dc2819c9dd9563
Author: Alexei Starovoitov <ast@kernel.org>

bpf: Fail the load when there is no memory

This commit adds __GFP_RETRY_MAYFAIL | __GFP_NOWARN to BPF verifier and
program load allocations so that hitting a memory cgroup limit returns
-ENOMEM instead of invoking the OOM killer.

> diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
> index b407b2393ac3e..09abfed83109c 100644
> --- a/kernel/bpf/core.c
> +++ b/kernel/bpf/core.c
[ ... ]
> @@ -309,7 +309,7 @@ int bpf_prog_calc_tag(struct bpf_prog *fp)
>  	bool was_ld_map;
>  	u32 i;
>  
> -	dst = __vmalloc(size, GFP_KERNEL_ACCOUNT);
> +	dst = __vmalloc(size, BPF_VERIFIER_GFP);
>  	if (!dst)
>  		return -ENOMEM;

[Severity: Critical]
This problem wasn't introduced by this patch, but can bpf_prog_calc_tag()
leak kernel map pointers [1] when hashing subprograms that use
BPF_PSEUDO_MAP_IDX or BPF_PSEUDO_MAP_IDX_VALUE?

check_and_resolve_insns() replaces the immediate fields of those pseudo map
instructions with kernel map pointers while keeping their original src_reg,
and jit_subprogs() later calls bpf_prog_calc_tag() on each subprogram.
Because the loop right below only zeroes dst[i].imm for BPF_PSEUDO_MAP_FD
and BPF_PSEUDO_MAP_VALUE:

kernel/bpf/core.c:bpf_prog_calc_tag() {
	...
	for (i = 0, was_ld_map = false; i < fp->len; i++) {
		dst[i] = fp->insnsi[i];
		if (!was_ld_map &&
		    dst[i].code == (BPF_LD | BPF_IMM | BPF_DW) &&
		    (dst[i].src_reg == BPF_PSEUDO_MAP_FD ||
		     dst[i].src_reg == BPF_PSEUDO_MAP_VALUE)) {
			was_ld_map = true;
			dst[i].imm = 0;
	...
}

the resolved kernel map pointers for BPF_PSEUDO_MAP_IDX and
BPF_PSEUDO_MAP_IDX_VALUE are hashed directly into the subprogram digest
exposed via bpf_prog_info, allowing userspace to recover kernel map
addresses and making subprogram tags non-deterministic across reloads.

> diff --git a/kernel/bpf/liveness.c b/kernel/bpf/liveness.c
> index 2c771b936d654..053b3875cde69 100644
> --- a/kernel/bpf/liveness.c
> +++ b/kernel/bpf/liveness.c
[ ... ]
> @@ -2190,7 +2190,7 @@ static noinline_for_stack int compute_subprog_args(struct bpf_verifier_env *env,
>  			struct spill_snapshot *snap;
>  
>  			kvfree(env->callsite_at_stack[idx]);
> -			env->callsite_at_stack[idx] = kvmalloc_flex(*snap, at, nslots, GFP_KERNEL_ACCOUNT);
> +			env->callsite_at_stack[idx] = kvmalloc_flex(*snap, at, nslots, BPF_VERIFIER_GFP);
>  			snap = env->callsite_at_stack[idx];
>  			if (!snap) {
>  				err = -ENOMEM;

[Severity: Medium]
This problem wasn't introduced by this patch, but can snapshotting
at_stack_in into env->callsite_at_stack[idx] without joining spilled slots
with ARG_NONE [2] cause a callee to falsely mark a caller's stack slot
with FM_MUST_WRITE?

arg_track_xfer() only updates local stack slots on stores or calls, leaving
ancestor frame snapshots in env->callsite_at_stack unchanged:

kernel/bpf/liveness.c:arg_track_deref() {
	...
	if (ptr->frame >= 0 && ptr->frame < depth) {
		struct spill_snapshot *parent = env->callsite_at_stack[callsites[ptr->frame]];

		return fill_from_stack(insn, at_out, reg, parent->at, parent->slots, ptr->frame);
	}
	...
}

If a caller spills a frame pointer to its stack and passes a frame pointer
to a callee that overwrites that spill slot with a non-frame pointer (such
as a map value pointer), loads it back, and stores through it,
fill_from_stack() still returns the original single-offset spill from
parent->at.  record_stack_access_off() then sets FM_MUST_WRITE on the
originally spilled caller slot, killing FM_LIVE_BEFORE at callee entry so
clean_verifier_state() poisons the live slot with STACK_POISON and rejects
valid programs.

[1] https://sashiko.dev/#/bug/linux-3631fcb7-6cc6-4103-b924-aa236118faf7
[2] https://sashiko.dev/#/bug/linux-770fd7fa-a8be-43e6-aced-6a3500427b32

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261116055638.4171529-1-alexei.starovoitov@gmail.com?part=2

  reply	other threads:[~2026-11-16  6:29 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16  5:56 [PATCH bpf-next 00/21] bpf: Remove the limits on maps, kfuncs, subprogs and special fields Alexei Starovoitov
2026-11-16  5:56 ` [PATCH bpf-next 01/21] bpf: Stop a load only when the loader is killed or has to freeze Alexei Starovoitov
2026-11-16  6:39   ` bot+bpf-ci
2026-11-16  6:49   ` sashiko-bot
2026-11-16  5:56 ` [PATCH bpf-next 02/21] bpf: Fail the load when there is no memory Alexei Starovoitov
2026-11-16  6:29   ` sashiko-bot [this message]
2026-11-16  5:56 ` [PATCH bpf-next 03/21] bpf: Give a syscall program the largest context when it does tail calls Alexei Starovoitov
2026-11-16  5:56 ` [PATCH bpf-next 04/21] bpf: Do not inline bpf_loop() when its callback is dead code Alexei Starovoitov
2026-11-16  5:56 ` [PATCH bpf-next 05/21] bpf: Dump programs that have more than 524288 insns Alexei Starovoitov
2026-11-16  5:56 ` [PATCH bpf-next 06/21] bpf: Resolve BTF structs and arrays first Alexei Starovoitov
2026-11-16  6:13   ` sashiko-bot
2026-11-16  5:56 ` [PATCH bpf-next 07/21] bpf: Remove the limits on maps, BTFs and fd_array of a program Alexei Starovoitov
2026-11-16  6:39   ` bot+bpf-ci
2026-11-16  5:56 ` [PATCH bpf-next 08/21] bpf: Do not scan all maps for each insn and each subprog Alexei Starovoitov
2026-11-16  6:16   ` sashiko-bot
2026-11-16  5:56 ` [PATCH bpf-next 09/21] bpf: Remove the limits on kfuncs of a program Alexei Starovoitov
2026-11-16  6:39   ` bot+bpf-ci
2026-11-16  5:56 ` [PATCH bpf-next 10/21] bpf: Remove the limits on tables of functions Alexei Starovoitov
2026-11-16  6:14   ` sashiko-bot
2026-11-16  5:56 ` [PATCH bpf-next 11/21] libbpf: Size the tables of the loader program from the object Alexei Starovoitov
2026-11-16  6:20   ` sashiko-bot
2026-11-16  5:56 ` [PATCH bpf-next 12/21] bpf: Relax jumps that patches push out of range Alexei Starovoitov
2026-11-16  6:52   ` bot+bpf-ci
2026-11-16  5:56 ` [PATCH bpf-next 13/21] bpf: Keep the call graph in lists of edges Alexei Starovoitov
2026-11-16  6:39   ` sashiko-bot
2026-11-16  5:56 ` [PATCH bpf-next 14/21] bpf: Find the effects of callees on the call graph Alexei Starovoitov
2026-11-16  5:56 ` [PATCH bpf-next 15/21] bpf: Link the decl tags of a type Alexei Starovoitov
2026-11-16  5:56 ` [PATCH bpf-next 16/21] bpf: Remove BPF_MAX_SUBPROGS Alexei Starovoitov
2026-11-16  5:56 ` [PATCH bpf-next 17/21] bpf: Walk each type once when looking for special fields Alexei Starovoitov
2026-11-16  5:56 ` [PATCH bpf-next 18/21] bpf: Raise the limit on the length of BTF names Alexei Starovoitov
2026-11-16  5:56 ` [PATCH bpf-next 19/21] bpf: Find dominators in O(n log n) Alexei Starovoitov
2026-11-16  5:56 ` [PATCH bpf-next 20/21] selftests/bpf: Test programs above the old limits Alexei Starovoitov
2026-11-16  6:33   ` sashiko-bot
2026-11-16  6:39   ` bot+bpf-ci
2026-11-16  5:56 ` [PATCH bpf-next 21/21] selftests/bpf: Test limits of the load with raw programs Alexei Starovoitov
2026-11-16  6:39   ` sashiko-bot

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-216279@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox