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=1796103113; b=MBsJszoKLFkqO8HkX8099lkGxP8ZqjiQ6SDBdZQXWTCc+DKFYbgcFPvk0i7pc1iMnK/1 BwVLDm5/J9n95IA3r1ok0OyJ3u34Eg+zwQXxtzMWBSrU7I2KcrP+om7QMAveH03pQO10P oTcJQPo7heTma3AmbWrPcLOF8XYFzepiFYROX/e73hRmwfLrYO+fFbi/Xm8Sff3hiqp6w FaZsQ5wrULVATJlZK1e3EC6CRcgT4McUnZVJTy6c6ONcRCCnrUKDDFeySsYGqmDjLcTuB Q3OWccxo0rnb/OJbo7jdjEEx+dhMPtnDOTtwSPfeNZjQcgvwRCFcMX7Kv6OVETqGiqQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796103113; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=zIHjRM3SVAjY0ODhhsflSRciP/l+KCL/UmyWMlVVpik=; b=h0WIxIt7l6cu1dtIQ24N5ZJsUPQy0FHPz6wdyrcx0KsyVCZJooxcA6kuNpZeJ2K2CE5d d//7PC48xQAa6kn7qiA3gsJJhnnEjr9UhPYWbCmumsL6PGTODR6ZqcRPVHOtkBVxCu3cU 6+L7MxAX0Umzm70133cck+IFs7IYH3AJem+nSlfI/Lt0841a2xhvR3Gwd9/pdIbOTFPeC 8MhbJ2nmVhznBq9q6lufXzz/jplrATbsOAlWhxer6o3Ok0j6Un8zpPb66E8+axhrEd2Uv ZAAIndKg/5AW6IV6su+LXS7Su+F/hIx4iyokvlIjvCQg8BviFINxRp9LjvWM7MnZY2w== 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=W+X4IL5p; 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 96726606A31A for ; Tue, 1 Dec 2026 05:31:53 +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=W+X4IL5p Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC5511F00893; Tue, 1 Dec 2026 05:31:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796103113; bh=zIHjRM3SVAjY0ODhhsflSRciP/l+KCL/UmyWMlVVpik=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=W+X4IL5p2cQNrYyEnP1KWxzatW+bu+OlaFsijbTYbYonNSEA1nmvVDaNrGRizxSC6 JY+Lpclb91WWtSFdktQN47XlrvjKR3tx08h9LJ/yuDE5aaby9akaRfPKbdZpssaPJK mcx0X9D6d/4mww7N5vXsqpwb/H5FEBtWgc9IIuSmK2On6DRNBzYm4fWmJKnC2SR/CZ g9xKYipEImaGT84v33qc3c0/TP6mA4rVqSW8pv75OMn+dCXX7r/D3KW5fxpIBcb1xa Zf7T6LXtttxVmOKCuhrUiqEc8ZYYCzoaheMhfqtLmvTBA4zlsPV8n8dr0scPm1t0dA mRdTPXHydp+IA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH bpf-next v1 24/73] bpf: Record what each call acquires and releases Reply-To: sashiko-reviews@lists.linux.dev To: "Kumar Kartikeya Dwivedi" , bpf@vger.kernel.org In-Reply-To: References: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 05:31:52 +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 1 potential issue to consider: - [Medium] bpf: under-counted note->held on NULL return in bpf_pad_note_return() -- commit 8812639e48841c61905030b2e860b98938bc3bc3 Author: Kumar Kartikeya Dwivedi bpf: Record what each call acquires and releases This commit records in struct bpf_pad_note what each call instruction acquires or releases during the main verification pass, preparing for hidden stack slots that landing pads will use to release resources. > diff --git a/kernel/bpf/pads.c b/kernel/bpf/pads.c > index 5c0973e2e2411..657f17f2aaabb 100644 > --- a/kernel/bpf/pads.c > +++ b/kernel/bpf/pads.c [ ... ] > @@ -1144,6 +1155,278 @@ struct bpf_pad_plan *bpf_pad_visit(struct bpf_ver= ifier_env *env, [ ... ] > +void bpf_pad_note_return(struct bpf_verifier_env *env, const struct bpf_= verifier_state *st, > + const struct bpf_func_state *caller, int call_idx, bool plain) > +{ > + const struct bpf_func_state *callee =3D st->frame[st->curframe]; > + const struct bpf_reference_state *ref =3D &st->refs[callee->entry_refs]; > + struct bpf_subprog_info *sub =3D &env->subprog_info[caller->subprogno]; > + struct bpf_insn_aux_data *aux =3D &env->insn_aux_data[call_idx]; > + const struct bpf_reg_state *r0 =3D &callee->regs[BPF_REG_0]; > + int i, nr =3D st->acquired_refs - callee->entry_refs, in_r0 =3D 0; > + struct bpf_pad_place place; > + struct bpf_pad_ent ent; > + > + for (i =3D 0; i < BPF_PAD_NR_SECTIONS; i++) > + if (frame_sections(st, i)) > + sub->no_slots |=3D BIT(i); > + if (plain && nr =3D=3D 1 && ref->type =3D=3D REF_TYPE_PTR && !ref->pare= nt_id) > + add_ref_cand(&place, &in_r0, r0, ref, BPF_PLACE_REG, BPF_REG_0); > + if (in_r0 && slot_ent(env, &ent, st, ref, r0, true) && > + can_release_under_lock(env, st, caller, &ent)) { > + note_acquire(env, sub, call_idx, &ent, BPF_REG_0, > + count_refs(st, caller->entry_refs, callee->entry_refs, > + BPF_PAD_GROUP_REFS)); > + } else { > + for (i =3D 0; i < nr; i++) > + sub->no_slots |=3D BIT(class_group(ref_class(&ref[i])));\ > + aux->call_brings_nothing |=3D plain && !reg_is_null(r0); > + } > + if (aux->call_brings_nothing && aux->pad_note && aux->pad_note->acquire= s) > + sub->no_slots |=3D BIT(BPF_PAD_GROUP_REFS); > +} [Severity: Medium] Can bpf_pad_note_return() leave aux->pad_note->held under-counted when a subprogram returns NULL (nr =3D=3D 0 and reg_is_null(r0)) while the caller already holds references of BPF_PAD_GROUP_REFS? When a subprogram called in a loop acquires and returns a reference on trip 0 (while the caller holds 0 references) and returns NULL on a later trip (while the caller still holds the reference from trip 0), the NULL return takes the else branch with aux->call_brings_nothing remaining false and never updates aux->pad_note->held with the caller's held count (or checks it against BPF_PAD_MAX_ENTS). Once hidden slots are wired up in commit "bpf: Add hidden stack slots for landing pads", the call is given only 1 + note->held =3D 1 slot with an unconditional store of R0, so the NULL return overwrites the active pointer in that slot with 0 and a subsequent landing pad leaks the reference. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/cover.1796099737.gi= t.memxor@gmail.com?part=3D24