From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lf1-f74.google.com (mail-lf1-f74.google.com [209.85.167.74]) (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 809621B1436 for ; Thu, 4 Jul 2024 15:08:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720105726; cv=none; b=efQzqcuR0pnzokFtClSYVTWHS3ena0WqvncRNOzYNh91/Frj2IfCH1a0uN/GbOhBrEDmh0nwHS8+hfdc4EDM/KKhjYK5RoNvK21owfzP+AbvLW6LCBzqLRP6K0IgDvFZrGSzR4Q1QE3rp4sGtIab041NcLU3lwNaX2+ugxHl/Lc= 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.167.74 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-lf1-f74.google.com with SMTP id 2adb3069b0e04-52ea3c7dfdcso47090e87.3 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=JOWRVLPjRblKnpf2j5bCf7Yuut/sFvg6D5TO+8+yKGZv7Vj+Id7ktvYYkhMHFmUzzX AY0KMfbddgfNR33+TyIaIkalSX+8W6mB1QxbqwtJyTqQV5ZmsDa8/2F8mD53a9QH1dQ9 tMDQb9F01RyKVdr5d4By7kvfBwUwqR+IvC17cMs+iwOGtDGrp1fkrh+J6jvhNeGeD2K3 rPdosM4JVucjoasFKCMwD8ihM6DVHZ3b++dQTWJTwyFwlOkLuzUeRiyDgl8kqwcSe0vz EzLZhc1E2N3TqFpccNItweyszohQRKSiprdF8PhmAuL8voRQ2JJDwbianPUPjb/Omc48 YDLA== X-Forwarded-Encrypted: i=1; AJvYcCUwUkEwV/MC4Aa5EkjDgsZs/vuCrBZBqm74g39fAVfTrKPXCDH6+6ULUculjnpMIWyKfIoZSyDJkWS/BH8FdHBseQ5KFzkDz5bPmMq+0N4= X-Gm-Message-State: AOJu0Yw83y5a4aTE9PVTfSsslSgVd2Eq6rBKl9/ifi9YyviXDv8LDFbV exzvDcSRkzsakgA+4Pm/OB85zCMpVv6NrSReOiicMpQUYoe8TXjZIC5VrtbXasajlEyrQeivjgI TqmVsku7aJ0F0Kw== 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: rust-for-linux@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" 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=+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=shadow-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 := -fsanitize=shadow-call-stack KBUILD_CFLAGS += $(CC_FLAGS_SCS) +KBUILD_RUSTFLAGS += -Zsanitizer=shadow-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 || !FUNCTION_GRAPH_TRACER - depends on !RUST + depends on !RUST || RUSTC_VERSION >= 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 += $(call cc-option,-mabi=lp64) ifneq ($(CONFIG_UNWIND_TABLES),y) KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables KBUILD_AFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables +KBUILD_RUSTFLAGS += -Cforce-unwind-tables=n else KBUILD_CFLAGS += -fasynchronous-unwind-tables KBUILD_AFLAGS += -fasynchronous-unwind-tables +KBUILD_RUSTFLAGS += -Cforce-unwind-tables=y -Zuse-sync-unwind=n endif ifeq ($(CONFIG_STACKPROTECTOR_PER_TASK),y) @@ -114,6 +116,7 @@ endif ifeq ($(CONFIG_SHADOW_CALL_STACK), y) KBUILD_CFLAGS += -ffixed-x18 +KBUILD_RUSTFLAGS += -Zfixed-x18 endif ifeq ($(CONFIG_CPU_BIG_ENDIAN), y) -- 2.45.2.803.g4e1b14247a-goog