Skip to contentSkip to conversation

x86/speculation: Don't inherit TIF_SSBD on execve()

RFC PATCH In review Waiman Long 3 participants 9 messages Dec 19, 2018 – Jan 15, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 x86/speculation: Don't inherit TIF_SSBD on execve()

With the default SPEC_STORE_BYPASS_SECCOMP/SPEC_STORE_BYPASS_PRCTL mode, the TIF_SSBD bit will be inherited when a new task is fork'ed or cloned.

As only certain class of applications (like Java) requires disabling speculative store bypass for security purpose, it may not make sense to allow the TIF_SSBD bit to be inherited across execve() boundary where the new application may not need SSBD at all and is probably not aware that SSBD may have been turned on. This may cause an unnecessary performance loss of up to 20% in some cases.

The arch_setup_new_exec() function is updated to clear the TIF_SSBD bit unless it has been force-disabled.

---
 Documentation/userspace-api/spec_ctrl.rst |  3 +++
 arch/x86/kernel/process.c                 | 10 ++++++++++
 2 files changed, 13 insertions(+)
Documentation/userspace-api/spec_ctrl.rst +3 -0
index c4dbe6f..226aed5 100644
@@ -55,6 +55,9 @@ is selected by arg2 of :manpage:`prctl(2)` per task. arg3 is used to hand
 in the control value, i.e. either PR_SPEC_ENABLE or PR_SPEC_DISABLE or
 PR_SPEC_FORCE_DISABLE.
 
+When mitigation is enabled, its state will not be inherited on
+:manpage:`execve(2)` unless it is force-disabled.
+
 Common error codes
 ------------------
 ======= =================================================================
arch/x86/kernel/process.c +10 -0
index 7d31192..f207f4d 100644
@@ -252,6 +252,16 @@ void arch_setup_new_exec(void)
 	/* If cpuid was previously disabled for this task, re-enable it. */
 	if (test_thread_flag(TIF_NOCPUID))
 		enable_cpuid();
+
+	/*
+	 * Don't inherit TIF_SSBD across exec boundary unless speculative
+	 * store bypass is force-disabled (e.g. seccomp on).
+	 */
+	if (test_thread_flag(TIF_SSBD) &&
+	   !task_spec_ssb_force_disable(current)) {
+		clear_thread_flag(TIF_SSBD);
+		task_clear_spec_ssb_disable(current);
+	}
 }
 
 static inline void switch_to_bitmap(struct thread_struct *prev,
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 10 lines · Waiman Long

With the default SPEC_STORE_BYPASS_SECCOMP/SPEC_STORE_BYPASS_PRCTL mode, the TIF_SSBD bit will be inherited when a new task is fork'ed or cloned.

As only certain class of applications (like Java) requires disabling speculative store bypass for security purpose, it may not make sense to allow the TIF_SSBD bit to be inherited across execve() boundary where the new application may not need SSBD at all and is probably not aware that SSBD may have been turned on. This may cause an unnecessary performance loss of up to 20% in some cases.

Quoted 2 lines

The arch_setup_new_exec() function is updated to clear the TIF_SSBD bit unless it has been force-disabled.

This makes it impossible to write a wrapper that turns this mode on for unmodified programs.

Do you have a real use case where this behavior is a problem?

-Andi

#2 lore raw
Quoted 11 lines · Andi Kleen
Quoted 10 lines · Waiman Long

With the default SPEC_STORE_BYPASS_SECCOMP/SPEC_STORE_BYPASS_PRCTL mode, the TIF_SSBD bit will be inherited when a new task is fork'ed or cloned.

As only certain class of applications (like Java) requires disabling speculative store bypass for security purpose, it may not make sense to allow the TIF_SSBD bit to be inherited across execve() boundary where the new application may not need SSBD at all and is probably not aware that SSBD may have been turned on. This may cause an unnecessary performance loss of up to 20% in some cases.

Quoted 4 lines
Quoted 2 lines

The arch_setup_new_exec() function is updated to clear the TIF_SSBD bit unless it has been force-disabled.

This makes it impossible to write a wrapper that turns this mode on for unmodified programs.

You can always force disable SSB. In that case, all the child processes will have SSBD on.

Quoted 4 lines

Do you have a real use case where this behavior is a problem?

-Andi

Yes, we have an enterprise application partner that found that their application slow down up to 10-20% depending on how their application was set up. With the slow setup, the application was spawned by Java processes causing the SSBD bit to stay on when the application was running.

Cheers,
Longman

#3 lore raw
Quoted 2 lines

You can always force disable SSB. In that case, all the child processes will have SSBD on.

Okay that sounds reasonable, given the below. Thanks.

-Andi

Quoted 10 lines
Quoted 5 lines

Do you have a real use case where this behavior is a problem?

-Andi

Yes, we have an enterprise application partner that found that their application slow down up to 10-20% depending on how their application was set up. With the slow setup, the application was spawned by Java processes causing the SSBD bit to stay on when the application was running.

#4 lore raw
In reply to Waiman Long
Quoted 44 lines · Waiman Long

With the default SPEC_STORE_BYPASS_SECCOMP/SPEC_STORE_BYPASS_PRCTL mode, the TIF_SSBD bit will be inherited when a new task is fork'ed or cloned.

As only certain class of applications (like Java) requires disabling speculative store bypass for security purpose, it may not make sense to allow the TIF_SSBD bit to be inherited across execve() boundary where the new application may not need SSBD at all and is probably not aware that SSBD may have been turned on. This may cause an unnecessary performance loss of up to 20% in some cases.

The arch_setup_new_exec() function is updated to clear the TIF_SSBD bit unless it has been force-disabled.

---
 Documentation/userspace-api/spec_ctrl.rst |  3 +++
 arch/x86/kernel/process.c                 | 10 ++++++++++
 2 files changed, 13 insertions(+)
Documentation/userspace-api/spec_ctrl.rst +3 -0
index c4dbe6f..226aed5 100644
@@ -55,6 +55,9 @@ is selected by arg2 of :manpage:`prctl(2)` per task. arg3 is used to hand
 in the control value, i.e. either PR_SPEC_ENABLE or PR_SPEC_DISABLE or
 PR_SPEC_FORCE_DISABLE.
 
+When mitigation is enabled, its state will not be inherited on
+:manpage:`execve(2)` unless it is force-disabled.
+
 Common error codes
 ------------------
 ======= =================================================================
arch/x86/kernel/process.c +3 -0
index 7d31192..f207f4d 100644
@@ -252,6 +252,16 @@ void arch_setup_new_exec(void)
 	/* If cpuid was previously disabled for this task, re-enable it. */
 	if (test_thread_flag(TIF_NOCPUID))
 		enable_cpuid();
+
+	/*
+	 * Don't inherit TIF_SSBD across exec boundary unless speculative

arch/x86/kernel/process.c void arch_setup_new_exec(void) · line 267

Quoted 10 lines
arch/x86/kernel/process.c +7 -0
+	 * store bypass is force-disabled (e.g. seccomp on).
+	 */
+	if (test_thread_flag(TIF_SSBD) &&
+	   !task_spec_ssb_force_disable(current)) {
+		clear_thread_flag(TIF_SSBD);
+		task_clear_spec_ssb_disable(current);
+	}
 }
 
 static inline void switch_to_bitmap(struct thread_struct *prev,

Ping! Any comments of objections?

Cheers,
Longman

#5 lore raw
In reply to Waiman Long
Quoted 9 lines · Waiman Long

With the default SPEC_STORE_BYPASS_SECCOMP/SPEC_STORE_BYPASS_PRCTL mode, the TIF_SSBD bit will be inherited when a new task is fork'ed or cloned.

As only certain class of applications (like Java) requires disabling speculative store bypass for security purpose, it may not make sense to allow the TIF_SSBD bit to be inherited across execve() boundary where the new application may not need SSBD at all and is probably not aware that SSBD may have been turned on. This may cause an unnecessary performance loss of up to 20% in some cases.

Lot's of MAY's here. Aside of that this fundamentally changes the behaviour. I'm not really a fan of doing that.

If there are good reasons to have a non-inherited variant, then we rather introduce that instead of changing the existing semantics without a way for existing userspace to notice.

Thanks,

tglx

#6 lore raw
Quoted 11 lines · Thomas Gleixner
Quoted 9 lines · Waiman Long

With the default SPEC_STORE_BYPASS_SECCOMP/SPEC_STORE_BYPASS_PRCTL mode, the TIF_SSBD bit will be inherited when a new task is fork'ed or cloned.

As only certain class of applications (like Java) requires disabling speculative store bypass for security purpose, it may not make sense to allow the TIF_SSBD bit to be inherited across execve() boundary where the new application may not need SSBD at all and is probably not aware that SSBD may have been turned on. This may cause an unnecessary performance loss of up to 20% in some cases.

Quoted 6 lines

Lot's of MAY's here. Aside of that this fundamentally changes the behaviour. I'm not really a fan of doing that.

If there are good reasons to have a non-inherited variant, then we rather introduce that instead of changing the existing semantics without a way for existing userspace to notice.

I understand your point. How about adding a ",noexec" auxillary option to the spec_store_bypass_disable command line to activate this new behavior without changing the default. Will that be acceptable?

Cheers,
Longman

#7 lore raw
Quoted 15 lines · Waiman Long
Quoted 14 lines · Thomas Gleixner
Quoted 9 lines · Waiman Long

With the default SPEC_STORE_BYPASS_SECCOMP/SPEC_STORE_BYPASS_PRCTL mode, the TIF_SSBD bit will be inherited when a new task is fork'ed or cloned.

As only certain class of applications (like Java) requires disabling speculative store bypass for security purpose, it may not make sense to allow the TIF_SSBD bit to be inherited across execve() boundary where the new application may not need SSBD at all and is probably not aware that SSBD may have been turned on. This may cause an unnecessary performance loss of up to 20% in some cases.

Lot's of MAY's here. Aside of that this fundamentally changes the behaviour. I'm not really a fan of doing that.

Quoted 7 lines
Quoted 3 lines

If there are good reasons to have a non-inherited variant, then we rather introduce that instead of changing the existing semantics without a way for existing userspace to notice.

I understand your point. How about adding a ",noexec" auxillary option to the spec_store_bypass_disable command line to activate this new behavior without changing the default. Will that be acceptable?

I'd rather have an explicit PR_SPEC_DISABLE_NOEXEC argument for the PRCTL so you can decide at the application level what kind of behaviour you want.

Thanks,

tglx

#8 lore raw
Quoted 22 lines · Thomas Gleixner
Quoted 15 lines · Waiman Long
Quoted 14 lines · Thomas Gleixner
Quoted 9 lines · Waiman Long

With the default SPEC_STORE_BYPASS_SECCOMP/SPEC_STORE_BYPASS_PRCTL mode, the TIF_SSBD bit will be inherited when a new task is fork'ed or cloned.

As only certain class of applications (like Java) requires disabling speculative store bypass for security purpose, it may not make sense to allow the TIF_SSBD bit to be inherited across execve() boundary where the new application may not need SSBD at all and is probably not aware that SSBD may have been turned on. This may cause an unnecessary performance loss of up to 20% in some cases.

Lot's of MAY's here. Aside of that this fundamentally changes the behaviour. I'm not really a fan of doing that.

Quoted 6 lines
Quoted 3 lines

If there are good reasons to have a non-inherited variant, then we rather introduce that instead of changing the existing semantics without a way for existing userspace to notice.

I understand your point. How about adding a ",noexec" auxillary option to the spec_store_bypass_disable command line to activate this new behavior without changing the default. Will that be acceptable?

Quoted 6 lines

I'd rather have an explicit PR_SPEC_DISABLE_NOEXEC argument for the PRCTL so you can decide at the application level what kind of behaviour you want.

Thanks,

tglx

Thanks for the advice. Will work on a v2 to be sent out later this week.

Cheers,
Longman