[RFC PATCH] riscv/usercfi: fix shadow stack locking argument

From: Bill Roberts

Date: Tue Sep 15 2026 - 15:11:48 EST


The API for arch_lock_shadow_stack_status, is that the argument contains
the feature bits one wants to lock, including support for unknown bits.

The API was documented in:
commit 91e102e79740 ("prctl: arch-agnostic prctl for shadow stack")

The current code expected the argument to be 0. That would mean nothing
is locked. Note that glibc has not merged the riscv support yet,
so now would be the time to correct this behavior.

See the patch series in question for glibc here:
Link: https://inbox.sourceware.org/libc-alpha/af2bbbac-5421-4b7c-af4b-4feb84b87629@xxxxxxxxxxxx/

Signed-off-by: Bill Roberts <bill.roberts@xxxxxxx>
---
RFC Notes:
I ONLY compile tested this. This was meant to strike up a conversation
on this before it gets baked into the kernel forever. Right now, seems
like the time to change that.


arch/riscv/kernel/usercfi.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/riscv/kernel/usercfi.c b/arch/riscv/kernel/usercfi.c
index f027e6e05251..a688e3b942a8 100644
--- a/arch/riscv/kernel/usercfi.c
+++ b/arch/riscv/kernel/usercfi.c
@@ -440,10 +440,12 @@ int arch_lock_shadow_stack_status(struct task_struct *task,
{
/* If shtstk not supported or not enabled on task, nothing to lock here */
if (!is_user_shstk_enabled() ||
- !is_shstk_enabled(task) || arg != 0)
+ !is_shstk_enabled(task))
return -EINVAL;

- set_shstk_lock(task, true);
+ /* transparently handle unknown bits, this is part of the API */
+ if (arg & PR_SHADOW_STACK_ENABLE)
+ set_shstk_lock(task, true);

return 0;
}
--
2.55.0