Skip to contentSkip to conversation

LoongArch: add spectre boundry for syscall dispatch table

PATCH In review Greg Kroah-Hartman 4 participants 8 messages Mar 24 – Apr 8 LoongArch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 LoongArch: add spectre boundry for syscall dispatch table

The LoongArch syscall number is directly controlled by userspace, but does not have a array_index_nospec() boundry to prevent access past the syscall function pointer tables.

Cc Huacai Chen <[email protected]>
Cc WANG Xuerui <[email protected]>
Assisted-by gkh_clanker_2000
Cc stable <[email protected]>

---
My scripts caught this as I think LoongArch is vulnerable to the old-style Spectre 1 issues, but I couldn't find where it was addressed in the syscall path. Did I just miss it somewhere, or is this patch still needed?

 arch/loongarch/kernel/syscall.c | 2 ++
 1 file changed, 2 insertions(+)
arch/loongarch/kernel/syscall.c +2 -0
index 1249d82c1cd0..f2c98bbafce3 100644
@@ -8,6 +8,7 @@
 #include <linux/capability.h>
 #include <linux/entry-common.h>
 #include <linux/errno.h>
+#include <linux/nospec.h>
 #include <linux/linkage.h>
 #include <linux/objtool.h>
 #include <linux/randomize_kstack.h>
@@ -74,6 +75,7 @@ void noinstr __no_stack_protector do_syscall(struct pt_regs *regs)
 	add_random_kstack_offset();
 
 	if (nr < NR_syscalls) {
+		nr = array_index_nospec(nr, NR_syscalls);
 		syscall_fn = sys_call_table[nr];
 		regs->regs[4] = syscall_fn(regs->orig_a0, regs->regs[5], regs->regs[6],
 					   regs->regs[7], regs->regs[8], regs->regs[9]);
Signature · 1 line
2.53.0
#1 lore raw
Quoted 5 lines · Greg Kroah-Hartman

The LoongArch syscall number is directly controlled by userspace, but does not have a array_index_nospec() boundry to prevent access past the
syscall function pointer tables.

Quoted 7 lines
Cc Huacai Chen <[email protected]>
Cc WANG Xuerui <[email protected]>
Assisted-by gkh_clanker_2000
Cc stable <[email protected]>

---
My scripts caught this as I think LoongArch is vulnerable to the

There's no evidence. The kernel currently report all LoongArch processors invulnerable to spectre V1 via cpuinfo.

So NAK unless there's a reproducer of spectre V1 on LoongArch. If so we'd also need to adjust the cpuinfo output.

Signature · 1 line
Xi Ruoyao <[email protected]>
#2 lore raw
Quoted 14 lines · Xi Ruoyao
Quoted 5 lines · Greg Kroah-Hartman

The LoongArch syscall number is directly controlled by userspace, but does not have a array_index_nospec() boundry to prevent access past the
syscall function pointer tables.

Quoted 7 lines
Cc Huacai Chen <[email protected]>
Cc WANG Xuerui <[email protected]>
Assisted-by gkh_clanker_2000
Cc stable <[email protected]>

---
My scripts caught this as I think LoongArch is vulnerable to the

Quoted 2 lines

There's no evidence. The kernel currently report all LoongArch processors invulnerable to spectre V1 via cpuinfo.

Where is that? In the sysfs files, or in the actual silicon testing?

Quoted 2 lines

So NAK unless there's a reproducer of spectre V1 on LoongArch. If so we'd also need to adjust the cpuinfo output.

I really thought this cpu was vulnerable to this, but if the companies say it isn't, then great, but reports like this:
https://cc-sw.com/chinese-loongarch-architecture-evaluation-part-3-of-3/
say that the silicon is vulnerable. So, which is it?

confused,

greg k-h

#3 lore raw
Quoted 20 lines · Greg Kroah-Hartman
Quoted 14 lines · Xi Ruoyao
Quoted 5 lines · Greg Kroah-Hartman

The LoongArch syscall number is directly controlled by userspace, but does not have a array_index_nospec() boundry to prevent access past the
syscall function pointer tables.

Quoted 7 lines
Cc Huacai Chen <[email protected]>
Cc WANG Xuerui <[email protected]>
Assisted-by gkh_clanker_2000
Cc stable <[email protected]>

---
My scripts caught this as I think LoongArch is vulnerable to the

Quoted 2 lines

There's no evidence. The kernel currently report all LoongArch processors invulnerable to spectre V1 via cpuinfo.

Where is that? In the sysfs files, or in the actual silicon testing?

Quoted 7 lines
Quoted 2 lines

So NAK unless there's a reproducer of spectre V1 on LoongArch. If so we'd also need to adjust the cpuinfo output.

I really thought this cpu was vulnerable to this, but if the companies say it isn't, then great, but reports like this:
https://cc-sw.com/chinese-loongarch-architecture-evaluation-part-3-of-3/
say that the silicon is vulnerable. So, which is it?

Any thoughts about this?

thanks,

greg k-h

#4 lore raw
Quoted 24 lines · Greg Kroah-Hartman
Quoted 23 lines · Greg Kroah-Hartman
Quoted 14 lines · Xi Ruoyao
Quoted 5 lines · Greg Kroah-Hartman

The LoongArch syscall number is directly controlled by userspace, but does not have a array_index_nospec() boundry to prevent access past the
syscall function pointer tables.

Quoted 7 lines
Cc Huacai Chen <[email protected]>
Cc WANG Xuerui <[email protected]>
Assisted-by gkh_clanker_2000
Cc stable <[email protected]>

---
My scripts caught this as I think LoongArch is vulnerable to the

Quoted 2 lines

There's no evidence. The kernel currently report all LoongArch processors invulnerable to spectre V1 via cpuinfo.

Where is that? In the sysfs files, or in the actual silicon testing?

Quoted 2 lines

So NAK unless there's a reproducer of spectre V1 on LoongArch. If so we'd also need to adjust the cpuinfo output.

Quoted 6 lines
Quoted 4 lines

I really thought this cpu was vulnerable to this, but if the companies say it isn't, then great, but reports like this:
https://cc-sw.com/chinese-loongarch-architecture-evaluation-part-3-of-3/
say that the silicon is vulnerable. So, which is it?

Any thoughts about this?

co-ask though it is hard to decide :(

Regards
Bibo Mao

Quoted 5 lines

thanks,

greg k-h

#5 lore raw
Quoted 27 lines · Bibo Mao
Quoted 24 lines · Greg Kroah-Hartman
Quoted 23 lines · Greg Kroah-Hartman
Quoted 14 lines · Xi Ruoyao
Quoted 5 lines · Greg Kroah-Hartman

The LoongArch syscall number is directly controlled by userspace, but does not have a array_index_nospec() boundry to prevent access past the
syscall function pointer tables.

Quoted 7 lines
Cc Huacai Chen <[email protected]>
Cc WANG Xuerui <[email protected]>
Assisted-by gkh_clanker_2000
Cc stable <[email protected]>

---
My scripts caught this as I think LoongArch is vulnerable to the

Quoted 2 lines

There's no evidence. The kernel currently report all LoongArch processors invulnerable to spectre V1 via cpuinfo.

Where is that? In the sysfs files, or in the actual silicon testing?

Quoted 2 lines

So NAK unless there's a reproducer of spectre V1 on LoongArch. If so we'd also need to adjust the cpuinfo output.

Quoted 7 lines
Quoted 6 lines
Quoted 4 lines

I really thought this cpu was vulnerable to this, but if the companies say it isn't, then great, but reports like this:
https://cc-sw.com/chinese-loongarch-architecture-evaluation-part-3-of-3/
say that the silicon is vulnerable. So, which is it?

Any thoughts about this?

co-ask though it is hard to decide :(

Can't you all run the reproducers on your platform to determine this? There should be some basic ones around somewhere, this is a very old bug :)

thanks,

greg k-h

maintainer
#6 lore raw

Hi, all,

Quoted 34 lines · Greg Kroah-Hartman
Quoted 32 lines · Bibo Mao
Quoted 29 lines · Greg Kroah-Hartman
Quoted 27 lines · Greg Kroah-Hartman
Quoted 14 lines · Xi Ruoyao
Quoted 5 lines · Greg Kroah-Hartman

The LoongArch syscall number is directly controlled by userspace, but does not have a array_index_nospec() boundry to prevent access past the
syscall function pointer tables.

Quoted 7 lines
Cc Huacai Chen <[email protected]>
Cc WANG Xuerui <[email protected]>
Assisted-by gkh_clanker_2000
Cc stable <[email protected]>

---
My scripts caught this as I think LoongArch is vulnerable to the

Quoted 2 lines

There's no evidence. The kernel currently report all LoongArch processors invulnerable to spectre V1 via cpuinfo.

Where is that? In the sysfs files, or in the actual silicon testing?

Quoted 2 lines

So NAK unless there's a reproducer of spectre V1 on LoongArch. If so we'd also need to adjust the cpuinfo output.

I really thought this cpu was vulnerable to this, but if the companies say it isn't, then great, but reports like this:
https://cc-sw.com/chinese-loongarch-architecture-evaluation-part-3-of-3/
say that the silicon is vulnerable. So, which is it?

Quoted 6 lines
Quoted 2 lines
Quoted 1 line

Any thoughts about this?

co-ask though it is hard to decide :(

Can't you all run the reproducers on your platform to determine this? There should be some basic ones around somewhere, this is a very old bug :)

I have consulted with the chip designers. They confirmed that existing LoongArch processors are vulnerable to Spectre-V1. But this conclusion is just for the PoC (as [1] said, Spectre-V1 is not easily mitigated in hardware), it is very difficult to create a real attack program. This is not even a LoongArch-specific problem.

As an additional point, LoongArch's boundary-checking memory access instructions, which provide immunity against Spectre-V1, are not convenient enough to automatically apply to all critical code sections.

Anyway, user pointer sanitization is the proper mitigation of Spectre-V1, and that is exactly what this patch does. So, I will take this patch and update other corresponding parts of the kernel.

[1] https://cc-sw.com/chinese-loongarch-architecture-evaluation-part-3-of-3/

Huacai

Quoted 4 lines

thanks,

greg k-h

#7 lore raw
Quoted 55 lines · Huacai Chen

Hi, all,

Quoted 34 lines · Greg Kroah-Hartman
Quoted 32 lines · Bibo Mao
Quoted 29 lines · Greg Kroah-Hartman
Quoted 27 lines · Greg Kroah-Hartman
Quoted 14 lines · Xi Ruoyao
Quoted 5 lines · Greg Kroah-Hartman

The LoongArch syscall number is directly controlled by userspace, but does not have a array_index_nospec() boundry to prevent access past the
syscall function pointer tables.

Quoted 7 lines
Cc Huacai Chen <[email protected]>
Cc WANG Xuerui <[email protected]>
Assisted-by gkh_clanker_2000
Cc stable <[email protected]>

---
My scripts caught this as I think LoongArch is vulnerable to the

Quoted 2 lines

There's no evidence.  The kernel currently report all LoongArch processors invulnerable to spectre V1 via cpuinfo.

Where is that?  In the sysfs files, or in the actual silicon testing?

Quoted 2 lines

So NAK unless there's a reproducer of spectre V1 on LoongArch.  If so we'd also need to adjust the cpuinfo output.

I really thought this cpu was vulnerable to this, but if the companies say it isn't, then great, but reports like this:
  https://cc-sw.com/chinese-loongarch-architecture-evaluation-part-3-of-3/
say that the silicon is vulnerable.  So, which is it?

Quoted 6 lines
Quoted 2 lines
Quoted 1 line

Any thoughts about this?

co-ask though it is hard to decide :(

Can't you all run the reproducers on your platform to determine this? There should be some basic ones around somewhere, this is a very old bug :)

I have consulted with the chip designers. They confirmed that existing LoongArch processors are vulnerable to Spectre-V1. But this conclusion is just for the PoC (as [1] said,  Spectre-V1 is not easily mitigated in hardware), it is very difficult to create a real attack program. This is not even a LoongArch-specific problem.

As an additional point, LoongArch's boundary-checking memory access instructions, which provide immunity against Spectre-V1, are not convenient enough to automatically apply to all critical code sections.

Quoted 5 lines

Anyway, user pointer sanitization is the proper mitigation of Spectre-V1, and that is exactly what this patch does. So, I will take this patch and update other corresponding parts of the kernel.

[1] https://cc-sw.com/chinese-loongarch-architecture-evaluation-part-3-of-3/

Then IMO we should update cpuinfo report as well (well, maybe also for other architectures, if there are literally no hardware immune to the issue).

Signature · 1 line
Xi Ruoyao <[email protected]>