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=1796103660; b=q2U8mYWEydD7jbDZCZ+05yxw1YfQBke4ifyUMDzXzul/V/Y28pxJaI2EpdwAfYik0LzV xDtJpYsd4ev7+1+nR487ItbBIhxcSDnygnZuDdRLGq3ByRYBdiHWVqNshtu8Mv2ATT6Ct TdpDmDmrqz054VJUnl+rL0w9cFAzjdvQwgs4YQ3ucM+PZN3hueN99nCGo4QLZlhlPSRRj qZ/lz2KmqEEOyQHVwR0LljOz1nZmla4X0LfljtUXJw1Qf3PifU0oIJLmmx4BONA4etMVa wrjg6IQ6e1koq3M5e9km+4z1+EZE6UgZ7rY7bjgeC4sx2X3TQ4De6vMaDTPU1evt5yA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796103660; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=sLgKyaIX/LwRT0KlsPSsXefcNvV1+oZHU8OLr8+MLt4=; b=HxXu0xaI/ROwH0pvg3aZgRSgsfas8Gm6FP7M4oyVR/8ofjKHI+8+a86jS2ydMedYXpsh bYTbtq7thTjg9j0/gVHZNNn3JXZcGfIIeLs4JLL5VzvLtsSMPOsNOO00VZelmwSiBvlRY nAl1MNhHOgEMWXmo3vQf4V26ELBzPQChSyqUXRZGb7WEIABmeP8L3rF2+Sg1MfBLPYk4U spD7jipaQwnyqCTK3Ofh01tYltsSv7ChW41NE22YBtEC0ImCgfqOX/7Fb6O0EENjQgDT+ Vj16B7F7LVqknJWdqmudg0Ox0ePMSjYhl4msZwjKnQ1C8ZFoF7vghzqEe0zD3Vo0rGQ== 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=bpqrVCuv; 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 D24C1606A31A for ; Tue, 1 Dec 2026 05:41:00 +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=bpqrVCuv Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6648D1F000C1; Tue, 1 Dec 2026 05:41:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796103660; bh=sLgKyaIX/LwRT0KlsPSsXefcNvV1+oZHU8OLr8+MLt4=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=bpqrVCuvO+DUYb4QTJHvHdlMRoOdfOuLupj0hmWqKEEicyM+Cyx6okm2zlMfu5D9f 6YvKtNZSiNx88gPrAIAdxRa+p3Fg6kJoLbGqAGiBKtUVP+i1dOydjfdNH14jyEVRLz 7L1jBmhrdrL4ZkFR1D86p7uida+HmnzJ6AA/qJHFOm79FDhVYe+K+3a27DdBlNy8BG 6L+3sc9ZSTnvFlpx9pOLR4rvGLmZ55zgXrxPMNRlpPUJ/HM6WiJwmIhLYF+CV/uV5L cqSPmg6n9YYyvB1pGuIHcc2o/oeUE79ucYvc+0399CAOy+msT0c+eFgNOtT8CqL/kT mW9eVLXbqHu9Q== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH bpf-next v1 25/73] bpf: Add hidden stack slots for landing pads 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:40:59 +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: wrong release register in bpf_pad_note_release() clears wrong slot -- commit 9104e9a3b93e493a258c21287cd7baded3ef930f Author: Kumar Kartikeya Dwivedi bpf: Add hidden stack slots for landing pads This commit adds hidden stack slots below a function's stack frame to track held resources at run time when landing pads cannot determine from the PC or a NULL check whether a resource is held. > diff --git a/kernel/bpf/pads.c b/kernel/bpf/pads.c > index 657f17f2aaabb..a9a2b56364abe 100644 > --- a/kernel/bpf/pads.c > +++ b/kernel/bpf/pads.c [ ... ] > +/* > + * The call of @rel releases: the slot of the group that has the handle = is cleared, whichever call > + * filled it in this run. The first match ends the search: two reference= s to one object are the > + * same handle in two slots, and one of them is released. No match: the = call was given NULL. > + * Sections are all alike: the first slot that is not 0. > + */ > +static int clear_insns(const struct bpf_pad_note **notes, int nr, const = struct bpf_pad_note *rel, > + struct bpf_insn *buf) > +{ > + int i, k, n =3D 0, off, delta, reg; > + > + for (i =3D 0; i < nr; i++) { > + if (class_group(notes[i]->ent.class) !=3D rel->group) > + continue; > + delta =3D rel->delta - notes[i]->ent.cand[0][0].delta; > + /* > + * The delta is made of constants that the program chose, the offsets = of a node in > + * its object. It is added in R0, which a call is about to clobber: th= ere the JIT > + * blinds it like any other constant of the program. An insn on AX is = not blinded. > + */ > + reg =3D delta ? BPF_REG_0 : BPF_REG_AX; > + for (k =3D 0; k < notes[i]->nr_slots; k++) { > + off =3D notes[i]->off - k * BPF_REG_SIZE; > + buf[n++] =3D BPF_LDX_MEM(BPF_DW, reg, BPF_REG_FP, off); > + if (delta) > + buf[n++] =3D BPF_ALU64_IMM(BPF_ADD, reg, delta); > + if (rel->group < BPF_PAD_NR_SECTIONS) > + buf[n++] =3D BPF_JMP_IMM(BPF_JEQ, reg, 0, 2); > + else > + buf[n++] =3D BPF_JMP_REG(BPF_JNE, reg, rel->reg, 2); > + buf[n++] =3D BPF_ST_MEM(BPF_DW, BPF_REG_FP, off, 0); > + buf[n++] =3D BPF_JMP_A(0); > + } > + } [Severity: Medium] Can clear_insns() zero the wrong hidden slot when a release helper takes the reference in R2-R5 while R1 also points into the same object? bpf_pad_note_release() finds rel->reg by scanning R1..R5 in order and stopping at the first register matching ref: kernel/bpf/pads.c:bpf_pad_note_release() { ... for (r =3D BPF_REG_1; r <=3D BPF_REG_5 && !nr; r++) if (env->insn_aux_data[env->insn_idx].live_regs_before & BIT(r)) add_cand(&place, &nr, &frame->regs[r], ref, obj ? &addr : NULL, BPF_PLACE_REG, r); if (!nr || place.delta !=3D (s16)place.delta) sub->no_slots |=3D BIT(group); else note_release(env, sub, group, place.at, place.delta); } If one path calls bpf_kptr_xchg(&p->next, p), R1 and R2 share p's ref id, so bpf_pad_note_release() records R1 and offsetof(typeof(*p), next) as rel->reg and rel->delta instead of R2. If another path reaches the same call instruction with R1 =3D &p->next and R2 =3D NULL, release_reg() returns early on NULL without calling bpf_pad_note_release(). At run time on the R2 =3D NULL path, the instructions emitted by clear_insns() match R1 against p's slot + delta and zero p's hidden slot even though nothing was released, so a subsequent unwind pad will skip releasing p and leak it. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/cover.1796099737.gi= t.memxor@gmail.com?part=3D25