Linux MIPS Architecture development
 help / color / mirror / Atom feed
* [PATCH] MIPS: ptrace: Fix syscall skipping via PTRACE_SYSCALL
@ 2026-07-17 11:27 Thomas Bogendoerfer
  2026-07-18 15:23 ` Oleg Nesterov
  2026-07-21 14:43 ` Philippe Mathieu-Daudé
  0 siblings, 2 replies; 4+ messages in thread
From: Thomas Bogendoerfer @ 2026-07-17 11:27 UTC (permalink / raw)
  To: Oleg Nesterov, James Hogan, Kees Cook, linux-mips, linux-kernel

If tracer wanted to skip a syscall return value was always
overwritten with -ENOSYS. Fix this by checking against original
syscall number and only return -ENOSYS, if it is negative.

Fixes: b6318a903d06 ("MIPS/ptrace: Pick up ptrace/seccomp changed syscalls")
Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
---
 arch/mips/kernel/ptrace.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
index 3f4c94c88124..87102a03b6ea 100644
--- a/arch/mips/kernel/ptrace.c
+++ b/arch/mips/kernel/ptrace.c
@@ -1321,8 +1321,12 @@ long arch_ptrace(struct task_struct *child, long request,
  */
 asmlinkage long syscall_trace_enter(struct pt_regs *regs)
 {
+	long syscall;
+
 	user_exit();
 
+	syscall = current_thread_info()->syscall;
+
 	if (test_thread_flag(TIF_SYSCALL_TRACE)) {
 		if (ptrace_report_syscall_entry(regs))
 			return -1;
@@ -1342,7 +1346,7 @@ asmlinkage long syscall_trace_enter(struct pt_regs *regs)
 	 * Negative syscall numbers are mistaken for rejected syscalls, but
 	 * won't have had the return value set appropriately, so we do so now.
 	 */
-	if (current_thread_info()->syscall < 0)
+	if (syscall < 0)
 		syscall_set_return_value(current, regs, -ENOSYS, 0);
 	return current_thread_info()->syscall;
 }
-- 
2.51.0


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

* Re: [PATCH] MIPS: ptrace: Fix syscall skipping via PTRACE_SYSCALL
  2026-07-17 11:27 [PATCH] MIPS: ptrace: Fix syscall skipping via PTRACE_SYSCALL Thomas Bogendoerfer
@ 2026-07-18 15:23 ` Oleg Nesterov
  2026-07-21 14:43 ` Philippe Mathieu-Daudé
  1 sibling, 0 replies; 4+ messages in thread
From: Oleg Nesterov @ 2026-07-18 15:23 UTC (permalink / raw)
  To: Thomas Bogendoerfer; +Cc: James Hogan, Kees Cook, linux-mips, linux-kernel

I obviously can't ack the mips-specific change, but it looks good to me.

Thomas, thanks again.

Oleg.

On 07/17, Thomas Bogendoerfer wrote:
>
> If tracer wanted to skip a syscall return value was always
> overwritten with -ENOSYS. Fix this by checking against original
> syscall number and only return -ENOSYS, if it is negative.
> 
> Fixes: b6318a903d06 ("MIPS/ptrace: Pick up ptrace/seccomp changed syscalls")
> Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
> ---
>  arch/mips/kernel/ptrace.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
> index 3f4c94c88124..87102a03b6ea 100644
> --- a/arch/mips/kernel/ptrace.c
> +++ b/arch/mips/kernel/ptrace.c
> @@ -1321,8 +1321,12 @@ long arch_ptrace(struct task_struct *child, long request,
>   */
>  asmlinkage long syscall_trace_enter(struct pt_regs *regs)
>  {
> +	long syscall;
> +
>  	user_exit();
>  
> +	syscall = current_thread_info()->syscall;
> +
>  	if (test_thread_flag(TIF_SYSCALL_TRACE)) {
>  		if (ptrace_report_syscall_entry(regs))
>  			return -1;
> @@ -1342,7 +1346,7 @@ asmlinkage long syscall_trace_enter(struct pt_regs *regs)
>  	 * Negative syscall numbers are mistaken for rejected syscalls, but
>  	 * won't have had the return value set appropriately, so we do so now.
>  	 */
> -	if (current_thread_info()->syscall < 0)
> +	if (syscall < 0)
>  		syscall_set_return_value(current, regs, -ENOSYS, 0);
>  	return current_thread_info()->syscall;
>  }
> -- 
> 2.51.0
> 


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

* Re: [PATCH] MIPS: ptrace: Fix syscall skipping via PTRACE_SYSCALL
  2026-07-17 11:27 [PATCH] MIPS: ptrace: Fix syscall skipping via PTRACE_SYSCALL Thomas Bogendoerfer
  2026-07-18 15:23 ` Oleg Nesterov
@ 2026-07-21 14:43 ` Philippe Mathieu-Daudé
  2026-07-21 15:04   ` Thomas Bogendoerfer
  1 sibling, 1 reply; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-07-21 14:43 UTC (permalink / raw)
  To: Thomas Bogendoerfer, Oleg Nesterov, James Hogan, Kees Cook,
	linux-mips, linux-kernel, Jiaxun Yang

Hi Thomas,

+Jiaxun

On 17/7/26 13:27, Thomas Bogendoerfer wrote:
> If tracer wanted to skip a syscall return value was always
> overwritten with -ENOSYS. Fix this by checking against original
> syscall number and only return -ENOSYS, if it is negative.
> 
> Fixes: b6318a903d06 ("MIPS/ptrace: Pick up ptrace/seccomp changed syscalls")

I think you meant:

Fixes: 4370b673ccf2 ("MIPS: scall: Save thread_info.syscall 
unconditionally on entry")

> Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
> ---
>   arch/mips/kernel/ptrace.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
> index 3f4c94c88124..87102a03b6ea 100644
> --- a/arch/mips/kernel/ptrace.c
> +++ b/arch/mips/kernel/ptrace.c
> @@ -1321,8 +1321,12 @@ long arch_ptrace(struct task_struct *child, long request,
>    */
>   asmlinkage long syscall_trace_enter(struct pt_regs *regs)
>   {
> +	long syscall;
> +
>   	user_exit();
>   
> +	syscall = current_thread_info()->syscall;
> +
>   	if (test_thread_flag(TIF_SYSCALL_TRACE)) {
>   		if (ptrace_report_syscall_entry(regs))
>   			return -1;
> @@ -1342,7 +1346,7 @@ asmlinkage long syscall_trace_enter(struct pt_regs *regs)
>   	 * Negative syscall numbers are mistaken for rejected syscalls, but
>   	 * won't have had the return value set appropriately, so we do so now.
>   	 */
> -	if (current_thread_info()->syscall < 0)
> +	if (syscall < 0)
>   		syscall_set_return_value(current, regs, -ENOSYS, 0);
>   	return current_thread_info()->syscall;
>   }

Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>


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

* Re: [PATCH] MIPS: ptrace: Fix syscall skipping via PTRACE_SYSCALL
  2026-07-21 14:43 ` Philippe Mathieu-Daudé
@ 2026-07-21 15:04   ` Thomas Bogendoerfer
  0 siblings, 0 replies; 4+ messages in thread
From: Thomas Bogendoerfer @ 2026-07-21 15:04 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Oleg Nesterov, James Hogan, Kees Cook, linux-mips, linux-kernel,
	Jiaxun Yang

On Tue, Jul 21, 2026 at 04:43:40PM +0200, Philippe Mathieu-Daudé wrote:
> Hi Thomas,
> 
> +Jiaxun
> 
> On 17/7/26 13:27, Thomas Bogendoerfer wrote:
> > If tracer wanted to skip a syscall return value was always
> > overwritten with -ENOSYS. Fix this by checking against original
> > syscall number and only return -ENOSYS, if it is negative.
> > 
> > Fixes: b6318a903d06 ("MIPS/ptrace: Pick up ptrace/seccomp changed syscalls")
> 
> I think you meant:
> 
> Fixes: 4370b673ccf2 ("MIPS: scall: Save thread_info.syscall unconditionally
> on entry")

no it was already broken before that commit.

b6318a903d06 reloads syscall number after tracehook_report_syscall_entry() so
the check for negative syscall is done with the "manipulated" syscall number.
And it the syscall should be skipped that number is -1.

Thomas.

-- 
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]

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

end of thread, other threads:[~2026-07-21 15:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-17 11:27 [PATCH] MIPS: ptrace: Fix syscall skipping via PTRACE_SYSCALL Thomas Bogendoerfer
2026-07-18 15:23 ` Oleg Nesterov
2026-07-21 14:43 ` Philippe Mathieu-Daudé
2026-07-21 15:04   ` Thomas Bogendoerfer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox