Re: [PATCH v5] rust: support for shadow call stack sanitizer

From: Will Deacon
Date: Fri Aug 23 2024 - 08:24:42 EST


On Tue, Aug 20, 2024 at 05:13:58PM +0200, Alice Ryhl wrote:
> On Tue, Aug 20, 2024 at 4:35 PM Will Deacon <will@xxxxxxxxxx> wrote:
> > On Tue, Aug 06, 2024 at 10:01:44AM +0000, Alice Ryhl wrote:
> > > diff --git a/init/Kconfig b/init/Kconfig
> > > index fe76c5d0a72e..d857f6f90885 100644
> > > --- a/init/Kconfig
> > > +++ b/init/Kconfig
> > > @@ -1909,7 +1909,7 @@ config RUST
> > > depends on !MODVERSIONS
> > > depends on !GCC_PLUGINS
> > > depends on !RANDSTRUCT
> > > - depends on !SHADOW_CALL_STACK
> > > + depends on !SHADOW_CALL_STACK || RUSTC_VERSION >= 108000 && UNWIND_PATCH_PAC_INTO_SCS
> >
> > Sorry, I didn't spot this in v4, but since UNWIND_PATCH_PAC_INTO_SCS is
> > specific to arm64 and the only other architecture selecting
> > ARCH_SUPPORTS_SHADOW_CALL_STACK is riscv, I can't help but feel it would
> > be cleaner to move this logic into the arch code selecting HAVE_RUST.
> >
> > That is, it's up to the architecture to make sure that it has whatever
> > it needs for SCS to work with Rust if it claims to support Rust.
> >
> > What do you think?
>
> The `select RUST if ...` is going to get really complicated if we
> apply that rule in general. Having options here allows us to split
> them across several `depends on` clauses. I'm not sure it will even
> work, I had issues with cyclic Kconfig errors previously. I also don't
> think it's unreasonable for the architecture to say it supports both
> options when it really does support both; they are just mutually
> exclusive. I also think there is value in having all of the options
> that Rust doesn't work with in one place.

I'm not sure I follow why this will get really complicated. Isn't it as
straightforward as the diff below, or did I miss something?

Will

--->8

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index a2f8ff354ca6..2f5702cb9dac 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -231,7 +231,7 @@ config ARM64
select HAVE_FUNCTION_ARG_ACCESS_API
select MMU_GATHER_RCU_TABLE_FREE
select HAVE_RSEQ
- select HAVE_RUST if CPU_LITTLE_ENDIAN
+ select HAVE_RUST if RUSTC_SUPPORTS_ARM64
select HAVE_STACKPROTECTOR
select HAVE_SYSCALL_TRACEPOINTS
select HAVE_KPROBES
@@ -265,6 +265,11 @@ config ARM64
help
ARM 64-bit (AArch64) Linux support.

+config RUSTC_SUPPORTS_ARM64
+ bool
+ depends on CPU_LITTLE_ENDIAN
+ depends on !SHADOW_CALL_STACK || RUSTC_VERSION >= 108000 && UNWIND_PATCH_PAC_INTO_SC
+
config CLANG_SUPPORTS_DYNAMIC_FTRACE_WITH_ARGS
def_bool CC_IS_CLANG
# https://github.com/ClangBuiltLinux/linux/issues/1507
diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index 0f3cd7c3a436..93858dbfefc0 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -172,7 +172,7 @@ config RISCV
select HAVE_REGS_AND_STACK_ACCESS_API
select HAVE_RETHOOK if !XIP_KERNEL
select HAVE_RSEQ
- select HAVE_RUST if 64BIT
+ select HAVE_RUST if 64BIT && !SHADOW_CALL_STACK
select HAVE_SAMPLE_FTRACE_DIRECT
select HAVE_SAMPLE_FTRACE_DIRECT_MULTI
select HAVE_STACKPROTECTOR
diff --git a/init/Kconfig b/init/Kconfig
index 5783a0b87517..3ada33b1d681 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -1902,7 +1902,6 @@ config RUST
depends on !MODVERSIONS
depends on !GCC_PLUGINS
depends on !RANDSTRUCT
- depends on !SHADOW_CALL_STACK
depends on !DEBUG_INFO_BTF || PAHOLE_HAS_LANG_EXCLUDE
help
Enables Rust support in the kernel.