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=1796384901; b=Z22A0EQC0RuUZl7UVJ9oYojkagUDkrm/yljkd34e9k0j/jKWkLcuidO3hvY0NGPD+hqx G/6ifNqPws5iDc1YgQZFj5ze4XCzFeIzEz5BVMjBA+zWUdd3a8zcpiFN0lea/aziHslWI QUajCsRh52zcZvoOUjrtz7PWA4cjVWJyStZrUTibcjhsl42Eiz3VjyMBECG2vEC0YTo3c 4rsBo5kNtuQtJuMz95OmJqP0R58QGpir0V+pXWrIZYAPTyWe7EbnGXdqIjHUfjz3hztkQ vrbMYkJHSeCwQuxlDfrQCoMSY+d703MIqOg4MUKk4meQ1jXMsQbWNH89bacdrfIHNGw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384901; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=5sK+LjDhKhiuQ7AhrGkqzDslWmNqckoS/sVruf3OCyo=; b=eUZ5gsVrG64LFRvTzOeyeY5h36MiBxY2X20TnUGL2A1JK6CPTbR7A8bfp2bYcnR69xY2 9rIvV7MzgrA2uSNO+zfov3MlG8IK7Pld6WS6jfjqlks1sS0eyJzLmwex4+LK7XvEfk1Mr C5Bi9Bevq9ZsBiBcgNSq5WxtgJGMm5a6uGHahnxPH9fasfByt2KanSTJyijYM7qjoxhnA PZ3r0VNjzFUMydFZDGa8FiR5jH7kV58zNMZRMZgb6rsHRT/Yql3MKlIwPYzEI3PsYgQGH Xhkbmt3xk5SegG8SrP6pOPpOWZP/OwHYx1AIDlN2j7u9ZNIK8UgpYhkvaI8qHpL74jQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=RkNQl30D; 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 8B8DF606A337; Fri, 4 Dec 2026 11:48:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=RkNQl30D Received: by smtp.kernel.org (Postfix) with ESMTPSA id F04401F00935; Fri, 4 Dec 2026 11:48:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384901; bh=5sK+LjDhKhiuQ7AhrGkqzDslWmNqckoS/sVruf3OCyo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=RkNQl30D30FiwEb0lTiQWmaDdQc7PvMrpaFqHDmWVJ7IfeeF9iy3WEpifzXJnjUaE NVQgLrQ8UlOvKfWC6OjrhXGr6lIt7zsyDfzPaAyw+q1yrkRde5F2ywktjUwWkoRxlr oMp0HdSavCq6+003WL3VOOEdRy6XC0KgP1BPMZ+o= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Hao Sun , Kumar Kartikeya Dwivedi , Sasha Levin Subject: [PATCH 6.6 0342/1167] bpf: Fix uninit read for non-fetch atomics on partially spilled slots Date: Fri, 4 Dec 2026 18:56:09 +0900 Message-ID: <20261204100710.901164909@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Hao Sun [ Upstream commit 5a84b4424db8ae07f0ac682ab031c37a91dce50b ] check_stack_read_fixed_off() skips partial spill checks for non-fetch atomics; the following prog can be loaded: 0: (b7) r1 = 1 ; R1=1 1: (63) *(u32 *)(r10 -8) = r1 ; R1=1 R10=fp0 fp-8=????1 2: (db) lock *(u64 *)(r10 -8) += r1 ; R1=1 R10=fp0 fp-8=mmmmmmmm 3: (79) r0 = *(u64 *)(r10 -8) ; R0=scalar() R10=fp0 fp-8=mmmmmmmm 4: (77) r0 >>= 32 ; R0=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff)) 5: (95) exit When test run: retval=4294967295 Note fp-8 is ????1 at #1, yet it becomes fp-8=mmmmmmmm after the non-fetching atomic add at #2; hence the high 32 bits are leaked. Fix by applying the partial load check; after the patch, the prog is rejected: Verification failed: Memory Safety: Uninitialized stack read Reason: This rejected read uses 8 bytes at stack offset -8, but byte 4 in that range is uninitialized on this path. Programs loaded with CAP_PERFMON can be allowed to read uninitialized stack bytes, but this program is being rejected without that allowance. At: ... 0 | (b7) r1 = 1 1 | (63) *(u32 *)(r10 -8) = r1 >>> 2 | (db) lock *(u64 *)(r10 -8) += r1 3 | (79) r0 = *(u64 *)(r10 -8) 4 | (77) r0 >>= 32 This affects CAP_BPF only. Fixes: 354e8f1970f8 ("bpf: Support <8-byte scalar spill and refill") Signed-off-by: Hao Sun Link: https://lore.kernel.org/bpf/20260924131342.934290-1-sunhao.th@gmail.com Signed-off-by: Kumar Kartikeya Dwivedi [ sashal: Moved the dst_regno < 0 early returns into the full-slot branch and after the partial-slot validation loop, since this tree's function body is shaped differently from upstream's. ] Signed-off-by: Sasha Levin --- kernel/bpf/verifier.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index a72d196bcbd29..70ffa05a919d3 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -5027,10 +5027,10 @@ static int check_stack_read_fixed_off(struct bpf_verifier_env *env, } mark_reg_read(env, reg, reg->parent, REG_LIVE_READ64); - if (dst_regno < 0) - return 0; - if (!(off % BPF_REG_SIZE) && size == spill_size) { + if (dst_regno < 0) + return 0; + /* The earlier check_reg_arg() has decided the * subreg_def for this insn. Save it first. */ @@ -5060,6 +5060,9 @@ static int check_stack_read_fixed_off(struct bpf_verifier_env *env, return -EACCES; } + if (dst_regno < 0) + return 0; + if (spill_cnt == size && tnum_is_const(reg->var_off) && reg->var_off.value == 0) { __mark_reg_const_zero(&state->regs[dst_regno]); -- 2.53.0