seccomp
PATCH 3/3 seccomp
From: Kees Cook <[email protected]>
Subject: [PATCH SSBv9 seccomp 3/3] 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.
--- kernel/seccomp.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
kernel/seccomp.c +13 -0
@@ -19,6 +19,8 @@#include <linux/compat.h> #include <linux/coredump.h> #include <linux/kmemleak.h> +#include <linux/nospec.h> +#include <linux/prctl.h> #include <linux/sched.h> #include <linux/sched/task_stack.h> #include <linux/seccomp.h>
@@ -227,6 +229,14 @@ static inline bool seccomp_may_assign_mode(unsigned long seccomp_mode)return true; } +#define SPEC_MITIGATE (task, which) \ +do { \ + int state = arch_prctl_get_spec_ctrl(task, PR_SPEC_ ## which); \ + if (state > 0 && (state & SPEC_ ## which ## _PRCTL)) \ + arch_prctl_set_spec_ctrl(task, PR_SPEC_ ## which, \ + PR_SPEC_DISABLE); \ +} while (0) +static inline void seccomp_assign_mode (struct task_struct *task,unsigned long seccomp_mode) {
@@ -239,6 +249,9 @@ static inline void seccomp_assign_mode(struct task_struct *task,*/ smp_mb__before_atomic ();set_tsk_thread_flag (task,TIF_SECCOMP ); + +/* Make sure opt-in speculation mitigations are enabled. */ +SPEC_MITIGATE (task,STORE_BYPASS ); }#ifdef CONFIG_SECCOMP_FILTER
Signature · 5 lines
2.7.4 -- Kees Cook @outflux.net
Quoted 2 lines · speck for Kees Cook
+#define
SPEC_MITIGATE(task, which)\
Is it really helpful to spare the PR_SPEC_ prefix on the call site?
Really not...
kernel/seccomp.c static inline bool seccomp_may_assign_mode(unsigned long seccomp_mode) · line 235
Quoted 3 lines
kernel/seccomp.c +3
-0+do { \ + int state = arch_prctl_get_spec_ctrl(task, PR_SPEC_ ## which); \ + if (state > 0 && (state & SPEC_ ## which ## _PRCTL)) \
Also the condition is wrong. This expands to
SPEC_STORE_BYPASS_PRCTL
which is not the arch_prctl_get_spec_ctrl() return value. It's the x86 internal mode.
kernel/seccomp.c static inline bool seccomp_may_assign_mode(unsigned long seccomp_mode) · line 238
Quoted 3 lines
kernel/seccomp.c +3
-0+ arch_prctl_set_spec_ctrl(task, PR_SPEC_ ## which, \ +PR_SPEC_DISABLE ); \ +}while (0 )
static inline void spec_mitigate(struct task_struct *tsk, unsigned long which)
{
int state = arch_prctl_get_spec_ctrl(tsk, which);
if (state > 0 && (state & PR_SPEC_PRCTL))
arch_prctl_set_spec_ctrl(tsk, which, PR_SPEC_DISABLE);
}That's readable and actually does what it should do.
Hmm?
tglx
Quoted 7 lines · speck for Kees Cook
From: Kees Cook <[email protected]>
Subject: [PATCH SSBv9 seccomp 3/3] seccomp: Enable speculation flaw
mitigationsWhen 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.
Hi Kees,
We had this in our original patches. But after some discussion with various people we decided it's actually not a good idea and a separate prctl is better.
- For web browsers which use seccomp today the right fix is to use site isolation, so they don't need this and it would
be overkill and slow them down unnecessarily.
- Applications have to be maintained for security problems (otherwise they will have lots of other problems, like variant 1), so adding the extra prctl after a proper security shouldn't be that big a burden.
- The extra prctl is needed anyways because it's quite a bit of work to enable seccomp for an application, and also forbids execing any suid tasks.
-Andi
Quoted 9 lines · speck for Andi Kleen
Quoted 7 lines · speck for Kees Cook
From: Kees Cook <[email protected]>
Subject: [PATCH SSBv9 seccomp 3/3] seccomp: Enable speculation flaw
mitigationsWhen 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.
Quoted 5 lines
Hi Kees,
We had this in our original patches. But after some discussion with various people we decided it's actually not a good idea and a separate prctl is better.
Right, I'm not suggesting removing the separate prctl. I'm suggesting adding another path to opt into protection. I really don't like that we're doing a completely new interface that software has to opt into. I understand (and mostly agree with) the rationales for doing it this way instead of the "auto" mode, so I'm not opposed "prctl" as the default, but I feel like we could do _something_ smarter. The class of applications that wants this protection overlaps best with seccomp (though, it's not perfect).
Quoted 3 lines
- For web browsers which use seccomp today the right fix is to use site isolation, so they don't need this and it would
be overkill and slow them down unnecessarily.
Right. AIUI, SpectreV1 provides easier primitives anyway, so site isolation is already the way forward for this, and is already rolled out in most (all?) browsers. As for slowing them down, they could just as easily choose to use the new prctl() to turn OFF mitigation. :)
Quoted 4 lines
- Applications have to be maintained for security problems (otherwise they will have lots of other problems, like variant 1), so adding the extra prctl after a proper security shouldn't be that big a burden.
Sure, but it's the coordination of the roll-out that makes me uncomfortable. The application developers will find out about the prctl after the attack goes public, which leaves a window of attack open (and dependent on the release schedules of various organizations, etc). I think we can do better. If we at least attach it to seccomp, then rolling out a new kernel is all that is needed for a large portion of the concerned applications. Similarly, there tends to already exist tooling to turn on seccomp for various process launchers, etc. Nothing I'm aware of lets an admin run an arbitrary prctl().
So for admins that are already using containers with seccomp, they are immediately covered (after kernel updates) and can sort out what needs doing in a relaxed way instead of having their hair on fire beyond doing the kernel update. And admins NOT using a container for their untrusted-input-running-application (for shame) can immediately add a simple seccomp filter (e.g. adding a single line to a systemd service file) can gain the protection without having to figure out how to write a prctl()-setting launcher, etc etc.
Quoted 3 lines
- The extra prctl is needed anyways because it's quite a bit of work to enable seccomp for an application, and also forbids execing any suid tasks.
Yup, totally agreed: we still need the prctl(). I just want to have a better answer than "I hope your software gets updated quickly LOL".
-Kees
Signature · 1 line
Kees Cook @outflux.net