All of lore.kernel.org
 help / color / mirror / Atom feed
* arm64: Unimplemented syscall kernel message
@ 2018-01-21 17:44 Michael Weiser
  2018-01-22 13:18 ` Will Deacon
  0 siblings, 1 reply; 12+ messages in thread
From: Michael Weiser @ 2018-01-21 17:44 UTC (permalink / raw)
  To: linux-arm-kernel

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?
-- 
Thanks,
Michael

^ permalink raw reply	[flat|nested] 12+ messages in thread

* arm64: Unimplemented syscall kernel message
  2018-01-21 17:44 arm64: Unimplemented syscall kernel message Michael Weiser
@ 2018-01-22 13:18 ` Will Deacon
  2018-01-22 21:20   ` [PATCH 0/2] " Michael Weiser
  2018-02-01 22:13   ` [PATCH v2 0/2] arm64: Unimplemented syscall kernel message Michael Weiser
  0 siblings, 2 replies; 12+ messages in thread
From: Will Deacon @ 2018-01-22 13:18 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Michael,

On Sun, Jan 21, 2018 at 06:44:01PM +0100, Michael Weiser wrote:
> 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?

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 0/2] arm64: Unimplemented syscall kernel message
  2018-01-22 13:18 ` Will Deacon
@ 2018-01-22 21:20   ` Michael Weiser
  2018-01-22 21:20     ` [PATCH 1/2] arm64: Remove unimplemented syscall log message Michael Weiser
  2018-01-22 21:20     ` [PATCH 2/2] arm64: Mirror arm for unimplemented compat syscalls Michael Weiser
  2018-02-01 22:13   ` [PATCH v2 0/2] arm64: Unimplemented syscall kernel message Michael Weiser
  1 sibling, 2 replies; 12+ messages in thread
From: Michael Weiser @ 2018-01-22 21:20 UTC (permalink / raw)
  To: linux-arm-kernel

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(-)

-- 
2.16.0

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 1/2] arm64: Remove unimplemented syscall log message
  2018-01-22 21:20   ` [PATCH 0/2] " Michael Weiser
@ 2018-01-22 21:20     ` Michael Weiser
  2018-01-29 15:38       ` Will Deacon
  2018-01-22 21:20     ` [PATCH 2/2] arm64: Mirror arm for unimplemented compat syscalls Michael Weiser
  1 sibling, 1 reply; 12+ messages in thread
From: Michael Weiser @ 2018-01-22 21:20 UTC (permalink / raw)
  To: linux-arm-kernel

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 <michael.weiser@gmx.de>
---
 arch/arm64/kernel/traps.c | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c
index bbb0fde2780e..0ef28b7f6aa7 100644
--- a/arch/arm64/kernel/traps.c
+++ b/arch/arm64/kernel/traps.c
@@ -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();
 }
 
-- 
2.16.0

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 2/2] arm64: Mirror arm for unimplemented compat syscalls
  2018-01-22 21:20   ` [PATCH 0/2] " Michael Weiser
  2018-01-22 21:20     ` [PATCH 1/2] arm64: Remove unimplemented syscall log message Michael Weiser
@ 2018-01-22 21:20     ` Michael Weiser
  2018-01-29 15:37       ` Will Deacon
  1 sibling, 1 reply; 12+ messages in thread
From: Michael Weiser @ 2018-01-22 21:20 UTC (permalink / raw)
  To: linux-arm-kernel

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 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.

Signed-off-by: Michael Weiser <michael.weiser@gmx.de>
---
 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(-)

diff --git a/arch/arm64/include/asm/system_misc.h b/arch/arm64/include/asm/system_misc.h
index 07aa8e3c5630..0f73b6c1ca63 100644
--- a/arch/arm64/include/asm/system_misc.h
+++ b/arch/arm64/include/asm/system_misc.h
@@ -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);
 
diff --git a/arch/arm64/kernel/sys_compat.c b/arch/arm64/kernel/sys_compat.c
index 8b8bbd3eaa52..3a5b3809b671 100644
--- a/arch/arm64/kernel/sys_compat.c
+++ b/arch/arm64/kernel/sys_compat.c
@@ -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;
 }
diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c
index 0ef28b7f6aa7..2ee511243140 100644
--- a/arch/arm64/kernel/traps.c
+++ b/arch/arm64/kernel/traps.c
@@ -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();
-- 
2.16.0

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 2/2] arm64: Mirror arm for unimplemented compat syscalls
  2018-01-22 21:20     ` [PATCH 2/2] arm64: Mirror arm for unimplemented compat syscalls Michael Weiser
@ 2018-01-29 15:37       ` Will Deacon
  0 siblings, 0 replies; 12+ messages in thread
From: Will Deacon @ 2018-01-29 15:37 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Michael,

On Mon, Jan 22, 2018 at 10:20:26PM +0100, Michael Weiser wrote:
> 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 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.
> 
> Signed-off-by: Michael Weiser <michael.weiser@gmx.de>
> ---
>  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(-)
> 
> diff --git a/arch/arm64/include/asm/system_misc.h b/arch/arm64/include/asm/system_misc.h
> index 07aa8e3c5630..0f73b6c1ca63 100644
> --- a/arch/arm64/include/asm/system_misc.h
> +++ b/arch/arm64/include/asm/system_misc.h
> @@ -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);
>  
> diff --git a/arch/arm64/kernel/sys_compat.c b/arch/arm64/kernel/sys_compat.c
> index 8b8bbd3eaa52..3a5b3809b671 100644
> --- a/arch/arm64/kernel/sys_compat.c
> +++ b/arch/arm64/kernel/sys_compat.c
> @@ -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;

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 1/2] arm64: Remove unimplemented syscall log message
  2018-01-22 21:20     ` [PATCH 1/2] arm64: Remove unimplemented syscall log message Michael Weiser
@ 2018-01-29 15:38       ` Will Deacon
  0 siblings, 0 replies; 12+ messages in thread
From: Will Deacon @ 2018-01-29 15:38 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, Jan 22, 2018 at 10:20:25PM +0100, Michael Weiser wrote:
> 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 <michael.weiser@gmx.de>
> ---
>  arch/arm64/kernel/traps.c | 8 --------
>  1 file changed, 8 deletions(-)
> 
> diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c
> index bbb0fde2780e..0ef28b7f6aa7 100644
> --- a/arch/arm64/kernel/traps.c
> +++ b/arch/arm64/kernel/traps.c
> @@ -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();
>  }

Acked-by: Will Deacon <will.deacon@arm.com>

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 0/2] arm64: Unimplemented syscall kernel message
  2018-01-22 13:18 ` Will Deacon
  2018-01-22 21:20   ` [PATCH 0/2] " Michael Weiser
@ 2018-02-01 22:13   ` Michael Weiser
  2018-02-01 22:13     ` [PATCH v2 1/3] arm64: Remove unimplemented syscall log message Michael Weiser
                       ` (3 more replies)
  1 sibling, 4 replies; 12+ messages in thread
From: Michael Weiser @ 2018-02-01 22:13 UTC (permalink / raw)
  To: linux-arm-kernel

Hi 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(-)

-- 
2.16.1

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 1/3] arm64: Remove unimplemented syscall log message
  2018-02-01 22:13   ` [PATCH v2 0/2] arm64: Unimplemented syscall kernel message Michael Weiser
@ 2018-02-01 22:13     ` Michael Weiser
  2018-02-01 22:13     ` [PATCH v2 2/3] arm64: Mirror arm for unimplemented compat syscalls Michael Weiser
                       ` (2 subsequent siblings)
  3 siblings, 0 replies; 12+ messages in thread
From: Michael Weiser @ 2018-02-01 22:13 UTC (permalink / raw)
  To: linux-arm-kernel

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 <michael.weiser@gmx.de>
Acked-by: Will Deacon <will.deacon@arm.com>
---
 arch/arm64/kernel/traps.c | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c
index bbb0fde2780e..0ef28b7f6aa7 100644
--- a/arch/arm64/kernel/traps.c
+++ b/arch/arm64/kernel/traps.c
@@ -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();
 }
 
-- 
2.16.1

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2 2/3] arm64: Mirror arm for unimplemented compat syscalls
  2018-02-01 22:13   ` [PATCH v2 0/2] arm64: Unimplemented syscall kernel message Michael Weiser
  2018-02-01 22:13     ` [PATCH v2 1/3] arm64: Remove unimplemented syscall log message Michael Weiser
@ 2018-02-01 22:13     ` Michael Weiser
  2018-02-01 22:13     ` [PATCH v2 3/3] arm64: Disable unhandled signal log messages by default Michael Weiser
  2018-02-19 15:39     ` [PATCH v2 0/2] arm64: Unimplemented syscall kernel message Will Deacon
  3 siblings, 0 replies; 12+ messages in thread
From: Michael Weiser @ 2018-02-01 22:13 UTC (permalink / raw)
  To: linux-arm-kernel

Mirror arm behaviour for unimplemented syscalls: Below 2048 return
-ENOSYS, above 2048 raise SIGILL.

Signed-off-by: Michael Weiser <michael.weiser@gmx.de>
---
 arch/arm64/kernel/sys_compat.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/kernel/sys_compat.c b/arch/arm64/kernel/sys_compat.c
index 8b8bbd3eaa52..4d5dfbb2c4cb 100644
--- a/arch/arm64/kernel/sys_compat.c
+++ b/arch/arm64/kernel/sys_compat.c
@@ -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;
 }
-- 
2.16.1

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2 3/3] arm64: Disable unhandled signal log messages by default
  2018-02-01 22:13   ` [PATCH v2 0/2] arm64: Unimplemented syscall kernel message Michael Weiser
  2018-02-01 22:13     ` [PATCH v2 1/3] arm64: Remove unimplemented syscall log message Michael Weiser
  2018-02-01 22:13     ` [PATCH v2 2/3] arm64: Mirror arm for unimplemented compat syscalls Michael Weiser
@ 2018-02-01 22:13     ` Michael Weiser
  2018-02-19 15:39     ` [PATCH v2 0/2] arm64: Unimplemented syscall kernel message Will Deacon
  3 siblings, 0 replies; 12+ messages in thread
From: Michael Weiser @ 2018-02-01 22:13 UTC (permalink / raw)
  To: linux-arm-kernel

aarch64 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.

Signed-off-by: Michael Weiser <michael.weiser@gmx.de>
---
 arch/arm64/kernel/traps.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c
index 0ef28b7f6aa7..eb2d15147e8d 100644
--- a/arch/arm64/kernel/traps.c
+++ b/arch/arm64/kernel/traps.c
@@ -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)
 {
-- 
2.16.1

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2 0/2] arm64: Unimplemented syscall kernel message
  2018-02-01 22:13   ` [PATCH v2 0/2] arm64: Unimplemented syscall kernel message Michael Weiser
                       ` (2 preceding siblings ...)
  2018-02-01 22:13     ` [PATCH v2 3/3] arm64: Disable unhandled signal log messages by default Michael Weiser
@ 2018-02-19 15:39     ` Will Deacon
  3 siblings, 0 replies; 12+ messages in thread
From: Will Deacon @ 2018-02-19 15:39 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Michael,

On Thu, Feb 01, 2018 at 11:13:35PM +0100, Michael Weiser wrote:
> 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, I'll pick these up for 4.17.

Will

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2018-02-19 15:39 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-21 17:44 arm64: Unimplemented syscall kernel message Michael Weiser
2018-01-22 13:18 ` Will Deacon
2018-01-22 21:20   ` [PATCH 0/2] " Michael Weiser
2018-01-22 21:20     ` [PATCH 1/2] arm64: Remove unimplemented syscall log message Michael Weiser
2018-01-29 15:38       ` Will Deacon
2018-01-22 21:20     ` [PATCH 2/2] arm64: Mirror arm for unimplemented compat syscalls Michael Weiser
2018-01-29 15:37       ` Will Deacon
2018-02-01 22:13   ` [PATCH v2 0/2] arm64: Unimplemented syscall kernel message Michael Weiser
2018-02-01 22:13     ` [PATCH v2 1/3] arm64: Remove unimplemented syscall log message Michael Weiser
2018-02-01 22:13     ` [PATCH v2 2/3] arm64: Mirror arm for unimplemented compat syscalls Michael Weiser
2018-02-01 22:13     ` [PATCH v2 3/3] arm64: Disable unhandled signal log messages by default Michael Weiser
2018-02-19 15:39     ` [PATCH v2 0/2] arm64: Unimplemented syscall kernel message Will Deacon

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.