arm64: Unimplemented syscall kernel message
Hello Catalin and Will,
I'd like ask your opinion as arm64 Linux port maintainers and initial authors of the code in question regarding kernel messages on unimplemented system calls. I apologise in advance if that isn't the right approach (and Cc: linux-arm :).
Currently, a programm doing an unimplemented syscall triggers a rather scary looking kernel message:
[ 189.143682] glibc-test[2118]: syscall 1000 [ 189.143728] Code: aa0503e4 aa0603e5 aa0703e6 d4000001 (b13ffc1f) [ 189.143750] CPU: 1 PID: 2118 Comm: glibc-test Not tainted 4.15.0-rc7-00232-g2c1cfa499018 #3 [ 189.143755] Hardware name: SoPine with baseboard (DT) [ 189.143762] pstate: 80000000 (Nzcv daif -PAN -UAO) [ 189.143774] pc : 0xffffb8fb0104 [ 189.143779] lr : 0xaaaab43c563c [ 189.143781] sp : 0000ffffd4fa1180 [ 189.143786] x29: 0000ffffd4fa1190 x28: 0000000000000000 [ 189.143795] x27: 0000000000000000 x26: 0000000000000000 [ 189.143802] x25: 0000000000000000 x24: 0000000000000000 [ 189.143809] x23: 0000000000000000 x22: 0000000000000000 [ 189.143816] x21: 0000aaaab43c564c x20: 0000000000000000 [ 189.143823] x19: 0000aaaab43c5770 x18: 0000000000000a03 [ 189.143829] x17: 0000aaaab43d6020 x16: 0000ffffb8fb00e0 [ 189.143837] x15: 0000ffffb8ed4000 x14: 0000ffffb8ed7540 [ 189.143844] x13: 0000ffffb8ee45d8 x12: 0000000000000000 [ 189.143851] x11: 0000000000000020 x10: 0000000000000000 [ 189.143857] x9 : 00000000000000ff x8 : 00000000000003e8 [ 189.143864] x7 : e607cc2262a01600 x6 : e607cc2262a01600 [ 189.143872] x5 : 0000ffffd4fa12c0 x4 : 0000000000000000 [ 189.143879] x3 : 0000000000000000 x2 : 0000aaaab43c5630 [ 189.143886] x1 : 0000ffffd4fa12d8 x0 : 0000ffffd4fa12c8
It requires some digging to find that this basically is a debugging/warning message and can be disabled using /proc/sys/debug/exception-trace (arm64/kernel/traps.c:do_ni_syscall,show_unhandled_signals_ratelimited).
Other platforms do not seem to do this, even with exception-trace enabled - x86_64 and arm for sure. Instead they silently return -ENOSYS.
There are a number of other kernel messages governed by the same sysctl (fault.c:__do_user_fault,do_sp_pc_abort, traps.c:force_signal_inject, signal.c:sys_rt_sigreturn).
Can I in good conscience disable exception-trace on the affected (production) systems or would this mask other, more critical misbehaviour?
Is it actually considered misbehaviour for arm64 userland to even attempt such a call? Or is the message maybe just a left-over development aid?
Can it perhaps be removed or disabled by default, considering that with future addition of syscalls userland will likely start triggering this message a lot when run on older kernels?
Signature · 2 lines
Thanks, Michael
Hi Michael,
Quoted 48 lines · Michael Weiser
I'd like ask your opinion as arm64 Linux port maintainers and initial authors of the code in question regarding kernel messages on unimplemented system calls. I apologise in advance if that isn't the right approach (and Cc: linux-arm :).
Currently, a programm doing an unimplemented syscall triggers a rather scary looking kernel message:
[ 189.143682] glibc-test[2118]: syscall 1000 [ 189.143728] Code: aa0503e4 aa0603e5 aa0703e6 d4000001 (b13ffc1f) [ 189.143750] CPU: 1 PID: 2118 Comm: glibc-test Not tainted 4.15.0-rc7-00232-g2c1cfa499018 #3 [ 189.143755] Hardware name: SoPine with baseboard (DT) [ 189.143762] pstate: 80000000 (Nzcv daif -PAN -UAO) [ 189.143774] pc : 0xffffb8fb0104 [ 189.143779] lr : 0xaaaab43c563c [ 189.143781] sp : 0000ffffd4fa1180 [ 189.143786] x29: 0000ffffd4fa1190 x28: 0000000000000000 [ 189.143795] x27: 0000000000000000 x26: 0000000000000000 [ 189.143802] x25: 0000000000000000 x24: 0000000000000000 [ 189.143809] x23: 0000000000000000 x22: 0000000000000000 [ 189.143816] x21: 0000aaaab43c564c x20: 0000000000000000 [ 189.143823] x19: 0000aaaab43c5770 x18: 0000000000000a03 [ 189.143829] x17: 0000aaaab43d6020 x16: 0000ffffb8fb00e0 [ 189.143837] x15: 0000ffffb8ed4000 x14: 0000ffffb8ed7540 [ 189.143844] x13: 0000ffffb8ee45d8 x12: 0000000000000000 [ 189.143851] x11: 0000000000000020 x10: 0000000000000000 [ 189.143857] x9 : 00000000000000ff x8 : 00000000000003e8 [ 189.143864] x7 : e607cc2262a01600 x6 : e607cc2262a01600 [ 189.143872] x5 : 0000ffffd4fa12c0 x4 : 0000000000000000 [ 189.143879] x3 : 0000000000000000 x2 : 0000aaaab43c5630 [ 189.143886] x1 : 0000ffffd4fa12d8 x0 : 0000ffffd4fa12c8It requires some digging to find that this basically is a debugging/warning message and can be disabled using
/proc/sys/debug/exception-trace(arm64/kernel/traps.c:do_ni_syscall,show_unhandled_signals_ratelimited).Other platforms do not seem to do this, even with exception-trace enabled -
x86_64and arm for sure. Instead they silently return-ENOSYS.There are a number of other kernel messages governed by the same sysctl (fault.c:__do_user_fault,do_sp_pc_abort, traps.c:force_signal_inject, signal.c:sys_rt_sigreturn).
Can I in good conscience disable exception-trace on the affected (production) systems or would this mask other, more critical misbehaviour?
Quoted 7 lines
Is it actually considered misbehaviour for arm64 userland to even attempt such a call? Or is the message maybe just a left-over development aid?
Can it perhaps be removed or disabled by default, considering that with future addition of syscalls userland will likely start triggering this message a lot when run on older kernels?
I agree that printing this stuff is bogus. We should instead just return -ENOSYS via a redirect to sys_ni_syscall. The only corner case is for the compat private syscalls, where we should match 32-bit and dispatch SIGILL for that range (and then probably print the warning based on show_unhandled_signals_ratelimited because there's a signal involved).
Will
cover arm64: Unimplemented syscall kernel message
Hi Will,
I'm not pretending to fully understand the semantics of what I've done but I've tried to make a start on implementing both changes anyway.
The first is straightforward in dropping the offending log message from do_ni_syscall().
The second mirrors arm behaviour in compat_arm_syscall() in raising SIGILL for (most) unimplemented syscalls. I've intentionally kept the arm message format in case anyone has a script filtering for it.
Syncing __dump_instr() with arm to support thumb instructions was done on the assumption that arm-eabi code may obviously contain thumb instructions.
Both are compile-tested as well as manually prodded with some randomly chosen syscall numbers from aarch64 and arm-eabi binaries while running under qemu-system-aarch64.
Thanks,
Michael
Michael Weiser (2):
arm64: Remove unimplemented syscall log message
arm64: Mirror arm for unimplemented compat syscalls
arch/arm64/include/asm/system_misc.h | 1 + arch/arm64/kernel/sys_compat.c | 27 ++++++++++++++++++++++++++- arch/arm64/kernel/traps.c | 22 ++++++++++------------ 3 files changed, 37 insertions(+), 13 deletions(-)
Signature · 1 line
2.16.0
PATCH 1/2 arm64: Remove unimplemented syscall log message
Stop printing a (ratelimited) kernel message for each instance of an unimplemented syscall being called. Userland making an unimplemented syscall is not necessarily misbehaviour and to be expected with a current userland running on an older kernel. Also, the current message looks scary to users but does not actually indicate a real problem nor help them narrow down the cause. Just rely on sys_ni_syscall() to return -ENOSYS.
--- arch/arm64/kernel/traps.c | 8 -------- 1 file changed, 8 deletions(-)
arch/arm64/kernel/traps.c +0 -8
@@ -526,14 +526,6 @@ asmlinkage long do_ni_syscall(struct pt_regs *regs) }#endif -if (show_unhandled_signals_ratelimited ()) { -pr_info ("%s[%d]: syscall %d\n" , current->comm, -task_pid_nr (current), regs->syscallno); -dump_instr ("" , regs); -if (user_mode (regs)) -__show_regs (regs); - } -return sys_ni_syscall (); }
Signature · 1 line
2.16.0
PATCH v2 1/2 arm64: Remove unimplemented syscall log message
Quoted 21 lines · Michael Weiser
Stop printing a (ratelimited) kernel message for each instance of an unimplemented syscall being called. Userland making an unimplemented syscall is not necessarily misbehaviour and to be expected with a current userland running on an older kernel. Also, the current message looks scary to users but does not actually indicate a real problem nor help them narrow down the cause. Just rely on
sys_ni_syscall()to return-ENOSYS.Signed-off-by Michael Weiser <[email protected]>--- arch/arm64/kernel/traps.c | 8 -------- 1 file changed, 8 deletions(-)arch/arm64/kernel/traps.c +0
-0@@ -526,14 +526,6 @@ asmlinkage long do_ni_syscall(struct pt_regs *regs) }#endif
arch/arm64/kernel/traps.c asmlinkage long do_ni_syscall(struct pt_regs *regs) · line 530
Quoted 10 lines
arch/arm64/kernel/traps.c +0
-8-if (show_unhandled_signals_ratelimited ()) { -pr_info ("%s[%d]: syscall %d\n" , current->comm, -task_pid_nr (current), regs->syscallno); -dump_instr ("" , regs); -if (user_mode (regs)) -__show_regs (regs); - } -return sys_ni_syscall (); }
I'm also strongly inclined to change the default value of show_unhandled_signals to be zero. I find it odd that it defaults to 1 when it can be changed via proc anyway, although this is consistent with other architectures.
Will
PATCH 2/2 arm64: Mirror arm for unimplemented compat syscalls
In reply to Michael WeiserMirror arm behaviour for unimplemented syscalls: Below 2048 return -ENOSYS. Above 2048 raise SIGILL and print a ratelimited message with details. dump_instr() is made non-static and added to system_misc.h so it can be used in compat_arm_syscall(). Also it is synced with the arm implementation to support thumb instructions.
--- arch/arm64/include/asm/system_misc.h | 1 + arch/arm64/kernel/sys_compat.c | 27 ++++++++++++++++++++++++++- arch/arm64/kernel/traps.c | 14 ++++++++++---- 3 files changed, 37 insertions(+), 5 deletions(-)
arch/arm64/include/asm/system_misc.h +1 -0
@@ -42,6 +42,7 @@ void hook_debug_fault_code(int nr, int (*fn)(unsigned long, unsigned int,struct mm_struct ;extern void show_pte (unsigned long addr);extern void __show_regs (struct pt_regs *); +extern void dump_instr (const char *lvl,struct pt_regs *regs);extern void (*arm_pm_restart)(enum reboot_mode reboot_mode,const char *cmd);
arch/arm64/kernel/sys_compat.c +28 -1
@@ -27,6 +27,7 @@#include <linux/uaccess.h> #include <asm/cacheflush.h> +#include <asm/system_misc.h> #include <asm/unistd.h> static long
@@ -67,6 +68,7 @@ do_compat_cache_op(unsigned long start, unsigned long end, int flags)*/ long compat_arm_syscall (struct pt_regs *regs) { +siginfo_t info;unsigned int no = regs->regs[7 ];switch (no) {
@@ -99,6 +101,31 @@ long compat_arm_syscall(struct pt_regs *regs)return 0 ;default : -return -ENOSYS ; +/* +* Calls 9f00xx..9f07ff are defined to return -ENOSYS +* if not implemented, rather than raising SIGILL. This +* way the calling program can gracefully determine whether +* a feature is supported. +*/ +if ((no &0xffff ) <=0x7ff ) +return -ENOSYS ; +break ; } + +if (show_unhandled_signals_ratelimited ()) { +pr_err ("[%d] %s: arm syscall %d\n" , +task_pid_nr (current), current->comm, no); +dump_instr ("" , regs); +if (user_mode (regs)) +__show_regs (regs); + } + + info.si_signo =SIGILL ; + info.si_errno =0 ; + info.si_code =ILL_ILLTRP ; + info.si_addr = (void __user *)instruction_pointer (regs) - + (compat_thumb_mode (regs) ?2 :4 ); + +arm64_notify_die ("Oops - bad syscall(2)" , regs, &info, no); +return 0 ; }
arch/arm64/kernel/traps.c +10 -4
@@ -67,16 +67,22 @@ static void dump_backtrace_entry(unsigned long where)static void __dump_instr (const char *lvl,struct pt_regs *regs) {unsigned long addr =instruction_pointer (regs); +const int thumb =compat_thumb_mode (regs); +const int width = thumb ?4 :8 ;char str[sizeof ("00000000 " ) *5 +2 +1 ], *p = str;int i; -for (i =-4 ; i <1 ; i++) { +for (i =-4 ; i <1 + !!thumb; i++) {unsigned int val, bad; - bad =get_user (val, &((u32 *)addr)[i]); +if (thumb) + bad =get_user (val, &((u16 *)addr)[i]); +else + bad =get_user (val, &((u32 *)addr)[i]);if (!bad) - p +=sprintf (p, i ==0 ?"(%08x) " :"%08x " , val); + p +=sprintf (p, i ==0 ?"(%0*x) " :"%0*x " , + width, val);else { p +=sprintf (p,"bad PC value" );break ;
@@ -85,7 +91,7 @@ static void __dump_instr(const char *lvl, struct pt_regs *regs)printk ("%sCode: %s\n" , lvl, str); } -static void dump_instr (const char *lvl,struct pt_regs *regs) +void dump_instr (const char *lvl,struct pt_regs *regs) {if (!user_mode (regs)) {mm_segment_t fs =get_fs ();
Signature · 1 line
2.16.0
PATCH v2 2/2 arm64: Mirror arm for unimplemented compat syscalls
Hi Michael,
Quoted 67 lines · Michael Weiser
Mirror arm behaviour for unimplemented syscalls: Below 2048 return
-ENOSYS. Above 2048 raise SIGILL and print a ratelimited message with details.dump_instr()is made non-static and added tosystem_misc.hso it can be used incompat_arm_syscall(). Also it is synced with the arm implementation to support thumb instructions.Signed-off-by Michael Weiser <[email protected]>--- arch/arm64/include/asm/system_misc.h | 1 + arch/arm64/kernel/sys_compat.c | 27 ++++++++++++++++++++++++++- arch/arm64/kernel/traps.c | 14 ++++++++++---- 3 files changed, 37 insertions(+), 5 deletions(-)arch/arm64/include/asm/system_misc.h +1
-0@@ -42,6 +42,7 @@ void hook_debug_fault_code(int nr, int (*fn)(unsigned long, unsigned int,struct mm_struct ;extern void show_pte (unsigned long addr);extern void __show_regs (struct pt_regs *); +extern void dump_instr (const char *lvl,struct pt_regs *regs);extern void (*arm_pm_restart)(enum reboot_mode reboot_mode,const char *cmd);arch/arm64/kernel/sys_compat.c +18
-1@@ -27,6 +27,7 @@#include <linux/uaccess.h> #include <asm/cacheflush.h> +#include <asm/system_misc.h> #include <asm/unistd.h> static long@@ -67,6 +68,7 @@ do_compat_cache_op(unsigned long start, unsigned long end, int flags)*/ long compat_arm_syscall (struct pt_regs *regs) { +siginfo_t info;unsigned int no = regs->regs[7 ];switch (no) {@@ -99,6 +101,31 @@ long compat_arm_syscall(struct pt_regs *regs)return 0 ;default : -return -ENOSYS ; +/* +* Calls 9f00xx..9f07ff are defined to return -ENOSYS +* if not implemented, rather than raising SIGILL. This +* way the calling program can gracefully determine whether +* a feature is supported. +*/ +if ((no &0xffff ) <=0x7ff ) +return -ENOSYS ; +break ; } + +if (show_unhandled_signals_ratelimited ()) { +pr_err ("[%d] %s: arm syscall %d\n" , +task_pid_nr (current), current->comm, no); +dump_instr ("" , regs); +if (user_mode (regs)) +__show_regs (regs);
arch/arm64/kernel/sys_compat.c long compat_arm_syscall(struct pt_regs *regs) · line 130
Quoted 10 lines
arch/arm64/kernel/sys_compat.c +10
-0+ } + + info.si_signo =SIGILL ; + info.si_errno =0 ; + info.si_code =ILL_ILLTRP ; + info.si_addr = (void __user *)instruction_pointer (regs) - + (compat_thumb_mode (regs) ?2 :4 ); + +arm64_notify_die ("Oops - bad syscall(2)" , regs, &info, no); +return 0 ;
Whilst I think it's worth mirroring the SIGILL behaviour here, I don't think we need to both with the show_unhandled_signals_ratelimited() hunk. It's predicated on CONFI_DEBUG_USER for arch/arm/ anyway, so it's something that can be relied upon but really more of a debug aid that we can live without for now.
So I'd suggest simply dropping that hunk and the changes to __dump_instr.
Cheers,
Will
v2 cover arm64: Unimplemented syscall kernel message
In reply to Will DeaconHi Will,
I've dropped the message from the compat change, which makes it much more straight-forward. We are still dropping the offending log message from do_ni_syscall(). The second change now just mirrors the part of arm behaviour in compat_arm_syscall() that raises SIGILL for (most) unimplemented syscalls. Finally show_unhandled_signals is disabled by default.
All are compile-tested as well as manually prodded with some randomly chosen syscall numbers from aarch64 and arm-eabi binaries while running under qemu-system-aarch64. New show_unhandled_signals defaults and enabling via /proc/sys have been tested with a minimal segfaulting test program.
Thanks,
Michael
Michael Weiser (3):
arm64: Remove unimplemented syscall log message
arm64: Mirror arm for unimplemented compat syscalls
arm64: Disable unhandled signal log messages by default
v2:
- drop message printing from compat syscall handling
arch/arm64/kernel/sys_compat.c | 21 ++++++++++++++++++++- arch/arm64/kernel/traps.c | 10 +--------- 2 files changed, 21 insertions(+), 10 deletions(-)
Signature · 1 line
2.16.1
PATCH v2 1/3 arm64: Remove unimplemented syscall log message
Stop printing a (ratelimited) kernel message for each instance of an unimplemented syscall being called. Userland making an unimplemented syscall is not necessarily misbehaviour and to be expected with a current userland running on an older kernel. Also, the current message looks scary to users but does not actually indicate a real problem nor help them narrow down the cause. Just rely on sys_ni_syscall() to return -ENOSYS.
--- arch/arm64/kernel/traps.c | 8 -------- 1 file changed, 8 deletions(-)
arch/arm64/kernel/traps.c +0 -8
@@ -526,14 +526,6 @@ asmlinkage long do_ni_syscall(struct pt_regs *regs) }#endif -if (show_unhandled_signals_ratelimited ()) { -pr_info ("%s[%d]: syscall %d\n" , current->comm, -task_pid_nr (current), regs->syscallno); -dump_instr ("" , regs); -if (user_mode (regs)) -__show_regs (regs); - } -return sys_ni_syscall (); }
Signature · 1 line
2.16.1
PATCH v2 2/3 arm64: Mirror arm for unimplemented compat syscalls
In reply to Michael WeiserMirror arm behaviour for unimplemented syscalls: Below 2048 return -ENOSYS, above 2048 raise SIGILL.
--- arch/arm64/kernel/sys_compat.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
arch/arm64/kernel/sys_compat.c +20 -1
@@ -27,6 +27,7 @@#include <linux/uaccess.h> #include <asm/cacheflush.h> +#include <asm/system_misc.h> #include <asm/unistd.h> static long
@@ -67,6 +68,7 @@ do_compat_cache_op(unsigned long start, unsigned long end, int flags)*/ long compat_arm_syscall (struct pt_regs *regs) { +siginfo_t info;unsigned int no = regs->regs[7 ];switch (no) {
@@ -99,6 +101,23 @@ long compat_arm_syscall(struct pt_regs *regs)return 0 ;default : -return -ENOSYS ; +/* +* Calls 9f00xx..9f07ff are defined to return -ENOSYS +* if not implemented, rather than raising SIGILL. This +* way the calling program can gracefully determine whether +* a feature is supported. +*/ +if ((no &0xffff ) <=0x7ff ) +return -ENOSYS ; +break ; } + + info.si_signo =SIGILL ; + info.si_errno =0 ; + info.si_code =ILL_ILLTRP ; + info.si_addr = (void __user *)instruction_pointer (regs) - + (compat_thumb_mode (regs) ?2 :4 ); + +arm64_notify_die ("Oops - bad syscall(2)" , regs, &info, no); +return 0 ; }
Signature · 1 line
2.16.1
PATCH v2 3/3 arm64: Disable unhandled signal log messages by default
In reply to Michael Weiseraarch64 unhandled signal kernel messages are very verbose, suggesting them to be more of a debugging aid:
sigsegv[33]: unhandled level 2 translation fault (11) at 0x00000000, esr 0x92000046, in sigsegv[400000+71000]
CPU: 1 PID: 33 Comm: sigsegv Tainted: G W 4.15.0-rc3+ #3 Hardware name: linux,dummy-virt (DT) pstate: 60000000 (nZCv daif -PAN -UAO) pc : 0x4003f4 lr : 0x4006bc
sp : 0000fffffe94a060
x29: 0000fffffe94a070 x28: 0000000000000000
x27: 0000000000000000 x26: 0000000000000000
x25: 0000000000000000 x24: 00000000004001b0
x23: 0000000000486ac8 x22: 00000000004001c8
x21: 0000000000000000 x20: 0000000000400be8
x19: 0000000000400b30 x18: 0000000000484728
x17: 000000000865ffc8 x16: 000000000000270f
x15: 00000000000000b0 x14: 0000000000000002
x13: 0000000000000001 x12: 0000000000000000
x11: 0000000000000000 x10: 0008000020008008 x9 : 000000000000000f x8 : ffffffffffffffff x7 : 0004000000000000 x6 : ffffffffffffffff x5 : 0000000000000000 x4 : 0000000000000000 x3 : 00000000004003e4 x2 : 0000fffffe94a1e8 x1 : 000000000000000a x0 : 0000000000000000
Disable them by default, so they can be enabled using /proc/sys/debug/exception-trace.
--- arch/arm64/kernel/traps.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kernel/traps.c +1 -1
@@ -57,7 +57,7 @@ static const char *handler[]= { "Error" }; -int show_unhandled_signals =1 ; +int show_unhandled_signals =0 ;static void dump_backtrace_entry (unsigned long where) {
Signature · 1 line
2.16.1
v2 cover arm64: Unimplemented syscall kernel message
In reply to Michael WeiserHi Michael,
Quoted 7 lines · Michael Weiser
I've dropped the message from the compat change, which makes it much more straight-forward. We are still dropping the offending log message from
do_ni_syscall(). The second change now just mirrors the part of arm behaviour incompat_arm_syscall()that raises SIGILL for (most) unimplemented syscalls. Finallyshow_unhandled_signalsis disabled by default.
Quoted 5 lines
All are compile-tested as well as manually prodded with some randomly chosen syscall numbers from aarch64 and arm-eabi binaries while running under qemu-system-aarch64. New
show_unhandled_signalsdefaults and enabling via/proc/syshave been tested with a minimal segfaulting test program.
Thanks, I'll pick these up for 4.17.
Will