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=1796380552; b=RCnLuLpMXCw+7Z7iCaZn6IXvKeq+n8BXSXWPQEGG6LDsjlnZ5j7H9x5pp+9Zsqz8XoK1 6dFlEjoSP2UUNizSJzsk6KoAH7a09/3o13OwuOixFUMQ68UoPbWoNSEzKnyOvHMqowrs3 GAU8JFdIArokGYFploXWZalO8U5AFQaoKrYPyaah0+Zvs5XQ6xzHdzT31JdbdVWPIqT9I XkuR4Hzb6PJOVxxosN+nLHYvdc39XwBTuRU+2BcjiveRTQqLiXtwvYdnZMSz7w6SthBOU l+B2sCDSgCHAAo9Xlvr88iGyCJQGsvZsIfQr6kSaIyG9u7v1fKNFBK2pYge30G89FUA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380552; 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=hZmEc0EF2gupVCFm1FOhaWiCnd7EsQynR2IsxviN5V0=; b=sbCDxLen2IcacKsp5PVdi7jbIke41HSp7/Oay372CV7B3SXS0a9zOOS1QauBxDhFIis5 uk9MajjiAOHZ/evWZ3QTHbmCO9vxQb7/sE6d54s52iRywElcm4Q3XUBHY+GbpjiiHTJvE NRJCRcky+XZ3gY0kjfZveu54/7R7SPJu2JPY+fJ1UbEvZ+gb36vbD0Xy09E4bUtjC0HZa k1zUca/NoFJxFn9z05Md+oj/3fVcXTXgrWfIeUGcN7iy9yKhncZAQvmo03jnPFXxcqCW+ zVIV9/DCxDQR6/x40IhBe6vj3SKaxDMoS2cOicZqmO1QRvOQcKBg+gLRLSyotZnn13g== 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=PBm90Cb7; 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 2BE2C606A682; Fri, 4 Dec 2026 10:35:52 +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=PBm90Cb7 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 95A341F000C2; Fri, 4 Dec 2026 10:35:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380552; bh=hZmEc0EF2gupVCFm1FOhaWiCnd7EsQynR2IsxviN5V0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=PBm90Cb7J+C1EkFNHls9hvLHxPcvfA8VIy9CH2tUKRAasdJ2Z3SnzmCgw5CJG1989 Sq7RqEoZvK3Kuz++pyM8v27TOEfVksxgvE8FaHPNLAPyG9DnMKR1VKVszF3HK2KMrN CAF+gz7hEDFp0moreZnznRFCvoZqba7l4YYV0+AI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Luis Gerhorst , Alexei Starovoitov , Sasha Levin Subject: [PATCH 7.3 324/742] bpf: Emit nospec after calls and atomics that write to the stack Date: Fri, 4 Dec 2026 19:03:08 +0900 Message-ID: <20261204100643.629156243@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@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 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alexei Starovoitov [ Upstream commit 1879b5e505de97e250bb2d7e6914fbdf4032e15b ] check_stack_write_fixed_off() sets nospec_result for BPF_ATOMIC insns and for calls of helpers and kfuncs too. do_check() ends a speculative path there, but bpf_convert_ctx_accesses() emits the nospec only after BPF_MEM stores. Later passes rewrite a call and need its aux data. Put the nospec in front of the next insn. Fixes: d6f1c85f2253 ("bpf: Fall back to nospec for Spectre v1") Fixes: 880442305a39 ("bpf: Introduce load-acquire and store-release instructions") Suggested-by: Luis Gerhorst Signed-off-by: Alexei Starovoitov Acked-by: Luis Gerhorst Link: https://patch.msgid.link/20261126033816.4124847-5-alexei.starovoitov@gmail.com Signed-off-by: Sasha Levin --- kernel/bpf/fixups.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/kernel/bpf/fixups.c b/kernel/bpf/fixups.c index 2f53df08e7056..b39e6acfd002f 100644 --- a/kernel/bpf/fixups.c +++ b/kernel/bpf/fixups.c @@ -815,6 +815,7 @@ int bpf_convert_ctx_accesses(struct bpf_verifier_env *env) const int insn_cnt = env->prog->len; struct bpf_insn *epilogue_buf = env->epilogue_buf; struct bpf_insn *insn_buf = env->insn_buf; + bool nospec, nospec_next = false; struct bpf_insn *insn; u32 target_size, size_default, off; struct bpf_prog *new_prog; @@ -884,8 +885,13 @@ int bpf_convert_ctx_accesses(struct bpf_verifier_env *env) enum bpf_reg_type ptr_type; u8 mode; - if (env->insn_aux_data[i + delta].nospec) { - WARN_ON_ONCE(env->insn_aux_data[i + delta].alu_state); + /* A call or an atomic gets its nospec in front of the next insn */ + nospec = env->insn_aux_data[i + delta].nospec; + WARN_ON_ONCE(nospec && env->insn_aux_data[i + delta].alu_state); + nospec |= nospec_next; + nospec_next = env->insn_aux_data[i + delta].nospec_result; + + if (nospec) { struct bpf_insn *patch = insn_buf; *patch++ = BPF_ST_NOSPEC(); @@ -977,6 +983,7 @@ int bpf_convert_ctx_accesses(struct bpf_verifier_env *env) delta += cnt - 1; env->prog = new_prog; insn = new_prog->insnsi + i + delta; + nospec_next = false; continue; } -- 2.53.0