Return-path: Received: from mta.outflux.net ([2001:19d0:2:6:c0de:0:736d:7471] helo=smtp.outflux.net) by Galois.linutronix.de with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1fDetz-0007zJ-8N for speck@linutronix.de; Wed, 02 May 2018 01:41:43 +0200 Received: from www.outflux.net (serenity.outflux.net [10.2.0.2]) by vinyl.outflux.net (8.15.2/8.15.2/Debian-3) with ESMTP id w41NfZqA024623 for ; Tue, 1 May 2018 16:41:36 -0700 Date: Tue, 1 May 2018 16:41:35 -0700 From: Kees Cook Subject: [MODERATED] [PATCH SSBv9 3/3] seccomp Message-ID: <20180501234135.GE32640@outflux.net> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit To: speck@linutronix.de List-ID: From: Kees Cook 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. Signed-off-by: Kees Cook --- kernel/seccomp.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/kernel/seccomp.c b/kernel/seccomp.c index dc77548167ef..22a0d3d56580 100644 --- a/kernel/seccomp.c +++ b/kernel/seccomp.c @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include #include #include @@ -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 -- 2.7.4 -- Kees Cook @outflux.net