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=1796384906; b=tSEJ8WT7HAcEnNaW6QqXB9mFmpBHdMcreHWpJBk0nvHZc2mX6jnj2Ome/8bFaUoL1LYp CMQBPbAF6ux0sr1O//W4AyqLpO259JqcmwsWfH8eIweIlWliu3FKuqPQif3celeUyagRH E3IM2Su6L9KBPdRnA267h33dNYv+89HFKD3DLcaASZ6nOCxSnUmbnil+SVg8Hrsk76YSc xF9eCJRXT6yQ5g45CZavKgU9AOwaJ2zm4B67xSzNpjOYMpC5TkhagilMHp5rRY3jj9A4L e1kg9ICm35RGrq1MSByUqO65xZkm8cVDnT2EwZ0EdILrjKk31o2+U4OAgavD8BPKZNQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384906; 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=bv8CThorz5pBzI67N106Ulxr9gBJY5n11snWG2f1co0=; b=0Ad1i6mu9+TNqcvfO0aFr4eI8vl2y6BHSkka7aUo835g0FihnKv69ZnS1llqA8fG2Bda w/h+RRyrWUzZLN9cydA+4ltVYXIM7qg5+N1b1lHnwpUC+hsppu24RETZmC77fmvMCxmRE qeIsyIBYDyIflo6ILjemnuwUvGePbjQ8sal6clFPK1SBHvxanK44ocJMAGBW+I2kNfv09 zkV3RqKHMVcqGOcAPkjGwpTj61uztS1uXnutQe/acniJlPTxQ5t5PXYIJmGGkU9lG7+7Q yP/z5pZiXNhjiQ6St4hD3g7gvslWPgxZNH3h5T3/IHizbCJV6Flwk0+mbGHuhfsu0Bw== 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=TKRjjsn8; 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 CB844606A32C; Fri, 4 Dec 2026 11:48:26 +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=TKRjjsn8 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3BC231F000CE; Fri, 4 Dec 2026 11:48:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384906; bh=bv8CThorz5pBzI67N106Ulxr9gBJY5n11snWG2f1co0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=TKRjjsn8RBw7xngq2vB6x+I1EIf9feAU/s+Rv2cS0+RLlR39LZnkw0ypOl0hxwEMB 0or8TvmJtm29drXxS1xsFH1xTPwAD1mqBOpkO8VT7epXxhHfC2mBo6qOFFoNzplfhY QLhWnpUVN17vWWhkDjRzqhRURUGDTHgNs3qAiZac= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Kumar Kartikeya Dwivedi , Hao Sun , Sasha Levin Subject: [PATCH 6.6 0343/1167] bpf: Fix uninit read for helper mem args on partially spilled slots Date: Fri, 4 Dec 2026 18:56:10 +0900 Message-ID: <20261204100710.926226618@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 b3861495d2b2f7459cddf49e63fa0758ba430583 ] check_stack_range_initialized() takes the spilled register path when bpf_is_spilled_reg(ss) holds, which, however, only looks at the last byte of the slot. Hence, a partially spilled scalar (on the lower part) bypasses the check and the following loads: 0: (b7) r1 = 1 ; R1=1 1: (63) *(u32 *)(r10 -8) = r1 ; R1=1 R10=fp0 fp-8=????1 2: (18) r1 = 0x0 ; R1=map_ptr(map=rb,ks=0,vs=0) 4: (bf) r2 = r10 ; R2=fp0 R10=fp0 5: (07) r2 += -8 ; R2=fp-8 6: (b7) r3 = 8 ; R3=8 7: (b7) r4 = 0 ; R4=0 8: (85) call bpf_ringbuf_output#130 ... When executed, it dumps the uninit four bytes: RINGBUF: 01 00 00 00 ff ff ff ff This is the same root cause as the non-fetch atomic case fixed in commit 5a84b4424db8 ("bpf: Fix uninit read for non-fetch atomics on partially spilled slots"). Fix by only taking the spilled register path for the bytes marked STACK_SPILL, so the rest of the slot goes through the usual checks. Fixes: 354e8f1970f8 ("bpf: Support <8-byte scalar spill and refill") Suggested-by: Kumar Kartikeya Dwivedi Signed-off-by: Hao Sun Link: https://lore.kernel.org/bpf/20260925082814.1554771-1-sunhao.th@gmail.com Signed-off-by: Kumar Kartikeya Dwivedi Signed-off-by: Sasha Levin --- kernel/bpf/verifier.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 70ffa05a919d3..687be68c728a9 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -7368,7 +7368,12 @@ static int check_stack_range_initialized( goto mark; } - if (is_spilled_reg(&state->stack[spi]) && + /* + * Only the bytes marked STACK_SPILL hold the spilled register. + * The rest of a narrowly spilled slot keeps its previous type + * and must be initialized on its own. + */ + if (*stype == STACK_SPILL && (state->stack[spi].spilled_ptr.type == SCALAR_VALUE || env->allow_ptr_leaks)) { if (clobber) { -- 2.53.0