[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aCdWueNaGeru4CRW@debug.ba.rivosinc.com>
Date: Fri, 16 May 2025 08:16:09 -0700
From: Deepak Gupta <debug@...osinc.com>
To: Alexandre Ghiti <alex@...ti.fr>
Cc: Thomas Gleixner <tglx@...utronix.de>, Ingo Molnar <mingo@...hat.com>,
Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>, x86@...nel.org,
"H. Peter Anvin" <hpa@...or.com>,
Andrew Morton <akpm@...ux-foundation.org>,
"Liam R. Howlett" <Liam.Howlett@...cle.com>,
Vlastimil Babka <vbabka@...e.cz>,
Lorenzo Stoakes <lorenzo.stoakes@...cle.com>,
Paul Walmsley <paul.walmsley@...ive.com>,
Palmer Dabbelt <palmer@...belt.com>,
Albert Ou <aou@...s.berkeley.edu>, Conor Dooley <conor@...nel.org>,
Rob Herring <robh@...nel.org>,
Krzysztof Kozlowski <krzk+dt@...nel.org>,
Arnd Bergmann <arnd@...db.de>,
Christian Brauner <brauner@...nel.org>,
Peter Zijlstra <peterz@...radead.org>,
Oleg Nesterov <oleg@...hat.com>,
Eric Biederman <ebiederm@...ssion.com>, Kees Cook <kees@...nel.org>,
Jonathan Corbet <corbet@....net>, Shuah Khan <shuah@...nel.org>,
Jann Horn <jannh@...gle.com>, Conor Dooley <conor+dt@...nel.org>,
Miguel Ojeda <ojeda@...nel.org>,
Alex Gaynor <alex.gaynor@...il.com>,
Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <benno.lossin@...ton.me>,
Andreas Hindborg <a.hindborg@...nel.org>,
Alice Ryhl <aliceryhl@...gle.com>, Trevor Gross <tmgross@...ch.edu>,
linux-kernel@...r.kernel.org, linux-fsdevel@...r.kernel.org,
linux-mm@...ck.org, linux-riscv@...ts.infradead.org,
devicetree@...r.kernel.org, linux-arch@...r.kernel.org,
linux-doc@...r.kernel.org, linux-kselftest@...r.kernel.org,
alistair.francis@....com, richard.henderson@...aro.org,
jim.shu@...ive.com, andybnac@...il.com, kito.cheng@...ive.com,
charlie@...osinc.com, atishp@...osinc.com, evan@...osinc.com,
cleger@...osinc.com, alexghiti@...osinc.com,
samitolvanen@...gle.com, broonie@...nel.org,
rick.p.edgecombe@...el.com, rust-for-linux@...r.kernel.org,
Zong Li <zong.li@...ive.com>
Subject: Re: [PATCH v15 22/27] riscv: enable kernel access to shadow stack
memory via FWFT sbi call
On Thu, May 15, 2025 at 09:10:08AM +0200, Alexandre Ghiti wrote:
>Hi Deepak,
>
>On 03/05/2025 01:30, Deepak Gupta wrote:
>>Kernel will have to perform shadow stack operations on user shadow stack.
>>Like during signal delivery and sigreturn, shadow stack token must be
>>created and validated respectively. Thus shadow stack access for kernel
>>must be enabled.
>>
>>In future when kernel shadow stacks are enabled for linux kernel, it must
>>be enabled as early as possible for better coverage and prevent imbalance
>>between regular stack and shadow stack. After `relocate_enable_mmu` has
>>been done, this is as early as possible it can enabled.
>>
>>Reviewed-by: Zong Li <zong.li@...ive.com>
>>Signed-off-by: Deepak Gupta <debug@...osinc.com>
>>---
>> arch/riscv/kernel/asm-offsets.c | 4 ++++
>> arch/riscv/kernel/head.S | 27 +++++++++++++++++++++++++++
>> 2 files changed, 31 insertions(+)
>>
>>diff --git a/arch/riscv/kernel/asm-offsets.c b/arch/riscv/kernel/asm-offsets.c
>>index f33945432f8f..7ab41f01aa17 100644
>>--- a/arch/riscv/kernel/asm-offsets.c
>>+++ b/arch/riscv/kernel/asm-offsets.c
>>@@ -514,4 +514,8 @@ void asm_offsets(void)
>> DEFINE(FREGS_A6, offsetof(struct __arch_ftrace_regs, a6));
>> DEFINE(FREGS_A7, offsetof(struct __arch_ftrace_regs, a7));
>> #endif
>>+ DEFINE(SBI_EXT_FWFT, SBI_EXT_FWFT);
>>+ DEFINE(SBI_EXT_FWFT_SET, SBI_EXT_FWFT_SET);
>>+ DEFINE(SBI_FWFT_SHADOW_STACK, SBI_FWFT_SHADOW_STACK);
>>+ DEFINE(SBI_FWFT_SET_FLAG_LOCK, SBI_FWFT_SET_FLAG_LOCK);
>
>
>kernel test robot reported errors when !RV64 and !SBI, the following
>diff fixes it:
>
>diff --git a/arch/riscv/kernel/asm-offsets.c
>b/arch/riscv/kernel/asm-offsets.c
>index 7fc085d27ca79..3aa5f56a84e9a 100644
>--- a/arch/riscv/kernel/asm-offsets.c
>+++ b/arch/riscv/kernel/asm-offsets.c
>@@ -532,8 +532,10 @@ void asm_offsets(void)
> DEFINE(FREGS_A6, offsetof(struct
>__arch_ftrace_regs, a6));
> DEFINE(FREGS_A7, offsetof(struct
>__arch_ftrace_regs, a7));
> #endif
>+#ifdef CONFIG_RISCV_SBI
> DEFINE(SBI_EXT_FWFT, SBI_EXT_FWFT);
> DEFINE(SBI_EXT_FWFT_SET, SBI_EXT_FWFT_SET);
> DEFINE(SBI_FWFT_SHADOW_STACK, SBI_FWFT_SHADOW_STACK);
> DEFINE(SBI_FWFT_SET_FLAG_LOCK, SBI_FWFT_SET_FLAG_LOCK);
>+#endif
> }
>
>No need to resend the whole series, I'll squash it.
Thanks.
>
>Thanks,
>
>Alex
>
>
>> }
>>diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S
>>index 356d5397b2a2..7eae9a172351 100644
>>--- a/arch/riscv/kernel/head.S
>>+++ b/arch/riscv/kernel/head.S
>>@@ -15,6 +15,7 @@
>> #include <asm/image.h>
>> #include <asm/scs.h>
>> #include <asm/xip_fixup.h>
>>+#include <asm/usercfi.h>
>> #include "efi-header.S"
>> __HEAD
>>@@ -164,6 +165,19 @@ secondary_start_sbi:
>> call relocate_enable_mmu
>> #endif
>> call .Lsetup_trap_vector
>>+#if defined(CONFIG_RISCV_SBI) && defined(CONFIG_RISCV_USER_CFI)
>>+ li a7, SBI_EXT_FWFT
>>+ li a6, SBI_EXT_FWFT_SET
>>+ li a0, SBI_FWFT_SHADOW_STACK
>>+ li a1, 1 /* enable supervisor to access shadow stack access */
>>+ li a2, SBI_FWFT_SET_FLAG_LOCK
>>+ ecall
>>+ beqz a0, 1f
>>+ la a1, riscv_nousercfi
>>+ li a0, CMDLINE_DISABLE_RISCV_USERCFI_BCFI
>>+ REG_S a0, (a1)
>>+1:
>>+#endif
>> scs_load_current
>> call smp_callin
>> #endif /* CONFIG_SMP */
>>@@ -320,6 +334,19 @@ SYM_CODE_START(_start_kernel)
>> la tp, init_task
>> la sp, init_thread_union + THREAD_SIZE
>> addi sp, sp, -PT_SIZE_ON_STACK
>>+#if defined(CONFIG_RISCV_SBI) && defined(CONFIG_RISCV_USER_CFI)
>>+ li a7, SBI_EXT_FWFT
>>+ li a6, SBI_EXT_FWFT_SET
>>+ li a0, SBI_FWFT_SHADOW_STACK
>>+ li a1, 1 /* enable supervisor to access shadow stack access */
>>+ li a2, SBI_FWFT_SET_FLAG_LOCK
>>+ ecall
>>+ beqz a0, 1f
>>+ la a1, riscv_nousercfi
>>+ li a0, CMDLINE_DISABLE_RISCV_USERCFI_BCFI
>>+ REG_S a0, (a1)
>>+1:
>>+#endif
>> scs_load_current
>> #ifdef CONFIG_KASAN
>>
Powered by blists - more mailing lists