From: sashiko-bot@kernel.org
To: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 08/49] bpf: Do not fail a check because a state has fewer values
Date: Fri, 20 Nov 2026 08:39:00 +0000 [thread overview]
Message-ID: <sashiko-outbox-224753@kernel.org> (raw)
In-Reply-To: <20261120074430.2704488-9-alexei.starovoitov@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] bpf: missing far-offset check in check_ptr_to_btf_access()
after blur
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [Critical] bpf: unaligned memory access in bpf_map_direct_read() [1]
--
commit 22e172eae518ce6c856dc6c4380ea2788200c435
Author: Alexei Starovoitov <ast@kernel.org>
bpf: Do not fail a check because a state has fewer values
This commit avoids rejecting pointer arithmetic with large positive
offsets, range-splitting conditional jumps, and narrow loads from spilled
pointers when a verifier state has a narrower set of values than a joined
state would.
> diff --git a/kernel/bpf/const_fold.c b/kernel/bpf/const_fold.c
> index 50179edbf348c..61e22636ff890 100644
> --- a/kernel/bpf/const_fold.c
> +++ b/kernel/bpf/const_fold.c
> @@ -214,6 +214,9 @@ static void const_reg_xfer(struct bpf_verifier_env *env, struct const_arg_info *
> ci_out[r] = unknown;
> break;
> }
> + /* do_check() has only a range for a far offset */
> + if (ci_is_map_value(dst) && abs((s64)dst->val) >= BPF_MAX_VAR_OFF)
> + *dst = unknown;
> }
[Severity: Critical]
This problem wasn't introduced by this patch, but can the BPF_LDX case in
const_reg_xfer() trigger an unaligned kernel memory access in
bpf_map_direct_read() [1]?
bpf_compute_const_regs() runs before the main verifier enforces alignment
checks. When const_reg_xfer() folds a BPF_LDX from a read-only map, it
computes off = src->val + insn->off and passes it directly to
bpf_map_direct_read(), which dereferences ptr with a direct C pointer cast
such as *(u32 *)ptr. On strict-alignment architectures, an unprivileged
user loading a program with an unaligned read offset from a read-only map
triggers an unhandled alignment fault and panics the kernel.
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 030263d01e3e2..ef8e45a399ca5 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
[ ... ]
> @@ -16078,6 +16066,27 @@ enum {
> REASON_STACK = -5,
> };
>
> +/*
> + * A far pointer is no error: a state with near offsets gets here, so this one does too.
> + * An access through it is unproven. But a constant offset has to fit in an int.
> + */
> +void bpf_blur_far_offset(struct bpf_verifier_env *env, struct bpf_reg_state *reg)
> +{
> + s64 smin = reg_smin(reg), smax = reg_smax(reg);
> +
> + /* an id and a range need an offset that does not wrap around */
> + if (reg_is_pkt_pointer(reg) && offset_is_far(reg)) {
> + reg->id = bpf_new_id(env);
> + reg->range = 0;
> + }
> + if (reg->type == SCALAR_VALUE || (smin < BPF_MAX_VAR_OFF && smax > -BPF_MAX_VAR_OFF))
> + return;
> + scalar_set_unknown(scalar_of(reg));
> + reg->r64 = cnum64_from_srange(min(smin, BPF_MAX_VAR_OFF - 1),
> + max(smax, 1 - BPF_MAX_VAR_OFF));
> + reg_bounds_sync(reg);
> +}
[Severity: High]
Can a far PTR_TO_BTF_ID pointer pass check_ptr_to_btf_access() and
btf_struct_access() after bpf_blur_far_offset() lowers its smin to
BPF_MAX_VAR_OFF - 1?
Unlike check_stack_access_within_bounds() and check_mem_region_access(),
neither check_ptr_to_btf_access() nor btf_struct_access() checks
offset_is_far(reg). Because bpf_blur_far_offset() lowers reg_smin(reg) to
BPF_MAX_VAR_OFF - 1 with step = 1, min_off in btf_struct_access() fits in a
32-bit int even when a huge positive offset was added, and a trailing
1-byte flexible array member (such as data[] in struct
bpf_local_storage_data or ifalias[] in struct dev_ifalias) skips the
max_off upper-bound check:
kernel/bpf/btf.c:btf_struct_access() {
if (check_add_overflow(reg_smin(reg), (s64)_off, &min_off) ||
check_add_overflow(reg_smax(reg), (s64)_off, &max_off) ||
min_off != (int)min_off) {
...
return -EINVAL;
}
...
array_start = min_off - arrays[i].off;
/* An array within the flexible tail has no upper bound to exceed */
if (array_start >= flex_off && btf_type_is_array(t) &&
btf_type_array(t)->nelems == 0)
return ret;
}
For a PTR_TRUSTED or MEM_RCU pointer, bpf_may_fault_on_deref() is false, so
the load is not rewritten to BPF_PROBE_MEM and can read arbitrary
out-of-bounds kernel memory or fault in kernel mode. Checking
offset_is_far(reg) in check_ptr_to_btf_access() would reject far BTF
pointer accesses.
[1] https://sashiko.dev/#/bug/linux-ad386ec5-9f86-4c83-a85e-b56e4d8748cb
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261120074430.2704488-1-alexei.starovoitov@gmail.com?part=8
next prev parent reply other threads:[~2026-11-20 8:39 UTC|newest]
Thread overview: 79+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 7:41 [PATCH bpf-next 00/49] bpf: Verify in passes, with equations in the state Alexei Starovoitov
2026-11-20 7:41 ` [PATCH bpf-next 01/49] bpf: Look for bpf_clone_redirect() once in check_recursion() Alexei Starovoitov
2026-11-20 7:41 ` [PATCH bpf-next 02/49] bpf: Make stack liveness faster Alexei Starovoitov
2026-11-20 8:01 ` sashiko-bot
2026-11-20 8:24 ` bot+bpf-ci
2026-11-20 7:41 ` [PATCH bpf-next 03/49] bpf: Delete the old main pass of the verifier Alexei Starovoitov
2026-11-20 8:25 ` bot+bpf-ci
2026-11-20 7:41 ` [PATCH bpf-next 04/49] bpf: Delete scalar evolution Alexei Starovoitov
2026-11-20 8:03 ` sashiko-bot
2026-11-20 8:25 ` bot+bpf-ci
2026-11-20 7:41 ` [PATCH bpf-next 05/49] bpf: Limit the cost and the memory of a load Alexei Starovoitov
2026-11-20 8:00 ` sashiko-bot
2026-11-20 8:25 ` bot+bpf-ci
2026-11-20 7:41 ` [PATCH bpf-next 06/49] bpf: Record what each insn reads and writes Alexei Starovoitov
2026-11-20 8:25 ` bot+bpf-ci
2026-11-20 7:41 ` [PATCH bpf-next 07/49] bpf: Name an id after the xreg that has it Alexei Starovoitov
2026-11-20 8:25 ` bot+bpf-ci
2026-11-20 7:41 ` [PATCH bpf-next 08/49] bpf: Do not fail a check because a state has fewer values Alexei Starovoitov
2026-11-20 8:25 ` bot+bpf-ci
2026-11-20 8:39 ` sashiko-bot [this message]
2026-11-20 7:41 ` [PATCH bpf-next 09/49] bpf: Check fixups in the main pass and keep a snapshot of them Alexei Starovoitov
2026-11-20 8:25 ` bot+bpf-ci
2026-11-20 7:41 ` [PATCH bpf-next 10/49] bpf: Reject a program with a call that needs two rewrites Alexei Starovoitov
2026-11-20 7:41 ` [PATCH bpf-next 11/49] bpf: Put a barrier where no mask fits Alexei Starovoitov
2026-11-20 8:25 ` bot+bpf-ci
2026-11-20 7:41 ` [PATCH bpf-next 12/49] bpf: Keep more of what is known about a number Alexei Starovoitov
2026-11-20 8:18 ` sashiko-bot
2026-11-20 8:25 ` bot+bpf-ci
2026-11-20 7:41 ` [PATCH bpf-next 13/49] bpf: Remember how many bytes of a packet are checked Alexei Starovoitov
2026-11-20 8:25 ` bot+bpf-ci
2026-11-20 7:41 ` [PATCH bpf-next 14/49] bpf: Mark a state that no run of the program has Alexei Starovoitov
2026-11-20 8:24 ` bot+bpf-ci
2026-11-20 7:41 ` [PATCH bpf-next 15/49] bpf: Peel the first trips of a loop and join the other trips Alexei Starovoitov
2026-11-20 8:25 ` bot+bpf-ci
2026-11-20 7:41 ` [PATCH bpf-next 16/49] bpf: Add equations and their arithmetic Alexei Starovoitov
2026-11-20 8:24 ` bot+bpf-ci
2026-11-20 7:41 ` [PATCH bpf-next 17/49] bpf: Keep a table of equations in each state Alexei Starovoitov
2026-11-20 8:17 ` sashiko-bot
2026-11-20 8:25 ` bot+bpf-ci
2026-11-20 7:41 ` [PATCH bpf-next 18/49] bpf: Refine all related numbers after a jump Alexei Starovoitov
2026-11-20 7:41 ` [PATCH bpf-next 19/49] bpf: Make equations from ALU, spill, fill and call insns Alexei Starovoitov
2026-11-20 8:25 ` bot+bpf-ci
2026-11-20 8:26 ` sashiko-bot
2026-11-20 7:41 ` [PATCH bpf-next 20/49] bpf: Delete the equations that say nothing Alexei Starovoitov
2026-11-20 8:25 ` bot+bpf-ci
2026-11-20 7:41 ` [PATCH bpf-next 21/49] bpf: Compare states by join_key, then by value Alexei Starovoitov
2026-11-20 8:22 ` sashiko-bot
2026-11-20 7:41 ` [PATCH bpf-next 22/49] bpf: Continue a pass after an unproven insn Alexei Starovoitov
2026-11-20 7:41 ` [PATCH bpf-next 23/49] bpf: Find the xregs that an unproven insn depends on Alexei Starovoitov
2026-11-20 7:41 ` [PATCH bpf-next 24/49] bpf: Keep two states apart if data and control deps differ Alexei Starovoitov
2026-11-20 7:41 ` [PATCH bpf-next 25/49] bpf: Join any two states that have the same join_key Alexei Starovoitov
2026-11-20 8:25 ` sashiko-bot
2026-11-20 7:41 ` [PATCH bpf-next 26/49] bpf: Check the equations when a state is pruned or joined Alexei Starovoitov
2026-11-20 7:41 ` [PATCH bpf-next 27/49] bpf: Guess the equations of a join Alexei Starovoitov
2026-11-20 7:42 ` [PATCH bpf-next 28/49] bpf: Prune or join each state that arrives Alexei Starovoitov
2026-11-20 7:42 ` [PATCH bpf-next 29/49] bpf: Order the pending states and free the states that are done Alexei Starovoitov
2026-11-20 7:42 ` [PATCH bpf-next 30/49] bpf: Get the trip count from the trip index Alexei Starovoitov
2026-11-20 8:22 ` sashiko-bot
2026-11-20 7:42 ` [PATCH bpf-next 31/49] bpf: Give a loop a checked trip count or may_goto Alexei Starovoitov
2026-11-20 7:42 ` [PATCH bpf-next 32/49] bpf: Use the equations in the join rule Alexei Starovoitov
2026-11-20 7:42 ` [PATCH bpf-next 33/49] bpf: Verify a static function once for each instance Alexei Starovoitov
2026-11-20 8:33 ` sashiko-bot
2026-11-20 7:42 ` [PATCH bpf-next 34/49] bpf: Partition the states after an error Alexei Starovoitov
2026-11-20 7:42 ` [PATCH bpf-next 35/49] bpf: Reproduce an error on one path, with no joins Alexei Starovoitov
2026-11-20 7:42 ` [PATCH bpf-next 36/49] bpf: Do not let a join raise what a program requires Alexei Starovoitov
2026-11-20 7:42 ` [PATCH bpf-next 37/49] bpf: Verify in passes Alexei Starovoitov
2026-11-20 7:42 ` [PATCH bpf-next 38/49] bpf: Make a returned pointer to the stack unreadable Alexei Starovoitov
2026-11-20 7:42 ` [PATCH bpf-next 39/49] bpf: Keep two states apart if a live xreg has two types Alexei Starovoitov
2026-11-20 7:42 ` [PATCH bpf-next 40/49] bpf: Check the body of a counted loop once Alexei Starovoitov
2026-11-20 7:42 ` [PATCH bpf-next 41/49] bpf: Refine the copies of a number that AND or OR splits Alexei Starovoitov
2026-11-20 7:42 ` [PATCH bpf-next 42/49] bpf: Allow a range of offsets for a constant string Alexei Starovoitov
2026-11-20 7:42 ` [PATCH bpf-next 43/49] bpf: Keep spilled pointers at a range of stack offsets Alexei Starovoitov
2026-11-20 7:42 ` [PATCH bpf-next 44/49] selftests/bpf: Adjust tests to the new log text Alexei Starovoitov
2026-11-20 7:42 ` [PATCH bpf-next 45/49] selftests/bpf: Adjust tests that get another verdict or may_goto Alexei Starovoitov
2026-11-20 7:42 ` [PATCH bpf-next 46/49] selftests/bpf: Test barriers and far pointers Alexei Starovoitov
2026-11-20 7:42 ` [PATCH bpf-next 47/49] selftests/bpf: Test passes, instances, precision and the failing path Alexei Starovoitov
2026-11-20 8:30 ` sashiko-bot
2026-11-20 7:42 ` [PATCH bpf-next 48/49] selftests/bpf: Test equations Alexei Starovoitov
2026-11-20 7:42 ` [PATCH bpf-next 49/49] bpf, docs: Rewrite verifier.rst Alexei Starovoitov
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-224753@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