Skip to content

Commit 2bd3d9c

Browse files
KAGA-KOKOkonradwilk
authored andcommitted
seccomp: Move speculation migitation control to arch code
The migitation control is simpler to implement in architecture code as it avoids the extra function call to check the mode. Aside of that having an explicit seccomp enabled mode in the architecture mitigations would require even more workarounds. Move it into architecture code and provide a weak function in the seccomp code. Remove the 'which' argument as this allows the architecture to decide which mitigations are relevant for seccomp. Signed-off-by: Thomas Gleixner <[email protected]> (cherry picked from commit 8bf37d8) Orabug: 28034177 CVE: CVE-2018-3639 Signed-off-by: Konrad Rzeszutek Wilk <[email protected]> Tested-by: Mihai Carabas <[email protected]> Reviewed-by: Mihai Carabas <[email protected]> Reviewed-by: John Haxby <[email protected]>
1 parent 576def0 commit 2bd3d9c

File tree

3 files changed

+22
-24
lines changed

3 files changed

+22
-24
lines changed

arch/x86/kernel/cpu/bugs.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,24 @@ static int ssb_prctl_set(struct task_struct *task, unsigned long ctrl)
850850
return 0;
851851
}
852852

853+
int arch_prctl_spec_ctrl_set(struct task_struct *task, unsigned long which,
854+
unsigned long ctrl)
855+
{
856+
switch (which) {
857+
case PR_SPEC_STORE_BYPASS:
858+
return ssb_prctl_set(task, ctrl);
859+
default:
860+
return -ENODEV;
861+
}
862+
}
863+
864+
#ifdef CONFIG_SECCOMP
865+
void arch_seccomp_spec_mitigate(struct task_struct *task)
866+
{
867+
ssb_prctl_set(task, PR_SPEC_FORCE_DISABLE);
868+
}
869+
#endif
870+
853871
static int ssb_prctl_get(struct task_struct *task)
854872
{
855873
switch (ssb_mode) {
@@ -869,17 +887,6 @@ static int ssb_prctl_get(struct task_struct *task)
869887
}
870888
}
871889

872-
int arch_prctl_spec_ctrl_set(struct task_struct *task, unsigned long which,
873-
unsigned long ctrl)
874-
{
875-
switch (which) {
876-
case PR_SPEC_STORE_BYPASS:
877-
return ssb_prctl_set(task, ctrl);
878-
default:
879-
return -ENODEV;
880-
}
881-
}
882-
883890
int arch_prctl_spec_ctrl_get(struct task_struct *task, unsigned long which)
884891
{
885892
switch (which) {

include/linux/nospec.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,7 @@ static inline unsigned long array_index_mask_nospec(unsigned long index,
6262
int arch_prctl_spec_ctrl_get(struct task_struct *task, unsigned long which);
6363
int arch_prctl_spec_ctrl_set(struct task_struct *task, unsigned long which,
6464
unsigned long ctrl);
65+
/* Speculation control for seccomp enforced mitigation */
66+
void arch_seccomp_spec_mitigate(struct task_struct *task);
6567

6668
#endif /* _LINUX_NOSPEC_H */

kernel/seccomp.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -229,18 +229,7 @@ static inline bool seccomp_may_assign_mode(unsigned long seccomp_mode)
229229
return true;
230230
}
231231

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_FORCE_DISABLE);
243-
}
232+
void __weak arch_seccomp_spec_mitigate(struct task_struct *task) { }
244233

245234
static inline void seccomp_assign_mode(struct task_struct *task,
246235
unsigned long seccomp_mode,
@@ -256,7 +245,7 @@ static inline void seccomp_assign_mode(struct task_struct *task,
256245
smp_mb__before_atomic();
257246
/* Assume default seccomp processes want spec flaw mitigation. */
258247
if ((flags & SECCOMP_FILTER_FLAG_SPEC_ALLOW) == 0)
259-
spec_mitigate(task, PR_SPEC_STORE_BYPASS);
248+
arch_seccomp_spec_mitigate(task);
260249
set_tsk_thread_flag(task, TIF_SECCOMP);
261250
}
262251

0 commit comments

Comments
 (0)