diff mbox series

[29/33] riscv: kernel command line option to opt out of user cfi

Message ID 20241001-v5_user_cfi_series-v1-29-3ba65b6e550f@rivosinc.com (mailing list archive)
State New
Headers show
Series riscv control-flow integrity for usermode | expand

Checks

Context Check Description
conchuod/vmtest-fixes-PR fail PR summary
conchuod/patch-29-test-1 success .github/scripts/patches/tests/build_rv32_defconfig.sh took 99.07s
conchuod/patch-29-test-2 success .github/scripts/patches/tests/build_rv64_clang_allmodconfig.sh took 925.48s
conchuod/patch-29-test-3 success .github/scripts/patches/tests/build_rv64_gcc_allmodconfig.sh took 1110.36s
conchuod/patch-29-test-4 fail .github/scripts/patches/tests/build_rv64_nommu_k210_defconfig.sh took 4.18s
conchuod/patch-29-test-5 fail .github/scripts/patches/tests/build_rv64_nommu_virt_defconfig.sh took 4.22s
conchuod/patch-29-test-6 warning .github/scripts/patches/tests/checkpatch.sh took 0.36s
conchuod/patch-29-test-7 success .github/scripts/patches/tests/dtb_warn_rv64.sh took 34.92s
conchuod/patch-29-test-8 success .github/scripts/patches/tests/header_inline.sh took 0.00s
conchuod/patch-29-test-9 success .github/scripts/patches/tests/kdoc.sh took 0.48s
conchuod/patch-29-test-10 success .github/scripts/patches/tests/module_param.sh took 0.01s
conchuod/patch-29-test-11 success .github/scripts/patches/tests/verify_fixes.sh took 0.00s
conchuod/patch-29-test-12 success .github/scripts/patches/tests/verify_signedoff.sh took 0.02s

Commit Message

Deepak Gupta Oct. 1, 2024, 4:06 p.m. UTC
This commit adds a kernel command line option using which user cfi can be
disabled.

Signed-off-by: Deepak Gupta <debug@rivosinc.com>
---
 arch/riscv/kernel/usercfi.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
diff mbox series

Patch

diff --git a/arch/riscv/kernel/usercfi.c b/arch/riscv/kernel/usercfi.c
index 40c32258b6ec..d92b49261b58 100644
--- a/arch/riscv/kernel/usercfi.c
+++ b/arch/riscv/kernel/usercfi.c
@@ -17,6 +17,8 @@ 
 #include <asm/csr.h>
 #include <asm/usercfi.h>
 
+bool disable_riscv_usercfi;
+
 #define SHSTK_ENTRY_SIZE sizeof(void *)
 
 bool is_shstk_enabled(struct task_struct *task)
@@ -393,6 +395,9 @@  int arch_set_shadow_stack_status(struct task_struct *t, unsigned long status)
 	unsigned long size = 0, addr = 0;
 	bool enable_shstk = false;
 
+	if (disable_riscv_usercfi)
+		return 0;
+
 	if (!cpu_supports_shadow_stack())
 		return -EINVAL;
 
@@ -472,6 +477,9 @@  int arch_set_indir_br_lp_status(struct task_struct *t, unsigned long status)
 {
 	bool enable_indir_lp = false;
 
+	if (disable_riscv_usercfi)
+		return 0;
+
 	if (!cpu_supports_indirect_br_lp_instr())
 		return -EINVAL;
 
@@ -504,3 +512,15 @@  int arch_lock_indir_br_lp_status(struct task_struct *task,
 
 	return 0;
 }
+
+static int __init setup_global_riscv_enable(char *str)
+{
+	if (strcmp(str, "true") == 0)
+		disable_riscv_usercfi = true;
+
+	pr_info("Setting riscv usercfi to be %s\n", (disable_riscv_usercfi ? "disabled" : "enabled"));
+
+	return 1;
+}
+
+__setup("disable_riscv_usercfi=", setup_global_riscv_enable);