From patchwork Thu May 1 07:35:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Gerhorst X-Patchwork-Id: 886586 Received: from mx-rz-1.rrze.uni-erlangen.de (mx-rz-1.rrze.uni-erlangen.de [131.188.11.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E230B2DC782; Thu, 1 May 2025 07:57:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=131.188.11.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746086261; cv=none; b=j3Y05CpWEhLFbvmpY0a+Mp9sYHyqSkmL8FZNniOgyVfK8oCFFmlsUzg+3jw4xHnf8/R0RNBgIQq00R7g0vEGmni4rV4OnPcX4s5jdh0cyYjaagtYce5TkyTE9lbBGZY70Hb4haQ1z29mx4F0qmzrHvQL3D9ggVdCJ730+Lsch80= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746086261; c=relaxed/simple; bh=e7E/j8WxzZn+JZOzyoOOcQbBdQtO6hyS1FFCCVgOb98=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bM7IDJvYhsGnanGWk1Sq7nNCFYr2v9N4DWI3MRgT+STN15uwTmWJzTtaBYjA2djlugtQ/jgTbXWfz0jUtiCDTjHAQN3ltBAgNNyDj3DfTF/JwY68ceCc3uOJof9uihNaL40wXQs1oKvujP/uT+aQSBuynoKpKKR0cUrjHnwrfD8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fau.de; spf=pass smtp.mailfrom=fau.de; dkim=pass (2048-bit key) header.d=fau.de header.i=@fau.de header.b=N5jRSGvf; arc=none smtp.client-ip=131.188.11.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fau.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fau.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=fau.de header.i=@fau.de header.b="N5jRSGvf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fau.de; s=fau-2021; t=1746086257; bh=Mh/McMFl1sfMWaVxUouRcc2dZA/Y3EiLQKZKPq/VM5U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:To:CC: Subject; b=N5jRSGvfw9Z/z9en8secDIzqxvtMNQLDFt995FGcMf/oXOVpetXv2rWwMPQQc8vvn z52tVsmjqOyb991SJ7obA0ebs4OUvxEA+YeNq7qkPW2hBFEZZ5wFFZEGeprujsBNhp apocaBFFFBV9uRgchIYSFKpoOdvmG7g/OOFZWDKUv9qT5NfJRYqkvAJYWaX+gaFUWM 1oadZxM0xNmVi9FdtcwtTp+1Kg4eWPC7kBeEHn/XmtxLUxmQjHxeBu8a01hhM9s6Vu As8FQ+g1HtdpBDfEAPuo+Roh/kw7BFaLmySUfOFZdXXjg25jyMvSw6jc1rd1Flbzte 5Gp/3Q+MpraJA== Received: from mx-rz-smart.rrze.uni-erlangen.de (mx-rz-smart.rrze.uni-erlangen.de [IPv6:2001:638:a000:1025::1e]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-rz-1.rrze.uni-erlangen.de (Postfix) with ESMTPS id 4Zp5xs2wm6z8srj; Thu, 1 May 2025 09:57:37 +0200 (CEST) X-Virus-Scanned: amavisd-new at boeck4.rrze.uni-erlangen.de (RRZE) X-RRZE-Flag: Not-Spam X-RRZE-Submit-IP: 2001:9e8:3636:a700:12b2:e53f:6cbc:f48c Received: from luis-tp.fritz.box (unknown [IPv6:2001:9e8:3636:a700:12b2:e53f:6cbc:f48c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: U2FsdGVkX182BTKsmsUxPlxvR5qszKlQmxj0W+48n0g=) by smtp-auth.uni-erlangen.de (Postfix) with ESMTPSA id 4Zp5xp0Y7jz8sv0; Thu, 1 May 2025 09:57:34 +0200 (CEST) From: Luis Gerhorst To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Puranjay Mohan , Xu Kuohai , Catalin Marinas , Will Deacon , Hari Bathini , Christophe Leroy , Naveen N Rao , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Mykola Lysenko , Shuah Khan , Luis Gerhorst , Henriette Herzog , Saket Kumar Bhaskar , Cupertino Miranda , Jiayuan Chen , Matan Shachnai , Dimitar Kanaliev , Shung-Hsi Yu , Daniel Xu , bpf@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kselftest@vger.kernel.org Cc: Maximilian Ott , Milan Stephan Subject: [PATCH bpf-next v3 07/11] bpf: Rename sanitize_stack_spill to nospec_result Date: Thu, 1 May 2025 09:35:58 +0200 Message-ID: <20250501073603.1402960-8-luis.gerhorst@fau.de> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250501073603.1402960-1-luis.gerhorst@fau.de> References: <20250501073603.1402960-1-luis.gerhorst@fau.de> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This is made to clarify that this flag will cause a nospec to be added after this insn and can therefore be relied upon to reduce speculative path analysis. Signed-off-by: Luis Gerhorst Cc: Henriette Herzog Cc: Maximilian Ott Cc: Milan Stephan Acked-by: Kumar Kartikeya Dwivedi --- include/linux/bpf_verifier.h | 2 +- kernel/bpf/verifier.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h index 9734544b6957..cebb67becdad 100644 --- a/include/linux/bpf_verifier.h +++ b/include/linux/bpf_verifier.h @@ -576,7 +576,7 @@ struct bpf_insn_aux_data { u64 map_key_state; /* constant (32 bit) key tracking for maps */ int ctx_field_size; /* the ctx field size for load insn, maybe 0 */ u32 seen; /* this insn was processed by the verifier at env->pass_cnt */ - bool sanitize_stack_spill; /* subject to Spectre v4 sanitation */ + bool nospec_result; /* result is unsafe under speculation, nospec must follow */ bool zext_dst; /* this insn zero extends dst reg */ bool needs_zext; /* alu op needs to clear upper bits */ bool storage_get_func_atomic; /* bpf_*_storage_get() with atomic memory alloc */ diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 9c921867f77f..1e1eca85b7a6 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -5031,7 +5031,7 @@ static int check_stack_write_fixed_off(struct bpf_verifier_env *env, } if (sanitize) - env->insn_aux_data[insn_idx].sanitize_stack_spill = true; + env->insn_aux_data[insn_idx].nospec_result = true; } err = destroy_if_dynptr_stack_slot(env, state, spi); @@ -20887,7 +20887,7 @@ static int convert_ctx_accesses(struct bpf_verifier_env *env) } if (type == BPF_WRITE && - env->insn_aux_data[i + delta].sanitize_stack_spill) { + env->insn_aux_data[i + delta].nospec_result) { struct bpf_insn patch[] = { *insn, BPF_ST_NOSPEC(),