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=1796387935; b=3ge9dE3T499nGmhmM/bkJGX/zXO5DOz1MEYEZjrnEivXMmhEXvVRNTBnOMqx2Y4uoLz9 1UUM2DX5wxdGK60854OheBjgiw5YJbrWAUtqlYqpNYgdQM5rDp9tpA1Axa0ri3jKcreZs wOdQAUvPBYJonhdPEQ71P2UvYGUPX/DjUiIJSUYjMk5736kOZr+2HfEm33rrtJbwBuEW3 kPhqy1Oa/ROfxqDJvC5FPnurJ/yOpJFOn0aMt27y5zLy194bESqJAfi9A7Nj2NCYTEAm9 sPliUwcfIEGKawC+U3xubeTwH9qzqbU2fvhT/0UrBYzjx8MI6oPw9tB/SW28h+KW1fw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387935; 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=83YRAEZUg9GuoL+l3UfD05gUWkAfBZ1O4Fk7/YO1iqg=; b=zZGLSCG0glaZtqqz9Epd7OYxYTMGtzD6GFUNVppJn91wMkKl4OmElBAVrYLZN6/gOkK/ h/bSjEAzc1G8mgUpDw86FSzheAZwIb6dcK+aaFo2lwo/YtSE0SE77jsNv5d6i7xmI7SUu 17sBrq4SEWnWQZjUNd18hs1epZDeplKIbd1vwqnjT2JM6LITZv1vMNSEFZmqn/q1TeP4g 6umLtCnLIUnuv9tTuYWTTLzPqo1nV8XWMTxX4Y/rpcXqQPBw9bCGUg9HjGTijCq5vE5jC dVo7Wro78nIDEze3VuK5sDppVXVl+al2d6RMxu2e33NCsiMFtR3SpheQ13LwPBGrirw== 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=QxLqOd9D; 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 2B17E606A322; Fri, 4 Dec 2026 12:38:55 +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=QxLqOd9D Received: by smtp.kernel.org (Postfix) with ESMTPSA id 99F8C1F00897; Fri, 4 Dec 2026 12:38:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387935; bh=83YRAEZUg9GuoL+l3UfD05gUWkAfBZ1O4Fk7/YO1iqg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=QxLqOd9D/T3VbklWdsnFSf/lh6K9d6x4ZqENmrb7kNpFnJiCdzwuTMu00IAPCR6fu C3CZqLrz4/sV7oZya+td28Kpj38wkv9WnaMoI5iZhLUWT3AcjKhJgTDFDpa0LImgM0 MtMQRzC5alaXI2NzyYLARlupApCPiyManUMuMueA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Woojin Ji , Alexei Starovoitov , Sasha Levin Subject: [PATCH 6.1 0419/1059] bpf: Zero-extend the index in inlined bpf_get_func_arg() Date: Fri, 4 Dec 2026 18:59:10 +0900 Message-ID: <20261204100655.188346311@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: patches@lists.linux.dev 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: Woojin Ji [ Upstream commit 1c1dda9ba9f3af9cd511a197dcc86de2465d8fe5 ] bpf_get_func_arg() takes a u32 index, but the inlined expansion compared only the low 32 bits of R2 with the argument count and then shifted the full 64-bit register to compute the context address. R2 is ARG_ANYTHING, so nothing guarantees that its upper bits are zero: an index of 1ULL << 32 passes the bounds check as index zero while the load is performed at ctx + (1ULL << 35). Shift the index as a 32-bit value. When the 32-bit bounds check passes, the low 32 bits of R2 are below R0, and R0 is at most 255: the trampoline arm masks the argument count with 0xFF and the raw_tp arm uses the BTF argument count minus one, which the verifier caps at MAX_BPF_FUNC_ARGS. The 3-bit shift therefore cannot overflow and it clears the upper bits of the register. Widening the comparison instead would reject indices whose low 32 bits are valid. The check itself is unchanged, so this cannot change which programs are accepted, only the address that is computed. Fixes: f92c1e183604 ("bpf: Add get_func_[arg|ret|arg_cnt] helpers") Signed-off-by: Woojin Ji Signed-off-by: Alexei Starovoitov Link: https://patch.msgid.link/20261018-get-func-arg-v2-1-048848b3eddf@gmail.com [ sashal: Changed the inlined bpf_get_func_arg expansion in kernel/bpf/verifier.c instead of the upstream fixups.c, since this tree has no such file; the edit itself is the same. ] Signed-off-by: Sasha Levin --- kernel/bpf/verifier.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 3e2865e0dc80b..423f8134cd502 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -14650,7 +14650,7 @@ static int do_misc_fixups(struct bpf_verifier_env *env) /* Load nr_args from ctx - 8 */ insn_buf[0] = BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -8); insn_buf[1] = BPF_JMP32_REG(BPF_JGE, BPF_REG_2, BPF_REG_0, 6); - insn_buf[2] = BPF_ALU64_IMM(BPF_LSH, BPF_REG_2, 3); + insn_buf[2] = BPF_ALU32_IMM(BPF_LSH, BPF_REG_2, 3); insn_buf[3] = BPF_ALU64_REG(BPF_ADD, BPF_REG_2, BPF_REG_1); insn_buf[4] = BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_2, 0); insn_buf[5] = BPF_STX_MEM(BPF_DW, BPF_REG_3, BPF_REG_0, 0); -- 2.53.0