Skip to content

Commit 6111939

Browse files
CoelacanthusHexpalmer-dabbelt
authored andcommitted
riscv: entry: always initialize regs->a0 to -ENOSYS
Otherwise when the tracer changes syscall number to -1, the kernel fails to initialize a0 with -ENOSYS and subsequently fails to return the error code of the failed syscall to userspace. For example, it will break strace syscall tampering. Fixes: 52449c1 ("riscv: entry: set a0 = -ENOSYS only when syscall != -1") Reported-by: "Dmitry V. Levin" <[email protected]> Reviewed-by: Björn Töpel <[email protected]> Cc: [email protected] Signed-off-by: Celeste Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent ee9a683 commit 6111939

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

arch/riscv/kernel/traps.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ void do_trap_ecall_u(struct pt_regs *regs)
319319

320320
regs->epc += 4;
321321
regs->orig_a0 = regs->a0;
322+
regs->a0 = -ENOSYS;
322323

323324
riscv_v_vstate_discard(regs);
324325

@@ -328,8 +329,7 @@ void do_trap_ecall_u(struct pt_regs *regs)
328329

329330
if (syscall >= 0 && syscall < NR_syscalls)
330331
syscall_handler(regs, syscall);
331-
else if (syscall != -1)
332-
regs->a0 = -ENOSYS;
332+
333333
/*
334334
* Ultimately, this value will get limited by KSTACK_OFFSET_MAX(),
335335
* so the maximum stack offset is 1k bytes (10 bits).

0 commit comments

Comments
 (0)