Re: [PATCH 2/2] arch: Reserve map_shadow_stack() syscall number for all architectures
"Edgecombe, Rick P" writes: > On Mon, 2023-09-11 at 18:02 +, Sohil Mehta wrote: >> diff --git a/arch/powerpc/kernel/syscalls/syscall.tbl >> b/arch/powerpc/kernel/syscalls/syscall.tbl >> index 20e50586e8a2..2767b8a42636 100644 >> --- a/arch/powerpc/kernel/syscalls/syscall.tbl >> +++ b/arch/powerpc/kernel/syscalls/syscall.tbl >> @@ -539,3 +539,4 @@ >> 450nospu set_mempolicy_home_node sys_set_mempolicy_hom >> e_node >> 451common cachestat sys_cachestat >> 452common fchmodat2 sys_fchmodat2 >> +453common map_shadow_stacksys_map_shadow_stack > > I noticed in powerpc, the not implemented syscalls are manually mapped > to sys_ni_syscall. It also has some special extra sys_ni_syscall() > implementation bits to handle both ARCH_HAS_SYSCALL_WRAPPER and > !ARCH_HAS_SYSCALL_WRAPPER. So wondering if it might need special > treatment. Did you see those parts? I don't think it needs any special treatment. It's processed by the same script as other arches (scripts/syscalltbl.sh). So if there's no compat or native entry it will default to sys_ni_syscall. I think it's just habit/historical that we always spell out sys_ni_syscall. cheers
Re: [PATCH 2/2] arch: Reserve map_shadow_stack() syscall number for all architectures
On Wed, 2023-09-13 at 12:18 -0700, Sohil Mehta wrote: > On 9/11/2023 2:10 PM, Edgecombe, Rick P wrote: > > On Mon, 2023-09-11 at 18:02 +, Sohil Mehta wrote: > > > diff --git a/arch/powerpc/kernel/syscalls/syscall.tbl > > > b/arch/powerpc/kernel/syscalls/syscall.tbl > > > index 20e50586e8a2..2767b8a42636 100644 > > > --- a/arch/powerpc/kernel/syscalls/syscall.tbl > > > +++ b/arch/powerpc/kernel/syscalls/syscall.tbl > > > @@ -539,3 +539,4 @@ > > > 450nospu set_mempolicy_home_node sys_set_mempolicy > > > _hom > > > e_node > > > 451common cachestat sys_cachestat > > > 452common fchmodat2 sys_fchmodat2 > > > +453common map_shadow_stacksys_map_shadow_st > > > ack > > > > I noticed in powerpc, the not implemented syscalls are manually > > mapped > > to sys_ni_syscall. It also has some special extra sys_ni_syscall() > > implementation bits to handle both ARCH_HAS_SYSCALL_WRAPPER and > > !ARCH_HAS_SYSCALL_WRAPPER. So wondering if it might need special > > treatment. Did you see those parts? > > > > Thanks for pointing this out. Powerpc seems to be unique in their > handling of not implemented syscalls. Maybe it's because of their > special casing of the ARCH_HAS_SYSCALL_WRAPPER. > > The code below in arch/powerpc/include/asm/syscalls.h suggests to me > that it should be safe to map map_shadow_stack() to sys_ni_syscall() > and > the special handling will be taken care of. > > #ifndef CONFIG_ARCH_HAS_SYSCALL_WRAPPER > long sys_ni_syscall(void); > #else > long sys_ni_syscall(const struct pt_regs *regs); > #endif > > I don't quite understand the underlying reasoning for it though. Do > you > have any additional insight into how we should handle this? > > I am thinking of doing the following in the next iteration unless > someone chimes in and says otherwise. > > --- a/arch/powerpc/kernel/syscalls/syscall.tbl > +++ b/arch/powerpc/kernel/syscalls/syscall.tbl > @@ -539,4 +539,4 @@ > 450 nospu set_mempolicy_home_node > sys_set_mempolicy_home_node > 451 common cachestat sys_cachestat > 452 common fchmodat2 sys_fchmodat2 > -453 common map_shadow_stack sys_map_shadow_stack > +453 common map_shadow_stack sys_ni_syscall It might have something to do with that powerpc's COND_SYSCALL() implementation only defines the struct pt_regs variety, but TBH I get a bit lost when I get to the inline assembly symbol definitions parts and how it all ties together. Doing powerpc's version as sys_ni_syscall seems to be consistent at least, and makes sense with respect to the code you quoted.
Re: [PATCH 2/2] arch: Reserve map_shadow_stack() syscall number for all architectures
On 9/11/2023 2:10 PM, Edgecombe, Rick P wrote: > On Mon, 2023-09-11 at 18:02 +, Sohil Mehta wrote: >> diff --git a/arch/powerpc/kernel/syscalls/syscall.tbl >> b/arch/powerpc/kernel/syscalls/syscall.tbl >> index 20e50586e8a2..2767b8a42636 100644 >> --- a/arch/powerpc/kernel/syscalls/syscall.tbl >> +++ b/arch/powerpc/kernel/syscalls/syscall.tbl >> @@ -539,3 +539,4 @@ >> 450nospu set_mempolicy_home_node sys_set_mempolicy_hom >> e_node >> 451common cachestat sys_cachestat >> 452common fchmodat2 sys_fchmodat2 >> +453common map_shadow_stacksys_map_shadow_stack > > I noticed in powerpc, the not implemented syscalls are manually mapped > to sys_ni_syscall. It also has some special extra sys_ni_syscall() > implementation bits to handle both ARCH_HAS_SYSCALL_WRAPPER and > !ARCH_HAS_SYSCALL_WRAPPER. So wondering if it might need special > treatment. Did you see those parts? > Thanks for pointing this out. Powerpc seems to be unique in their handling of not implemented syscalls. Maybe it's because of their special casing of the ARCH_HAS_SYSCALL_WRAPPER. The code below in arch/powerpc/include/asm/syscalls.h suggests to me that it should be safe to map map_shadow_stack() to sys_ni_syscall() and the special handling will be taken care of. #ifndef CONFIG_ARCH_HAS_SYSCALL_WRAPPER long sys_ni_syscall(void); #else long sys_ni_syscall(const struct pt_regs *regs); #endif I don't quite understand the underlying reasoning for it though. Do you have any additional insight into how we should handle this? I am thinking of doing the following in the next iteration unless someone chimes in and says otherwise. --- a/arch/powerpc/kernel/syscalls/syscall.tbl +++ b/arch/powerpc/kernel/syscalls/syscall.tbl @@ -539,4 +539,4 @@ 450nospu set_mempolicy_home_node sys_set_mempolicy_home_node 451common cachestat sys_cachestat 452common fchmodat2 sys_fchmodat2 -453common map_shadow_stacksys_map_shadow_stack +453common map_shadow_stacksys_ni_syscall
Re: [PATCH 2/2] arch: Reserve map_shadow_stack() syscall number for all architectures
On Mon, 2023-09-11 at 18:02 +, Sohil Mehta wrote: > diff --git a/arch/powerpc/kernel/syscalls/syscall.tbl > b/arch/powerpc/kernel/syscalls/syscall.tbl > index 20e50586e8a2..2767b8a42636 100644 > --- a/arch/powerpc/kernel/syscalls/syscall.tbl > +++ b/arch/powerpc/kernel/syscalls/syscall.tbl > @@ -539,3 +539,4 @@ > 450nospu set_mempolicy_home_node sys_set_mempolicy_hom > e_node > 451common cachestat sys_cachestat > 452common fchmodat2 sys_fchmodat2 > +453common map_shadow_stacksys_map_shadow_stack I noticed in powerpc, the not implemented syscalls are manually mapped to sys_ni_syscall. It also has some special extra sys_ni_syscall() implementation bits to handle both ARCH_HAS_SYSCALL_WRAPPER and !ARCH_HAS_SYSCALL_WRAPPER. So wondering if it might need special treatment. Did you see those parts?
[PATCH 2/2] arch: Reserve map_shadow_stack() syscall number for all architectures
Support for map_shadow_stack() was recently added but it is an x86 only system call for now. There is a possibility that other architectures (namely, arm64 and Risc-V) that are implementing support for shadow stacks, might need to add support for it. Independent of that, reserving arch-specific syscall numbers in the syscall tables of all architectures is good practice and would help avoid future conflicts. Note, map_shadow_stack() was assigned #453 since #452 was taken by fchmodat2(). Link:https://lore.kernel.org/lkml/20230830234752.19858-1-dave.han...@linux.intel.com/ Signed-off-by: Sohil Mehta --- arch/alpha/kernel/syscalls/syscall.tbl | 1 + arch/arm/tools/syscall.tbl | 1 + arch/arm64/include/asm/unistd.h | 2 +- arch/arm64/include/asm/unistd32.h | 2 ++ arch/ia64/kernel/syscalls/syscall.tbl | 1 + arch/m68k/kernel/syscalls/syscall.tbl | 1 + arch/microblaze/kernel/syscalls/syscall.tbl | 1 + arch/mips/kernel/syscalls/syscall_n32.tbl | 1 + arch/mips/kernel/syscalls/syscall_n64.tbl | 1 + arch/mips/kernel/syscalls/syscall_o32.tbl | 1 + arch/parisc/kernel/syscalls/syscall.tbl | 1 + arch/powerpc/kernel/syscalls/syscall.tbl| 1 + arch/s390/kernel/syscalls/syscall.tbl | 1 + arch/sh/kernel/syscalls/syscall.tbl | 1 + arch/sparc/kernel/syscalls/syscall.tbl | 1 + arch/x86/entry/syscalls/syscall_32.tbl | 1 + arch/xtensa/kernel/syscalls/syscall.tbl | 1 + include/uapi/asm-generic/unistd.h | 5 - tools/include/uapi/asm-generic/unistd.h | 5 - tools/perf/arch/mips/entry/syscalls/syscall_n64.tbl | 1 + tools/perf/arch/powerpc/entry/syscalls/syscall.tbl | 1 + tools/perf/arch/s390/entry/syscalls/syscall.tbl | 1 + tools/perf/arch/x86/entry/syscalls/syscall_64.tbl | 1 + 23 files changed, 30 insertions(+), 3 deletions(-) diff --git a/arch/alpha/kernel/syscalls/syscall.tbl b/arch/alpha/kernel/syscalls/syscall.tbl index ad37569d0507..6e8479c96e65 100644 --- a/arch/alpha/kernel/syscalls/syscall.tbl +++ b/arch/alpha/kernel/syscalls/syscall.tbl @@ -492,3 +492,4 @@ 560common set_mempolicy_home_node sys_ni_syscall 561common cachestat sys_cachestat 562common fchmodat2 sys_fchmodat2 +563common map_shadow_stacksys_map_shadow_stack diff --git a/arch/arm/tools/syscall.tbl b/arch/arm/tools/syscall.tbl index c572d6c3dee0..6d494dfbf5e4 100644 --- a/arch/arm/tools/syscall.tbl +++ b/arch/arm/tools/syscall.tbl @@ -466,3 +466,4 @@ 450common set_mempolicy_home_node sys_set_mempolicy_home_node 451common cachestat sys_cachestat 452common fchmodat2 sys_fchmodat2 +453common map_shadow_stacksys_map_shadow_stack diff --git a/arch/arm64/include/asm/unistd.h b/arch/arm64/include/asm/unistd.h index bd77253b62e0..6a28fb91b85d 100644 --- a/arch/arm64/include/asm/unistd.h +++ b/arch/arm64/include/asm/unistd.h @@ -39,7 +39,7 @@ #define __ARM_NR_compat_set_tls(__ARM_NR_COMPAT_BASE + 5) #define __ARM_NR_COMPAT_END(__ARM_NR_COMPAT_BASE + 0x800) -#define __NR_compat_syscalls 453 +#define __NR_compat_syscalls 454 #endif #define __ARCH_WANT_SYS_CLONE diff --git a/arch/arm64/include/asm/unistd32.h b/arch/arm64/include/asm/unistd32.h index 78b68311ec81..a201d842ec82 100644 --- a/arch/arm64/include/asm/unistd32.h +++ b/arch/arm64/include/asm/unistd32.h @@ -911,6 +911,8 @@ __SYSCALL(__NR_set_mempolicy_home_node, sys_set_mempolicy_home_node) __SYSCALL(__NR_cachestat, sys_cachestat) #define __NR_fchmodat2 452 __SYSCALL(__NR_fchmodat2, sys_fchmodat2) +#define __NR_map_shadow_stack 453 +__SYSCALL(__NR_map_shadow_stack, sys_map_shadow_stack) /* * Please add new compat syscalls above this comment and update diff --git a/arch/ia64/kernel/syscalls/syscall.tbl b/arch/ia64/kernel/syscalls/syscall.tbl index 83d8609aec03..be02ce9d376f 100644 --- a/arch/ia64/kernel/syscalls/syscall.tbl +++ b/arch/ia64/kernel/syscalls/syscall.tbl @@ -373,3 +373,4 @@ 450common set_mempolicy_home_node sys_set_mempolicy_home_node 451common cachestat sys_cachestat 452common fchmodat2 sys_fchmodat2 +453common map_shadow_stacksys_map_shadow_stack diff --git a/arch/m68k/kernel/syscalls/syscall.tbl b/arch/m68k/kernel/syscalls/syscall.tbl index 259ceb125367..bee2d2f7f82c 100644 --- a/arch/m68k/kernel/syscalls/syscall.tbl +++ b/arch/m68k/kernel/syscalls/syscall.tbl @@ -452,3 +452,4 @@ 450common set_mempolicy_home_node sys_set_mempolicy_home_node 451common cachestat sys_cachestat 452common fchmodat2