From nobody Sat Feb 7 20:38:40 2026 Received: from mail-lj1-f202.google.com (mail-lj1-f202.google.com [209.85.208.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 51C661B1433 for ; Thu, 4 Jul 2024 15:08:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720105726; cv=none; b=ZT0Pjx15WKDfrP7yj0wTmn920Iz1zcJ1Vd4Mftk1y8YpmD+rSCT+8UvlPeqAnABl5HW1eRRi0oV1rAeayovczUEuWFnRC5vza46vaRjx4Z4I9plst56AcbJ6iqc/tCrcGBLpScK3l6LW07CHxyB5zm1r4ic76AxF6SNyn1vg/Xo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720105726; c=relaxed/simple; bh=JuGBj/G53huERAYmOEJ7zt/Eif/6HD+856XFNofQJEM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=V+BnWZugLxcKUbUY1QJIYEyoFJRT882Cmt5HnHinkWGf4dGU5J5u04A7E7Yi9O9EYhx10qqMtHt+48QAdCwWfbquZ07rLJQn8U11/dxdcyCjrkgL4QfVAVAIGeJQ/LUngOQ7+EyLpMdgk5u5RR94LDOBkKTkjITT7eV2sBy57oI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=qUanNB8F; arc=none smtp.client-ip=209.85.208.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="qUanNB8F" Received: by mail-lj1-f202.google.com with SMTP id 38308e7fff4ca-2ee864483c2so6831171fa.2 for ; Thu, 04 Jul 2024 08:08:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1720105723; x=1720710523; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Bz+EbBDOjmeMrGJd8QmvR0upRYw2Fmi/0lt2+1YTdQg=; b=qUanNB8FSRpjUgMYUq/bDi4zOvdNrV/FFLd0qI/16Z+lRVp+4CBXd4zkkax3SW2RgA P5xtrdUtzaOICzkrXeR3B6qt6soMxZgxDNzDFeIBZ7o2lawQdtK6kl6bgSSQr862Ua2R kOe+8vc+L8OPTC6LPKBwdTN0AS4SykBB8LRLU4U6pT/nPMUz2uY5eyD+a+Hqe2vmEUyU y/NYuVvJolfNUZB3ighoW4hLHjpp+VroPu+VONwEOmDC0Lg2IOeisaGNZNS8DvJlPbMo bG8TxJ+7/ew3N6xp2Jg34NYRkLTfkFEkTEyY9s6upK4F6bRB0wt3bBMb0tl1NbP7l0j5 Iyxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720105723; x=1720710523; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Bz+EbBDOjmeMrGJd8QmvR0upRYw2Fmi/0lt2+1YTdQg=; b=p9XG/R7SPNdVNoI9Aigp8ntddheids3wpI1/u/dSZokZbkMdmQEarMxcd5/bPuH/y3 zOwRf6REAt6uSyw7F0w4ZIa/9KDyZyfIPzrQxH2CMM1TZakP5Uje2mQWWhnjV7Q6rbTP tOMLjlgxiSip1yDsbbC0BO/RnCk7cBW33Jg+LLL/9TJDFPOGfMwmo8DggahfWE7Z1vYA zPtDzil4sJpqaL6fN9ou0ciwcnk0JRwJRSYR2d+2jGHhWD6jEcisl2264+fNzXAGs5Bp ZtApIk3vAxS3s3h4imzI+bCSx710EsiY8f682/17ATQt49ats8iCzQU7xVG0Rn7jIXSU q8iQ== X-Forwarded-Encrypted: i=1; AJvYcCWt16oFsGUbJ5DTNUuH/gx2l5Q4PN3UDkXGvU48S1goMqIhqejTD5cPWiIHKAM+ASxOeX6VimcwUiTAkSwGA6N4rZG5OKjGwqJZBsDS X-Gm-Message-State: AOJu0YwnDd0Pj2AYq7pHXJtgSsS9AS2ZpEHm5Kr3S0Yr6z+F8Yj9ipXk FNyvQKNvX40ucblyo9W+1VkEJFCdermN6TAaQ6WzSI33vvj0rVgJ/dOVwNzm5uLSEyR9Pe3zNlc aoz5+7AAghGaBgw== X-Google-Smtp-Source: AGHT+IE03aDhat/nctBL3TSUjtF7n0/BH4Iv3XWnyA2/KfN0iRZTIP1nm3dzjP2dil5/BZGhl8862qWvC2IkeAc= X-Received: from aliceryhl2.c.googlers.com ([fda3:e722:ac3:cc00:68:949d:c0a8:572]) (user=aliceryhl job=sendgmr) by 2002:ac2:51c5:0:b0:52c:7f96:81d1 with SMTP id 2adb3069b0e04-52ea063536dmr1741e87.6.1720105722612; Thu, 04 Jul 2024 08:08:42 -0700 (PDT) Date: Thu, 04 Jul 2024 15:07:58 +0000 In-Reply-To: <20240704-shadow-call-stack-v3-0-d11c7a6ebe30@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240704-shadow-call-stack-v3-0-d11c7a6ebe30@google.com> X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=2683; i=aliceryhl@google.com; h=from:subject:message-id; bh=JuGBj/G53huERAYmOEJ7zt/Eif/6HD+856XFNofQJEM=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBmhrrxeD87TT9nOZdZlSkM9Ug38Lq8pSNUKPjWV S8NfW1wCauJAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCZoa68QAKCRAEWL7uWMY5 RuclEACRYz+o0orQSxwv7q+/d5rq3VqoTqZslfFT+l8/uynAxKQaS04uT9n0J3p20m905uf+kbA jyxYAe8B1qxiRcLwgxRbrHbKCHdch+xHTn/Qr2mV9q3bNPwwM79X3rvjaVOVhYkRL5JtYZMUuLq Z1BsoS7Nb89E01i8mTQhua3kOSrs3sjneafcmOushtO6IJxXiznFxXssUNaHctx4rHNQIvi94Bs RsNZ950OQZjq9mPNFZ6ZPetrlDGFFcM9Fiy3o8QwzLQUsSJ+zb8FgN6bBnucaHg1EVplZQzYj/y UHd6j4p9PzDXvWho+jfoV3LVuKBFkmyB8wfGYWbAoAIgKsPef5TSHKErkmKV4Cd7MsSe6JeVE4j NR0qFvEw9zjxUG3Mt8tYEoSpG5XTFwdqd+cpZCn+cScG+F2olTofTbx+f81TS45rrQ58EsHhZyu AHDBIVcrQ5x39H5d0RZMLPOStirm749G3soSpvBZo6+zYk8lxPaRmOZwuDn+EapYreKrtLFEcKY rLsd87PNhxDelvB35f8h8er05euI9yQSbucbYlJCE2kOmqRJ/VBdNFoBRaMb+9B7/M+ppoxPTq2 OhnZJy1a3hf5nYwjnjqWSOpL1i50mUIrWLxSw+zmnVzGFQfWaqywlsFX2HbImPn9kPkvibqf+A9 7v/oXvrs1CicloQ== X-Mailer: b4 0.13-dev-26615 Message-ID: <20240704-shadow-call-stack-v3-2-d11c7a6ebe30@google.com> Subject: [PATCH v3 2/2] rust: add flags for shadow call stack sanitizer From: Alice Ryhl To: Catalin Marinas , Will Deacon , Jamie Cunliffe , Sami Tolvanen Cc: Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Ard Biesheuvel , Marc Zyngier , Mark Rutland , Mark Brown , Nick Desaulniers , Kees Cook , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , "=?utf-8?q?Bj=C3=B6rn_Roy_Baron?=" , Benno Lossin , Andreas Hindborg , Valentin Obst , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, rust-for-linux@vger.kernel.org, Alice Ryhl Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable As of rustc 1.80.0, the Rust compiler supports the -Zfixed-x18 flag, so we can now use Rust with the shadow call stack sanitizer. On older versions of Rust, it is possible to use shadow call stack by passing -Ctarget-feature=3D+reserve-x18 instead of -Zfixed-x18. However, this flag emits a warning, so this patch does not add support for that. Currently, the compiler thinks that the aarch64-unknown-none target doesn't support -Zsanitizer=3Dshadow-call-stack, so the build will fail if you enable shadow call stack in non-dynamic mode. See [2] for the feature request to add this. Kconfig is not configured to reject this configuration because that leads to cyclic Kconfig rules. Link: https://github.com/rust-lang/rust/issues/121972 [1] Signed-off-by: Alice Ryhl --- Makefile | 1 + arch/Kconfig | 2 +- arch/arm64/Makefile | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index c11a10c8e710..4ae741601a1c 100644 --- a/Makefile +++ b/Makefile @@ -945,6 +945,7 @@ ifdef CONFIG_SHADOW_CALL_STACK ifndef CONFIG_DYNAMIC_SCS CC_FLAGS_SCS :=3D -fsanitize=3Dshadow-call-stack KBUILD_CFLAGS +=3D $(CC_FLAGS_SCS) +KBUILD_RUSTFLAGS +=3D -Zsanitizer=3Dshadow-call-stack endif export CC_FLAGS_SCS endif diff --git a/arch/Kconfig b/arch/Kconfig index 238448a9cb71..5a6e296df5e6 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -690,7 +690,7 @@ config SHADOW_CALL_STACK bool "Shadow Call Stack" depends on ARCH_SUPPORTS_SHADOW_CALL_STACK depends on DYNAMIC_FTRACE_WITH_ARGS || DYNAMIC_FTRACE_WITH_REGS || !FUNCT= ION_GRAPH_TRACER - depends on !RUST + depends on !RUST || RUSTC_VERSION >=3D 108000 depends on MMU help This option enables the compiler's Shadow Call Stack, which diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile index 3f0f35fd5bb7..bbf313ddd700 100644 --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -57,9 +57,11 @@ KBUILD_AFLAGS +=3D $(call cc-option,-mabi=3Dlp64) ifneq ($(CONFIG_UNWIND_TABLES),y) KBUILD_CFLAGS +=3D -fno-asynchronous-unwind-tables -fno-unwind-tables KBUILD_AFLAGS +=3D -fno-asynchronous-unwind-tables -fno-unwind-tables +KBUILD_RUSTFLAGS +=3D -Cforce-unwind-tables=3Dn else KBUILD_CFLAGS +=3D -fasynchronous-unwind-tables KBUILD_AFLAGS +=3D -fasynchronous-unwind-tables +KBUILD_RUSTFLAGS +=3D -Cforce-unwind-tables=3Dy -Zuse-sync-unwind=3Dn endif =20 ifeq ($(CONFIG_STACKPROTECTOR_PER_TASK),y) @@ -114,6 +116,7 @@ endif =20 ifeq ($(CONFIG_SHADOW_CALL_STACK), y) KBUILD_CFLAGS +=3D -ffixed-x18 +KBUILD_RUSTFLAGS +=3D -Zfixed-x18 endif =20 ifeq ($(CONFIG_CPU_BIG_ENDIAN), y) --=20 2.45.2.803.g4e1b14247a-goog