summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorKees Cook <keescook@chromium.org>2018-05-01 15:07:31 -0700
committerBen Hutchings <ben@decadent.org.uk>2018-10-03 04:09:42 +0100
commit284aa1550489336c3e5fd7b7ea3269b6ad96fe01 (patch)
tree198509ac498a5ada8b604a098b25914f03bc28d6 /kernel
parentc0f77718114bfdc56711dbaa411825839b7a190e (diff)
downloadlinux-284aa1550489336c3e5fd7b7ea3269b6ad96fe01.tar.gz
linux-284aa1550489336c3e5fd7b7ea3269b6ad96fe01.tar.bz2
linux-284aa1550489336c3e5fd7b7ea3269b6ad96fe01.zip
seccomp: Enable speculation flaw mitigations
commit 5c3070890d06ff82eecb808d02d2ca39169533ef upstream. 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 <keescook@chromium.org> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> [bwh: Backported to 3.16: - Apply to current task - Adjust context] Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/seccomp.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/kernel/seccomp.c b/kernel/seccomp.c
index d2596136b0d1..816cdfe9b592 100644
--- a/kernel/seccomp.c
+++ b/kernel/seccomp.c
@@ -16,6 +16,8 @@
#include <linux/atomic.h>
#include <linux/audit.h>
#include <linux/compat.h>
+#include <linux/nospec.h>
+#include <linux/prctl.h>
#include <linux/sched.h>
#include <linux/seccomp.h>
#include <linux/syscalls.h>
@@ -205,9 +207,24 @@ 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(unsigned long seccomp_mode)
{
current->seccomp.mode = seccomp_mode;
+ /* Assume seccomp processes want speculation flaw mitigation. */
+ spec_mitigate(current, PR_SPEC_STORE_BYPASS);
set_tsk_thread_flag(current, TIF_SECCOMP);
}