summaryrefslogtreecommitdiff
path: root/arch/riscv
diff options
context:
space:
mode:
authorPaul Walmsley <pjw@kernel.org>2026-04-04 18:40:58 -0600
committerPaul Walmsley <pjw@kernel.org>2026-04-04 18:40:58 -0600
commit08ee1559052be302f1d3752f48360b89517d9f8d (patch)
tree75318cdfd654c53621e9e75e7b429877acc556ad /arch/riscv
parente5342fe2c1bb5b4fab6ed531a0122c6417e57ecf (diff)
downloadlwn-08ee1559052be302f1d3752f48360b89517d9f8d.tar.gz
lwn-08ee1559052be302f1d3752f48360b89517d9f8d.zip
prctl: cfi: change the branch landing pad prctl()s to be more descriptive
Per Linus' comments requesting the replacement of "INDIR_BR_LP" in the indirect branch tracking prctl()s with something more readable, and suggesting the use of the speculation control prctl()s as an exemplar, reimplement the prctl()s and related constants that control per-task forward-edge control flow integrity. This primarily involves two changes. First, the prctls are restructured to resemble the style of the speculative execution workaround control prctls PR_{GET,SET}_SPECULATION_CTRL, to make them easier to extend in the future. Second, the "indir_br_lp" abbrevation is expanded to "branch_landing_pads" to be less telegraphic. The kselftest and documentation is adjusted accordingly. Link: https://lore.kernel.org/linux-riscv/CAHk-=whhSLGZAx3N5jJpb4GLFDqH_QvS07D+6BnkPWmCEzTAgw@mail.gmail.com/ Cc: Deepak Gupta <debug@rivosinc.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Mark Brown <broonie@kernel.org> Signed-off-by: Paul Walmsley <pjw@kernel.org>
Diffstat (limited to 'arch/riscv')
-rw-r--r--arch/riscv/kernel/usercfi.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/arch/riscv/kernel/usercfi.c b/arch/riscv/kernel/usercfi.c
index 04ab1eb8df29..2c535737511d 100644
--- a/arch/riscv/kernel/usercfi.c
+++ b/arch/riscv/kernel/usercfi.c
@@ -465,16 +465,14 @@ int arch_prctl_get_branch_landing_pad_state(struct task_struct *t,
if (!is_user_lpad_enabled())
return -EINVAL;
- /* indirect branch tracking is enabled on the task or not */
- fcfi_status |= (is_indir_lp_enabled(t) ? PR_INDIR_BR_LP_ENABLE : 0);
+ fcfi_status = (is_indir_lp_enabled(t) ? PR_CFI_ENABLE : PR_CFI_DISABLE);
+ fcfi_status |= (is_indir_lp_locked(t) ? PR_CFI_LOCK : 0);
return copy_to_user(state, &fcfi_status, sizeof(fcfi_status)) ? -EFAULT : 0;
}
int arch_prctl_set_branch_landing_pad_state(struct task_struct *t, unsigned long state)
{
- bool enable_indir_lp = false;
-
if (!is_user_lpad_enabled())
return -EINVAL;
@@ -482,12 +480,13 @@ int arch_prctl_set_branch_landing_pad_state(struct task_struct *t, unsigned long
if (is_indir_lp_locked(t))
return -EINVAL;
- /* Reject unknown flags */
- if (state & ~PR_INDIR_BR_LP_ENABLE)
+ if (!(state & (PR_CFI_ENABLE | PR_CFI_DISABLE)))
+ return -EINVAL;
+
+ if (state & PR_CFI_ENABLE && state & PR_CFI_DISABLE)
return -EINVAL;
- enable_indir_lp = (state & PR_INDIR_BR_LP_ENABLE);
- set_indir_lp_status(t, enable_indir_lp);
+ set_indir_lp_status(t, !!(state & PR_CFI_ENABLE));
return 0;
}