Skip to contentSkip to conversation

riscv: return -ENOSYS for syscall -1

PATCH In review Andreas Schwab 4 participants 6 messages Dec 21, 2020 – Dec 24, 2020 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 riscv: return -ENOSYS for syscall -1

Properly return -ENOSYS for syscall -1 instead of leaving the return value uninitialized. This fixes the strace teststuite.

Fixes 5340627e3fe0 ("riscv: add support for SECCOMP and SECCOMP_FILTER")
---
 arch/riscv/kernel/entry.S | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
arch/riscv/kernel/entry.S +1 -8
index 524d918f3601..d07763001eb0 100644
@@ -186,14 +186,7 @@ check_syscall_nr:
 	 * Syscall number held in a7.
 	 * If syscall number is above allowed value, redirect to ni_syscall.
 	 */
-	bge a7, t0, 1f
-	/*
-	 * Check if syscall is rejected by tracer, i.e., a7 == -1.
-	 * If yes, we pretend it was executed.
-	 */
-	li t1, -1
-	beq a7, t1, ret_from_syscall_rejected
-	blt a7, t1, 1f
+	bgeu a7, t0, 1f
 	/* Call syscall */
 	la s0, sys_call_table
 	slli t0, a7, RISCV_LGPTR
Signature · 12 lines
2.29.0


-- 
Andreas Schwab, SUSE Labs, [email protected]
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines · Andreas Schwab

Properly return -ENOSYS for syscall -1 instead of leaving the return value uninitialized. This fixes the strace teststuite.

Fixes 5340627e3fe0 ("riscv: add support for SECCOMP and SECCOMP_FILTER")
---
 arch/riscv/kernel/entry.S | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
arch/riscv/kernel/entry.S +0 -0
index 524d918f3601..d07763001eb0 100644
@@ -186,14 +186,7 @@ check_syscall_nr:
 	 * Syscall number held in a7.
 	 * If syscall number is above allowed value, redirect to ni_syscall.

arch/riscv/kernel/entry.S check_syscall_nr: · line 189

Quoted 10 lines
arch/riscv/kernel/entry.S +1 -8
 	 */
-	bge a7, t0, 1f
-	/*
-	 * Check if syscall is rejected by tracer, i.e., a7 == -1.
-	 * If yes, we pretend it was executed.
-	 */
-	li t1, -1
-	beq a7, t1, ret_from_syscall_rejected
-	blt a7, t1, 1f
+	bgeu a7, t0, 1f

IIUC, this is all dead code anyway for the path where seccomp actually rejects the syscall, since it should do the rejection directly in handle_syscall_trace_enter(), which is called above this hunk. So it seems good to me.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

maintainer
#2 lore raw
Quoted 33 lines · On Tue, 22 Dec 2020 08:22:19 PST (-0800), [email protected] wrote:
Quoted 16 lines · Andreas Schwab

Properly return -ENOSYS for syscall -1 instead of leaving the return value uninitialized. This fixes the strace teststuite.

Fixes 5340627e3fe0 ("riscv: add support for SECCOMP and SECCOMP_FILTER")
---
 arch/riscv/kernel/entry.S | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
arch/riscv/kernel/entry.S +0 -0
index 524d918f3601..d07763001eb0 100644
@@ -186,14 +186,7 @@ check_syscall_nr:
 	 * Syscall number held in a7.
 	 * If syscall number is above allowed value, redirect to ni_syscall.

arch/riscv/kernel/entry.S check_syscall_nr: · line 189

Quoted 10 lines
arch/riscv/kernel/entry.S +1 -8
 	 */
-	bge a7, t0, 1f
-	/*
-	 * Check if syscall is rejected by tracer, i.e., a7 == -1.
-	 * If yes, we pretend it was executed.
-	 */
-	li t1, -1
-	beq a7, t1, ret_from_syscall_rejected
-	blt a7, t1, 1f
+	bgeu a7, t0, 1f

IIUC, this is all dead code anyway for the path where seccomp actually rejects the syscall, since it should do the rejection directly in handle_syscall_trace_enter(), which is called above this hunk. So it seems good to me.

Quoted 1 line

Thanks, this is on fixes.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#3 lore raw
In reply to Tycho Andersen
Quoted 24 lines · Tycho Andersen
Quoted 23 lines · Andreas Schwab

Properly return -ENOSYS for syscall -1 instead of leaving the return value uninitialized. This fixes the strace teststuite.

Fixes 5340627e3fe0 ("riscv: add support for SECCOMP and SECCOMP_FILTER")
---
 arch/riscv/kernel/entry.S | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
arch/riscv/kernel/entry.S +0 -6
index 524d918f3601..d07763001eb0 100644
@@ -186,14 +186,7 @@ check_syscall_nr:
 	 * Syscall number held in a7.
 	 * If syscall number is above allowed value, redirect to ni_syscall.
 	 */
-	bge a7, t0, 1f
-	/*
-	 * Check if syscall is rejected by tracer, i.e., a7 == -1.
-	 * If yes, we pretend it was executed.
-	 */
-	li t1, -1
Quoted 8 lines

arch/riscv/kernel/entry.S check_syscall_nr: · line 189

Quoted 3 lines
arch/riscv/kernel/entry.S +1 -2
-	beq a7, t1, ret_from_syscall_rejected
-	blt a7, t1, 1f
+	bgeu a7, t0, 1f

IIUC, this is all dead code anyway for the path where seccomp actually rejects the syscall, since it should do the rejection directly in handle_syscall_trace_enter(), which is called above this hunk. So it seems good to me.

That change really needs to be documented in the commit log, or even better split into a separate patch (still documented of course!).

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

maintainer
#4 lore raw
Quoted 34 lines · Christoph Hellwig
Quoted 24 lines · Tycho Andersen
Quoted 23 lines · Andreas Schwab

Properly return -ENOSYS for syscall -1 instead of leaving the return value uninitialized. This fixes the strace teststuite.

Fixes 5340627e3fe0 ("riscv: add support for SECCOMP and SECCOMP_FILTER")
---
 arch/riscv/kernel/entry.S | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
arch/riscv/kernel/entry.S +0 -6
index 524d918f3601..d07763001eb0 100644
@@ -186,14 +186,7 @@ check_syscall_nr:
 	 * Syscall number held in a7.
 	 * If syscall number is above allowed value, redirect to ni_syscall.
 	 */
-	bge a7, t0, 1f
-	/*
-	 * Check if syscall is rejected by tracer, i.e., a7 == -1.
-	 * If yes, we pretend it was executed.
-	 */
-	li t1, -1
Quoted 8 lines

arch/riscv/kernel/entry.S check_syscall_nr: · line 189

Quoted 3 lines
arch/riscv/kernel/entry.S +1 -2
-	beq a7, t1, ret_from_syscall_rejected
-	blt a7, t1, 1f
+	bgeu a7, t0, 1f

IIUC, this is all dead code anyway for the path where seccomp actually rejects the syscall, since it should do the rejection directly in handle_syscall_trace_enter(), which is called above this hunk. So it seems good to me.

Quoted 2 lines

That change really needs to be documented in the commit log, or even better split into a separate patch (still documented of course!).

Unless I'm missing something, this is already how it works already? handle_syscall_trace_enter is checking the result of do_syscall_trace_enter(), which checks secure_computing(). When secure_computing() rejects the syscall we already ended up rejecting the syscall, so this code wasn't doing anything for the case it was supposed to handle.

It was, however, intercepting syscall number -1 when we weren't rejecting the syscall and directly exiting rather than calling sys_ni_syscall. That would, at a bare minimum, result in an uninitialized return value. It also breaks the pairing of trace_sys_enter() and trace_sys_exit(), which doesn't smell like a good idea.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#5 lore raw
Quoted 35 lines · Palmer Dabbelt
Quoted 34 lines · Christoph Hellwig
Quoted 32 lines · Tycho Andersen
Quoted 16 lines · Andreas Schwab

Properly return -ENOSYS for syscall -1 instead of leaving the return value uninitialized. This fixes the strace teststuite.

Fixes 5340627e3fe0 ("riscv: add support for SECCOMP and SECCOMP_FILTER")
---
 arch/riscv/kernel/entry.S | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
arch/riscv/kernel/entry.S +0 -0
index 524d918f3601..d07763001eb0 100644
@@ -186,14 +186,7 @@ check_syscall_nr:
 	 * Syscall number held in a7.
 	 * If syscall number is above allowed value, redirect to ni_syscall.

arch/riscv/kernel/entry.S check_syscall_nr: · line 189

Quoted 10 lines
arch/riscv/kernel/entry.S +1 -8
 	 */
-	bge a7, t0, 1f
-	/*
-	 * Check if syscall is rejected by tracer, i.e., a7 == -1.
-	 * If yes, we pretend it was executed.
-	 */
-	li t1, -1
-	beq a7, t1, ret_from_syscall_rejected
-	blt a7, t1, 1f
+	bgeu a7, t0, 1f

IIUC, this is all dead code anyway for the path where seccomp actually rejects the syscall, since it should do the rejection directly in handle_syscall_trace_enter(), which is called above this hunk. So it seems good to me.

Quoted 4 lines
Quoted 2 lines

That change really needs to be documented in the commit log, or even better split into a separate patch (still documented of course!).

Unless I'm missing something, this is already how it works already?

Yes, agreed. My musing was mostly just that this is dead code that probably should have been in removed in af33d2433b03 ("riscv: fix seccomp reject syscall code path"), but was overlooked. Maybe this could use a Fixes: tag for that too.

Tycho

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv