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=1796387573; b=ny/Y4Iigifcj6Ema73MZmAMMUBGyScIJQbHovdrbGxtbpPN/Clo3ss8l3f97r1m/QMDD nZS/rcR7t1SIoaqb+CS/EVMyxaVXnzC6EYifTrXgx02hwK5rAgMAQr35sSMMj+ef2Cxa5 vsFjcft0eCl4K8HrtKFoGX7//6YJuWJLRac+bFd7VT0991BhJnkBRKq+XCydW1I9WfPej x20iJXS3DbhoSRdq7/HEoDgHDP/g6xg3P68fEE4J0waeVNMv/Di/mmp6cmDkEhxV3lQ0G 08mmY0IPss+yYlX90JUilV9z6HlLY6apQNTcpJXeua015Yjm8J78ISRHN/+i6m6LKgw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387573; 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=fw5PPJ0YFelF1Fow0g+tCkNk4kd6nA5HYLE1A72+yx8=; b=KpIS2DFVa7570JZv/oTQ9QGhLtxle5XlTa3eZ+K669eSK8MaIPXHYKBg8a3gyXvfxZo8 UW+yJhjhN4JHSIT8bqoUnfX2zw8ZceegSe8X9WASUqab55NoDkphkKr0btnC53gL+cQzx FOFnwxuxPsHKAZ7AY4hOkqgCpM0qY6EIZ+/4gfSJz+0K3Ru2S0jnfHCbcTY3TV6G1ubYl AqmxF4RSehCyVI+XD6VNjU893WCMJmcWp/UNbYdnjlwF8hoMIEGyzRi3aiODqCa3AW3Zf hONwIiK+azPFjB0VuZqmSfjGRpDQkXo7DpTKcmMFJtGD3+MnjmFjBU9JLc0WHYDUYKg== 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=Gntfbyy0; 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 BCFD1606A322; Fri, 4 Dec 2026 12:32:53 +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=Gntfbyy0 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3BB141F000C2; Fri, 4 Dec 2026 12:32:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387573; bh=fw5PPJ0YFelF1Fow0g+tCkNk4kd6nA5HYLE1A72+yx8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Gntfbyy0JW0QkaILB0MoklkOkMTJcQ5A5IbN7bq4t9xz0wHLLPJjaR0hTS0Kx0fci JXh1pXoF81TdaIsdym4cfdfh05kml1jkoziOufhyRAshLA3ctExvjyrCwG4UNsAJtq mQoG57LBRpmoj84g+pmcp4/wdU71rVd5lgNMyB4w= 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.1 0301/1059] bpf: Fix uninit read for helper mem args on partially spilled slots Date: Fri, 4 Dec 2026 18:57:12 +0900 Message-ID: <20261204100652.069779367@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@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.1-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 ba4ae75512294..dee55d5db7da7 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -5391,7 +5391,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