summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/x86/kernel/cpu/bugs.c29
-rw-r--r--include/linux/nospec.h2
-rw-r--r--kernel/seccomp.c15
3 files changed, 22 insertions, 24 deletions
diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index 7e0f28160e5e..5dab4c3d26e7 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -569,6 +569,24 @@ static int ssb_prctl_set(struct task_struct *task, unsigned long ctrl)
569 return 0; 569 return 0;
570} 570}
571 571
572int arch_prctl_spec_ctrl_set(struct task_struct *task, unsigned long which,
573 unsigned long ctrl)
574{
575 switch (which) {
576 case PR_SPEC_STORE_BYPASS:
577 return ssb_prctl_set(task, ctrl);
578 default:
579 return -ENODEV;
580 }
581}
582
583#ifdef CONFIG_SECCOMP
584void arch_seccomp_spec_mitigate(struct task_struct *task)
585{
586 ssb_prctl_set(task, PR_SPEC_FORCE_DISABLE);
587}
588#endif
589
572static int ssb_prctl_get(struct task_struct *task) 590static int ssb_prctl_get(struct task_struct *task)
573{ 591{
574 switch (ssb_mode) { 592 switch (ssb_mode) {
@@ -587,17 +605,6 @@ static int ssb_prctl_get(struct task_struct *task)
587 } 605 }
588} 606}
589 607
590int arch_prctl_spec_ctrl_set(struct task_struct *task, unsigned long which,
591 unsigned long ctrl)
592{
593 switch (which) {
594 case PR_SPEC_STORE_BYPASS:
595 return ssb_prctl_set(task, ctrl);
596 default:
597 return -ENODEV;
598 }
599}
600
601int arch_prctl_spec_ctrl_get(struct task_struct *task, unsigned long which) 608int arch_prctl_spec_ctrl_get(struct task_struct *task, unsigned long which)
602{ 609{
603 switch (which) { 610 switch (which) {
diff --git a/include/linux/nospec.h b/include/linux/nospec.h
index a908c954484d..0c5ef54fd416 100644
--- a/include/linux/nospec.h
+++ b/include/linux/nospec.h
@@ -62,5 +62,7 @@ static inline unsigned long array_index_mask_nospec(unsigned long index,
62int arch_prctl_spec_ctrl_get(struct task_struct *task, unsigned long which); 62int arch_prctl_spec_ctrl_get(struct task_struct *task, unsigned long which);
63int arch_prctl_spec_ctrl_set(struct task_struct *task, unsigned long which, 63int arch_prctl_spec_ctrl_set(struct task_struct *task, unsigned long which,
64 unsigned long ctrl); 64 unsigned long ctrl);
65/* Speculation control for seccomp enforced mitigation */
66void arch_seccomp_spec_mitigate(struct task_struct *task);
65 67
66#endif /* _LINUX_NOSPEC_H */ 68#endif /* _LINUX_NOSPEC_H */
diff --git a/kernel/seccomp.c b/kernel/seccomp.c
index 53eb946120c1..e691d9a6c58d 100644
--- a/kernel/seccomp.c
+++ b/kernel/seccomp.c
@@ -229,18 +229,7 @@ static inline bool seccomp_may_assign_mode(unsigned long seccomp_mode)
229 return true; 229 return true;
230} 230}
231 231
232/* 232void __weak arch_seccomp_spec_mitigate(struct task_struct *task) { }
233 * If a given speculation mitigation is opt-in (prctl()-controlled),
234 * select it, by disabling speculation (enabling mitigation).
235 */
236static inline void spec_mitigate(struct task_struct *task,
237 unsigned long which)
238{
239 int state = arch_prctl_spec_ctrl_get(task, which);
240
241 if (state > 0 && (state & PR_SPEC_PRCTL))
242 arch_prctl_spec_ctrl_set(task, which, PR_SPEC_FORCE_DISABLE);
243}
244 233
245static inline void seccomp_assign_mode(struct task_struct *task, 234static inline void seccomp_assign_mode(struct task_struct *task,
246 unsigned long seccomp_mode, 235 unsigned long seccomp_mode,
@@ -256,7 +245,7 @@ static inline void seccomp_assign_mode(struct task_struct *task,
256 smp_mb__before_atomic(); 245 smp_mb__before_atomic();
257 /* Assume default seccomp processes want spec flaw mitigation. */ 246 /* Assume default seccomp processes want spec flaw mitigation. */
258 if ((flags & SECCOMP_FILTER_FLAG_SPEC_ALLOW) == 0) 247 if ((flags & SECCOMP_FILTER_FLAG_SPEC_ALLOW) == 0)
259 spec_mitigate(task, PR_SPEC_STORE_BYPASS); 248 arch_seccomp_spec_mitigate(task);
260 set_tsk_thread_flag(task, TIF_SECCOMP); 249 set_tsk_thread_flag(task, TIF_SECCOMP);
261} 250}
262 251