From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796105396; b=qiYzNKhX877BAS+1+t9pl146tyoDgC6Y0/qxxTgcev7kUnmifm7sf2jKMLGyEgMy+yWh 6qe0c5uysrrYrztOrTte/pKHfWr33F4SeHHtaOTqp/Cc5zeWC9tcXv0ngk3n8ToyvGb3i nsp9ruTzVCStWNqysdo0VGPXMjaG4uTjbyJraKoNKPxkoerLyzQryhhvA2SF2xzE5GrHE 9yyIJAsE5CssGsG8gJijdNub/qcdG8j1e7AH4JeU0BBV+b8FfaUkPyKTO/YFJ2SRHGDW1 /d8pHu9/o8wq50qyYbAbIlapQWWpRH8HgxWweDAT5Elzb/eXdyp6nyOC6Qj0H5cSENg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796105396; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=XykIj8H/hZMnwc69y0MTt2Qgg6+XrIgw6D54kDpb7bE=; b=gX0rSIXzd8NRdJx+JW7bLc3dYcoY84lX0GKq+2AAa5EjXi061P9QPCqum3AReA6VLNDY NzbnWykIvvbnqjlSw58Rg30zdhq7mJlIzKIu3j+NQwpXpXJBIFxSIYs9c8aioY8AN5NJb V7Fx9SVr3OJUzX5lOPbTI+jDqC4q85NoLWXtBrXSA94Z024I8Hd5gSf/5sPkMyLKfAdxt WFA9WjlR0rlUGQGt1LY9Vjb0q5Dkfsee+FMu2eNsT1xYWSP4BE9TvXT6lnB7Hqdl7dijx lexQyVCT43lwoz6ERaJrOReNqb++UJMoln9KvFzM7VP5xRgc7KqbYrYn55er40OzOTw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=bpLzSNLv; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9939C606A31A for ; Tue, 1 Dec 2026 06:09:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=bpLzSNLv Received: by smtp.kernel.org (Postfix) with ESMTPSA id 93E581F00899; Tue, 1 Dec 2026 06:09:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796105395; bh=XykIj8H/hZMnwc69y0MTt2Qgg6+XrIgw6D54kDpb7bE=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=bpLzSNLvwjJ8gFRKtfISon2tfdRrxL0HLUmPX9hjZrioIWUjwzlHX8yk7myiT42k0 TH4WxdE2JZwfxemCI/Sa+o+fTCoNOCveZXwgXr6e/LDff94jyCBHxKu78unaY75LMB ZbhQ2z8P/tzU08C/4jsJHiAr628lWEJJi9xz4bTAyXhQRMMkaGBCEVrYpw8ZuN9TtH 4+irq711/KT/XzhPWmuczMSks1HrrLfCPqVPAF5J/et3Lb9gCzOWkpYxUMv4vZL74Z 9+H9DSCy0kD3/rlLRUnaGLxADKB9D8CtTgBtzBBKYcp5CuP3YDR7B/lyM97FKHBPks 19KIpBbm1PFcQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH bpf-next v1 49/73] bpf: Cancel the program when the time of its own may_goto is up Reply-To: sashiko-reviews@lists.linux.dev To: "Kumar Kartikeya Dwivedi" , bpf@vger.kernel.org In-Reply-To: <33bbfdec2a3e0b6c2d26bfddc849feeb82d0ec2c.1796099738.git.memxor@gmail.com> References: <33bbfdec2a3e0b6c2d26bfddc849feeb82d0ec2c.1796099738.git.memxor@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 06:09:55 +0000 X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [Medium] bpf: stale did_unwind on stuck global subprogs in check_funcs() - [Medium] bpf: guessed loop guards set sub->must_unwind in unwind_frame() - [Medium] selftests/bpf: unconditional unwound retval check in test_far() - [Medium] selftests/bpf: missing arch filters on subprog may_goto unwind tests -- commit 094833e46010de972d0b8edab3d44817e43701f1 Author: Kumar Kartikeya Dwivedi bpf: Cancel the program when the time of its own may_goto is up This commit cancels a BPF program through landing pads when its own timed may_goto expires, rather than jumping to the instruction's target, unless the containing function is marked stuck and cannot be unwound. > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c > index f5bc401bce873..2141cef41a88b 100644 > --- a/kernel/bpf/verifier.c > +++ b/kernel/bpf/verifier.c [ ... ] > @@ -3468,6 +3475,51 @@ static void mark_unwind_above(struct bpf_verifier_= env *env) > } while (changed); > } > =20 > +/* > + * A global subprog that has a may_goto of the program, or that calls a = subprog which has one, is > + * cancelled there when the time is up, see check_may_goto_site(). Its c= allers are verified before > + * it. Mark it before the first pass, so that the pass does not have to = start again to tell them. > + */ > +static int expect_may_goto_unwinds(struct bpf_verifier_env *env) > +{ [ ... ] > + for_each_set_bit(s, soft, cnt) > + si[s].did_unwind |=3D si[s].bail_unwinds && bpf_subprog_is_global(env,= s); > + bitmap_free(soft); > + return err; > +} [ ... ] > @@ -22291,8 +22429,10 @@ static int unwind_frame(struct bpf_verifier_env = *env, struct bpf_verifier_state > env->pads_late =3D true; > } > sub->did_unwind |=3D st->unwound; > + if (st->unwound) > + bpf_pad_note_left(env, sub, plan, kind); > sub->must_unwind |=3D st->unwound && plan && bpf_pad_must_unwind(env, p= lan); > - sub->unwinds_for_sure |=3D st->unwound && plan && bpf_pad_must_unwind(e= nv, plan) && certain; > + sub->unwinds_for_sure |=3D st->unwound && plan && certain; [Severity: Medium] Does setting sub->must_unwind without checking certain (or recomputing it after bpf_flow_drop_guards()) leave sub->must_unwind set when a guessed BPF_SITE_GUARD is later dropped? In pass 0, check_loop_guard() pushes a speculative BPF_SITE_GUARD edge for any bounded loop that is not syntactically rt_bounded, and unwind_frame() sets sub->must_unwind =3D true on that edge even though certain is false. Unlike sites_of_subprogs(), bpf_pads_must_unwind() never resets sub->must_unwind or filters by plan->used after bpf_flow_drop_guards() drops the guard. If the subprogram also has a program may_goto or arena access, subprog_cannot_unwind() will reject a valid callback with -EINVAL, and plan_rejects() in bpf_pads_settle() will reject a conflicting call site above the subprogram instead of calling skip_faults() to mark it stuck and repeat the pass. [ ... ] > @@ -24500,6 +24640,14 @@ static int check_funcs(struct bpf_verifier_env *= env, struct bpf_snapshot *initia > initial->subprogs[i].bail_unwinds_at_first; > else if (env->faults_late) > initial->subprogs[i].bail_unwinds &=3D env->subprog_info[i].bail_unwi= nds; > + /* > + * Its may_goto jumps where the program says, see check_may_goto_site(= ) and > + * stuck_frame_calls(). That is what it did before the verifier unwoun= d programs > + * there, so it is safe to keep in every run that follows: a run that = had to find > + * it again could end at an error which is none before it gets to the = call that > + * tells. > + */ > + initial->subprogs[i].stuck |=3D env->subprog_info[i].stuck; [Severity: Medium] Can initial->subprogs[i].did_unwind stay set across restarted passes after a global subprogram or its static callee with may_goto is marked stuck? expect_may_goto_unwinds() sets si[s].did_unwind =3D true before save_snapshot() captures initial->subprogs. If pass 0 later marks s (or the callee that had the may_goto) stuck and restarts via env->faults_late, check_funcs() propagates stuck into initial->subprogs[i] without clearing did_unwind, and bail_unwinds remains true. In the restarted pass, check_func_call() still sees did_unwind && bail_unwinds and pushes a phantom unwound return state after calls to the stuck global subprogram, which can cause false landing-pad conflicts in callers that release resources after the call. > diff --git a/tools/testing/selftests/bpf/prog_tests/may_goto_far.c b/tool= s/testing/selftests/bpf/prog_tests/may_goto_far.c > index b6d262911a3ea..201cda7cf34b4 100644 > --- a/tools/testing/selftests/bpf/prog_tests/may_goto_far.c > +++ b/tools/testing/selftests/bpf/prog_tests/may_goto_far.c [ ... ] > @@ -74,14 +79,14 @@ static void test_far(int off, bool subprog) > insn =3D fill(insn, back, BPF_REG_8); > *insn++ =3D BPF_EXIT_INSN(); > =20 > - fd =3D bpf_prog_load(BPF_PROG_TYPE_SYSCALL, NULL, "GPL", insns, insn - = insns, &opts); > + fd =3D bpf_prog_load(BPF_PROG_TYPE_SCHED_CLS, NULL, "GPL", insns, insn = - insns, &opts); > free(insns); > if (!ASSERT_GE(fd, 0, "prog_load")) > return; > =20 > err =3D bpf_prog_test_run_opts(fd, &topts); > ASSERT_OK(err, "test_run"); > - ASSERT_EQ(topts.retval, 0, "retval"); > + ASSERT_EQ(topts.retval, 2, "retval"); > close(fd); > } [Severity: Medium] Will test_far() fail when subprog is true on architectures whose JIT supports timed may_goto but not subprogram unwinding (such as s390x, riscv64, loongarch, and powerpc64), or when JIT is disabled? When subprog is true, frame_is_top() is false and frame_cannot_unwind() returns BPF_CONFLICT_CANNOT_UNWIND unless bpf_jit_supports_unwind() is supported (currently only x86_64 and arm64). check_may_goto_site() then marks the subprog stuck and leaves may_goto as a plain jump, so the program returns 0 instead of 2. > diff --git a/tools/testing/selftests/bpf/progs/verifier_iterating_callbac= ks.c b/tools/testing/selftests/bpf/progs/verifier_iterating_callbacks.c > index 1dfeb13b43825..c4a0c3f303b40 100644 > --- a/tools/testing/selftests/bpf/progs/verifier_iterating_callbacks.c > +++ b/tools/testing/selftests/bpf/progs/verifier_iterating_callbacks.c [ ... ] > @@ -618,24 +623,22 @@ static __noinline int static_subprog(void) > } > =20 > SEC("socket") > -__success __retval(1) > +__load_if_JITed() > +__success __retval(0) > int cond_break5(const void *ctx) > { > int cnt1 =3D zero, cnt2; > =20 > - /* > - * There is one time slice for all may_goto of the prog. When it's used= up a function that > - * is called after that makes no iteration. So this loop has an end. > - */ > + /* This loop has an end: it does not use up the time slice of the prog.= */ > for (; cnt1 < 100;) { > cond_break; > cnt1++; > } > =20 > + /* The loop of the subprog does. The prog is unwound from there. */ > cnt2 =3D static_subprog(); > =20 > - /* main and subprog have to loop a bit */ > - return cnt1 > 1 && cnt2 > 1 ? 1 : 0; > + return cnt1 > 1 && cnt2 > 1 ? 1 : 2; > } [Severity: Medium] Should cond_break5 and stack_arg_may_goto_timeout_in_callee in tools/testing/selftests/bpf/progs/verifier_stack_arg.c be restricted to architectures that support subprogram unwinding (__arch_x86_64 and __arch_arm64)? In both tests the expiring may_goto is inside a non-inlined callee subprog (static_subprog() and spins_then_reads_8args()). On architectures where bpf_jit_supports_unwind() is false (such as s390x, riscv64, loongarch, and powerpc64), the callee is marked stuck and its may_goto jumps to its target instead of unwinding, so cond_break5 returns 1 instead of 0 and stack_arg_may_goto_timeout_in_callee returns 876 instead of 2 on riscv64. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/cover.1796099737.gi= t.memxor@gmail.com?part=3D49