Skip to contentSkip to conversation

x86/shstk: Provide kernel command line knob to disable

PATCH Superseded Mathias Krause 4 participants 8 messages Apr 2 x86

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/shstk: Provide kernel command line knob to disable

Provide a kernel command line option 'shstk=off' to disable CET shadow stacks, much like 'ibt=off' can be used to disable CET IBT.

With both set to off, it avoids setting CR4.CET on capable hardware to allow debugging related issues during early boot.

---
 arch/x86/kernel/shstk.c | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/x86/kernel/shstk.c +9 -0
index 978232b6d48d..68b46bf1540b 100644
@@ -542,6 +542,15 @@ static int shstk_disable(void)
 	return 0;
 }
 
+static int __init shstk_configure(char *str)
+{
+	if (!strcmp(str, "off"))
+		setup_clear_cpu_cap(X86_FEATURE_SHSTK);
+
+	return 1;
+}
+__setup("shstk=", shstk_configure);
+
 SYSCALL_DEFINE3(map_shadow_stack, unsigned long, addr, unsigned long, size, unsigned int, flags)
 {
 	bool set_tok = flags & SHADOW_STACK_SET_TOKEN;
Signature · 1 line
2.47.3
#1 lore raw
Quoted 5 lines · Mathias Krause

Provide a kernel command line option 'shstk=off' to disable CET shadow stacks, much like 'ibt=off' can be used to disable CET IBT.

With both set to off, it avoids setting CR4.CET on capable hardware to allow debugging related issues during early boot.

Why though?

#2 lore raw
Quoted 8 lines · Peter Zijlstra
Quoted 5 lines · Mathias Krause

Provide a kernel command line option 'shstk=off' to disable CET shadow stacks, much like 'ibt=off' can be used to disable CET IBT.

With both set to off, it avoids setting CR4.CET on capable hardware to allow debugging related issues during early boot.

Why though?

I ran into related issues three times in the past now, where the lack of early exception handling and the lack of a knob to disable CR4.CET=1 enabling made debugging this a real PITA. Now, with QEMU having gained CET virtualization support, that may be less of an issue. However, in at least one case the UEFI firmware was involved and I had to test&debug on bare metal. Having such a knob allows ruling out or pin-pointing CET as the cause more easily.

Thanks,
Mathias

#3 lore raw
Quoted 8 lines · Mathias Krause
Quoted 7 lines · Peter Zijlstra
Quoted 5 lines · Mathias Krause

Provide a kernel command line option 'shstk=off' to disable CET shadow stacks, much like 'ibt=off' can be used to disable CET IBT.

With both set to off, it avoids setting CR4.CET on capable hardware to allow debugging related issues during early boot.

Quoted 6 lines
Quoted 1 line

Why though?

I ran into related issues three times in the past now, where the lack of early exception handling and the lack of a knob to disable CR4.CET=1 enabling made debugging this a real PITA. Now, with QEMU having gained CET virtualization support, that may be less of an issue.

Ah, I wrote the kernel IBT code using a host/qemu patched with very early versions of those patches. It did indeed take ages for that stuff to land upstream.

Quoted 3 lines

However, in at least one case the UEFI firmware was involved and I had to test&debug on bare metal. Having such a knob allows ruling out or pin-pointing CET as the cause more easily.

Fair enough, although this should probably have made it in the Changelog.

Other than that,

#4 lore raw
Quoted 8 lines · Peter Zijlstra
Quoted 3 lines

However, in at least one case the UEFI firmware was involved and I had to test&debug on bare metal. Having such a knob allows ruling out or pin-pointing CET as the cause more easily.

Fair enough, although this should probably have made it in the Changelog.

Other than that,

Some firmwares use supervisor shadow stack in SMM and have had issues with CR4.CET set. But these were BIOS crashes.

The other usefulness could be recovering from shadow stack crashes in early userspace that block boot.

Could we add something to the docs though?

#5 lore raw
Quoted 1 line · Rick P

Could we add something to the docs though?

Yes, an update to Documentation/admin-guide/kernel-parameters.txt is in order. Bonus points if the missing ibt=off gets added too.

#6 lore raw
Quoted 5 lines · Dave Hansen
Quoted 1 line · Rick P

Could we add something to the docs though?

Yes, an update to Documentation/admin-guide/kernel-parameters.txt is in order. Bonus points if the missing ibt=off gets added too.

Ready to pick up my bonus points: :D
https://lore.kernel.org/lkml/[email protected]/

Cheers,
Mathias

#7 lore raw
In reply to Edgecombe, Rick P
Quoted 5 lines · Rick P
Quoted 4 lines · Peter Zijlstra
Quoted 3 lines

However, in at least one case the UEFI firmware was involved and I had to test&debug on bare metal. Having such a knob allows ruling out or pin-pointing CET as the cause more easily.

Quoted 7 lines
Quoted 4 lines

Fair enough, although this should probably have made it in the Changelog.

Other than that,

Some firmwares use supervisor shadow stack in SMM and have had issues with CR4.CET set. But these were BIOS crashes.

TIL! :D

Quoted 3 lines

The other usefulness could be recovering from shadow stack crashes in early userspace that block boot.

Jepp. A chicken-bit is always nice to have, IMHO.

Quoted 4 lines

Could we add something to the docs though?

As the 'ibt=off' commandline option lacks documentation as well, I don't think it's needed.

There are other parameters, e.g. "debug-alternative", that are useful debugging tools but also lack documentation. The reason for that is likely that these switches are meant for developers and these can 'git grep -w __setup' easily to hunt for these.

Thanks,
Mathias