From: Kees Cook Date: Tue, 1 May 2018 22:07:31 +0000 (-0700) Subject: seccomp: Enable speculation flaw mitigations X-Git-Tag: Ubuntu-4.13.0-43.48~32 X-Git-Url: https://git.proxmox.com/?p=mirror_ubuntu-artful-kernel.git;a=commitdiff_plain;h=7d85e158712ca8ed70206c893c49b501ff24c4a2 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 Signed-off-by: Thomas Gleixner CVE-2018-3639 (x86) Signed-off-by: Tyler Hicks Signed-off-by: Stefan Bader --- diff --git a/kernel/seccomp.c b/kernel/seccomp.c index 3fd2c4b23697..cb1e2fb77ca1 100644 --- a/kernel/seccomp.c +++ b/kernel/seccomp.c @@ -18,6 +18,8 @@ #include #include #include +#include +#include #include #include #include @@ -225,6 +227,19 @@ static inline bool seccomp_may_assign_mode(unsigned long seccomp_mode) return true; } +/* + * If a given speculation mitigation is opt-in (prctl()-controlled), + * select it, by disabling speculation (enabling mitigation). + */ +static inline void spec_mitigate(struct task_struct *task, + unsigned long which) +{ + int state = arch_prctl_spec_ctrl_get(task, which); + + if (state > 0 && (state & PR_SPEC_PRCTL)) + arch_prctl_spec_ctrl_set(task, which, PR_SPEC_DISABLE); +} + static inline void seccomp_assign_mode(struct task_struct *task, unsigned long seccomp_mode) { @@ -236,6 +251,8 @@ static inline void seccomp_assign_mode(struct task_struct *task, * filter) is set. */ smp_mb__before_atomic(); + /* Assume seccomp processes want speculation flaw mitigation. */ + spec_mitigate(task, PR_SPEC_STORE_BYPASS); set_tsk_thread_flag(task, TIF_SECCOMP); }