Skip to content

Commit edaed16

Browse files
committed
Merge branch 'x86-pti-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86/pti update from Thomas Gleixner: "Just a single change from the anti-performance departement: - Add a new PR_SPEC_DISABLE_NOEXEC option which allows to apply the speculation protections on a process without inheriting the state on exec. This remedies a situation where a Java-launcher has speculation protections enabled because that's the default for JVMs which causes the launched regular harmless processes to inherit the protection state which results in unintended performance degradation" * 'x86-pti-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/speculation: Add PR_SPEC_DISABLE_NOEXEC
2 parents 78f8601 + 71368af commit edaed16

6 files changed

Lines changed: 46 additions & 12 deletions

File tree

‎Documentation/userspace-api/spec_ctrl.rst‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,20 @@ PR_GET_SPECULATION_CTRL returns the state of the speculation misfeature
2828
which is selected with arg2 of prctl(2). The return value uses bits 0-3 with
2929
the following meaning:
3030

31-
==== ===================== ===================================================
32-
Bit Define Description
33-
==== ===================== ===================================================
34-
0 PR_SPEC_PRCTL Mitigation can be controlled per task by
35-
PR_SET_SPECULATION_CTRL.
36-
1 PR_SPEC_ENABLE The speculation feature is enabled, mitigation is
37-
disabled.
38-
2 PR_SPEC_DISABLE The speculation feature is disabled, mitigation is
39-
enabled.
40-
3 PR_SPEC_FORCE_DISABLE Same as PR_SPEC_DISABLE, but cannot be undone. A
41-
subsequent prctl(..., PR_SPEC_ENABLE) will fail.
42-
==== ===================== ===================================================
31+
==== ====================== ==================================================
32+
Bit Define Description
33+
==== ====================== ==================================================
34+
0 PR_SPEC_PRCTL Mitigation can be controlled per task by
35+
PR_SET_SPECULATION_CTRL.
36+
1 PR_SPEC_ENABLE The speculation feature is enabled, mitigation is
37+
disabled.
38+
2 PR_SPEC_DISABLE The speculation feature is disabled, mitigation is
39+
enabled.
40+
3 PR_SPEC_FORCE_DISABLE Same as PR_SPEC_DISABLE, but cannot be undone. A
41+
subsequent prctl(..., PR_SPEC_ENABLE) will fail.
42+
4 PR_SPEC_DISABLE_NOEXEC Same as PR_SPEC_DISABLE, but the state will be
43+
cleared on :manpage:`execve(2)`.
44+
==== ====================== ==================================================
4345

4446
If all bits are 0 the CPU is not affected by the speculation misfeature.
4547

@@ -92,6 +94,7 @@ Speculation misfeature controls
9294
* prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_STORE_BYPASS, PR_SPEC_ENABLE, 0, 0);
9395
* prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_STORE_BYPASS, PR_SPEC_DISABLE, 0, 0);
9496
* prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_STORE_BYPASS, PR_SPEC_FORCE_DISABLE, 0, 0);
97+
* prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_STORE_BYPASS, PR_SPEC_DISABLE_NOEXEC, 0, 0);
9598

9699
- PR_SPEC_INDIR_BRANCH: Indirect Branch Speculation in User Processes
97100
(Mitigate Spectre V2 style attacks against user processes)

‎arch/x86/kernel/cpu/bugs.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,15 +798,25 @@ static int ssb_prctl_set(struct task_struct *task, unsigned long ctrl)
798798
if (task_spec_ssb_force_disable(task))
799799
return -EPERM;
800800
task_clear_spec_ssb_disable(task);
801+
task_clear_spec_ssb_noexec(task);
801802
task_update_spec_tif(task);
802803
break;
803804
case PR_SPEC_DISABLE:
804805
task_set_spec_ssb_disable(task);
806+
task_clear_spec_ssb_noexec(task);
805807
task_update_spec_tif(task);
806808
break;
807809
case PR_SPEC_FORCE_DISABLE:
808810
task_set_spec_ssb_disable(task);
809811
task_set_spec_ssb_force_disable(task);
812+
task_clear_spec_ssb_noexec(task);
813+
task_update_spec_tif(task);
814+
break;
815+
case PR_SPEC_DISABLE_NOEXEC:
816+
if (task_spec_ssb_force_disable(task))
817+
return -EPERM;
818+
task_set_spec_ssb_disable(task);
819+
task_set_spec_ssb_noexec(task);
810820
task_update_spec_tif(task);
811821
break;
812822
default:
@@ -885,6 +895,8 @@ static int ssb_prctl_get(struct task_struct *task)
885895
case SPEC_STORE_BYPASS_PRCTL:
886896
if (task_spec_ssb_force_disable(task))
887897
return PR_SPEC_PRCTL | PR_SPEC_FORCE_DISABLE;
898+
if (task_spec_ssb_noexec(task))
899+
return PR_SPEC_PRCTL | PR_SPEC_DISABLE_NOEXEC;
888900
if (task_spec_ssb_disable(task))
889901
return PR_SPEC_PRCTL | PR_SPEC_DISABLE;
890902
return PR_SPEC_PRCTL | PR_SPEC_ENABLE;

‎arch/x86/kernel/process.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,18 @@ void arch_setup_new_exec(void)
255255
/* If cpuid was previously disabled for this task, re-enable it. */
256256
if (test_thread_flag(TIF_NOCPUID))
257257
enable_cpuid();
258+
259+
/*
260+
* Don't inherit TIF_SSBD across exec boundary when
261+
* PR_SPEC_DISABLE_NOEXEC is used.
262+
*/
263+
if (test_thread_flag(TIF_SSBD) &&
264+
task_spec_ssb_noexec(current)) {
265+
clear_thread_flag(TIF_SSBD);
266+
task_clear_spec_ssb_disable(current);
267+
task_clear_spec_ssb_noexec(current);
268+
speculation_ctrl_update(task_thread_info(current)->flags);
269+
}
258270
}
259271

260272
static inline void switch_to_bitmap(struct thread_struct *prev,

‎include/linux/sched.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,6 +1453,7 @@ static inline bool is_percpu_thread(void)
14531453
#define PFA_SPEC_SSB_FORCE_DISABLE 4 /* Speculative Store Bypass force disabled*/
14541454
#define PFA_SPEC_IB_DISABLE 5 /* Indirect branch speculation restricted */
14551455
#define PFA_SPEC_IB_FORCE_DISABLE 6 /* Indirect branch speculation permanently restricted */
1456+
#define PFA_SPEC_SSB_NOEXEC 7 /* Speculative Store Bypass clear on execve() */
14561457

14571458
#define TASK_PFA_TEST(name, func) \
14581459
static inline bool task_##func(struct task_struct *p) \
@@ -1481,6 +1482,10 @@ TASK_PFA_TEST(SPEC_SSB_DISABLE, spec_ssb_disable)
14811482
TASK_PFA_SET(SPEC_SSB_DISABLE, spec_ssb_disable)
14821483
TASK_PFA_CLEAR(SPEC_SSB_DISABLE, spec_ssb_disable)
14831484

1485+
TASK_PFA_TEST(SPEC_SSB_NOEXEC, spec_ssb_noexec)
1486+
TASK_PFA_SET(SPEC_SSB_NOEXEC, spec_ssb_noexec)
1487+
TASK_PFA_CLEAR(SPEC_SSB_NOEXEC, spec_ssb_noexec)
1488+
14841489
TASK_PFA_TEST(SPEC_SSB_FORCE_DISABLE, spec_ssb_force_disable)
14851490
TASK_PFA_SET(SPEC_SSB_FORCE_DISABLE, spec_ssb_force_disable)
14861491

‎include/uapi/linux/prctl.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ struct prctl_mm_map {
219219
# define PR_SPEC_ENABLE (1UL << 1)
220220
# define PR_SPEC_DISABLE (1UL << 2)
221221
# define PR_SPEC_FORCE_DISABLE (1UL << 3)
222+
# define PR_SPEC_DISABLE_NOEXEC (1UL << 4)
222223

223224
/* Reset arm64 pointer authentication keys */
224225
#define PR_PAC_RESET_KEYS 54

‎tools/include/uapi/linux/prctl.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ struct prctl_mm_map {
219219
# define PR_SPEC_ENABLE (1UL << 1)
220220
# define PR_SPEC_DISABLE (1UL << 2)
221221
# define PR_SPEC_FORCE_DISABLE (1UL << 3)
222+
# define PR_SPEC_DISABLE_NOEXEC (1UL << 4)
222223

223224
/* Reset arm64 pointer authentication keys */
224225
#define PR_PAC_RESET_KEYS 54

0 commit comments

Comments
 (0)