linux/arch/riscv
Tycho Andersen af33d2433b
riscv: fix seccomp reject syscall code path
If secure_computing() rejected a system call, we were previously setting
the system call number to -1, to indicate to later code that the syscall
failed. However, if something (e.g. a user notification) was sleeping, and
received a signal, we may set a0 to -ERESTARTSYS and re-try the system call
again.

In this case, seccomp "denies" the syscall (because of the signal), and we
would set a7 to -1, thus losing the value of the system call we want to
restart.

Instead, let's return -1 from do_syscall_trace_enter() to indicate that the
syscall was rejected, so we don't clobber the value in case of -ERESTARTSYS
or whatever.

This commit fixes the user_notification_signal seccomp selftest on riscv to
no longer hang. That test expects the system call to be re-issued after the
signal, and it wasn't due to the above bug. Now that it is, everything
works normally.

Note that in the ptrace (tracer) case, the tracer can set the register
values to whatever they want, so we still need to keep the code that
handles out-of-bounds syscalls. However, we can drop the comment.

We can also drop syscall_set_nr(), since it is no longer used anywhere, and
the code that re-loads the value in a7 because of it.

Reported in: https://lore.kernel.org/bpf/CAEn-LTp=ss0Dfv6J00=rCAy+N78U2AmhqJNjfqjr2FDpPYjxEQ@mail.gmail.com/

Reported-by: David Abdurachmanov <david.abdurachmanov@gmail.com>
Signed-off-by: Tycho Andersen <tycho@tycho.ws>
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
2020-03-05 13:58:15 -08:00
..
boot riscv: dts: Add GPIO reboot method to HiFive Unleashed DTS file 2020-03-05 12:27:10 -08:00
configs RISC-V: Select Goldfish RTC driver for QEMU virt machine 2020-03-05 10:48:46 -08:00
include riscv: fix seccomp reject syscall code path 2020-03-05 13:58:15 -08:00
kernel riscv: fix seccomp reject syscall code path 2020-03-05 13:58:15 -08:00
lib riscv: Add KASAN support 2020-01-22 13:09:58 -08:00
mm riscv: Fix range looking for kernel image memblock 2020-03-04 15:11:03 -08:00
net Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next 2019-12-27 14:20:10 -08:00
Kbuild riscv: add arch/riscv/Kbuild 2019-08-30 17:34:00 -07:00
Kconfig riscv: Force flat memory model with no-mmu 2020-03-04 10:38:17 -08:00
Kconfig.debug RISC-V: Remove EARLY_PRINTK support 2018-12-17 10:23:46 -08:00
Kconfig.socs RISC-V: Select Goldfish RTC driver for QEMU virt machine 2020-03-05 10:48:46 -08:00
Makefile riscv: Change code model of module to medany to improve data accessing 2020-03-03 10:27:46 -08:00