Skip to content

Commit 5c30708

Browse files
keesKAGA-KOKO
authored andcommitted
seccomp: Enable speculation flaw mitigations
When speculation flaw mitigations are opt-in (via prctl), using seccomp will automatically opt-in to these protections, since using seccomp indicates at least some level of sandboxing is desired. Signed-off-by: Kees Cook <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]>
1 parent fae1fa0 commit 5c30708

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

kernel/seccomp.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include <linux/compat.h>
2020
#include <linux/coredump.h>
2121
#include <linux/kmemleak.h>
22+
#include <linux/nospec.h>
23+
#include <linux/prctl.h>
2224
#include <linux/sched.h>
2325
#include <linux/sched/task_stack.h>
2426
#include <linux/seccomp.h>
@@ -227,6 +229,19 @@ static inline bool seccomp_may_assign_mode(unsigned long seccomp_mode)
227229
return true;
228230
}
229231

232+
/*
233+
* If a given speculation mitigation is opt-in (prctl()-controlled),
234+
* select it, by disabling speculation (enabling mitigation).
235+
*/
236+
static 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_DISABLE);
243+
}
244+
230245
static inline void seccomp_assign_mode(struct task_struct *task,
231246
unsigned long seccomp_mode)
232247
{
@@ -238,6 +253,8 @@ static inline void seccomp_assign_mode(struct task_struct *task,
238253
* filter) is set.
239254
*/
240255
smp_mb__before_atomic();
256+
/* Assume seccomp processes want speculation flaw mitigation. */
257+
spec_mitigate(task, PR_SPEC_STORE_BYPASS);
241258
set_tsk_thread_flag(task, TIF_SECCOMP);
242259
}
243260

0 commit comments

Comments
 (0)