Commit c2219eda authored by Jamie Garside's avatar Jamie Garside Committed by Michal Simek

microblaze: Fix syscall error recovery for invalid syscall IDs

This patch fixes two bugs in the Microblaze syscall trap handler when an invalid
syscall ID is used.

First, the range check on line 351 only checks for syscall IDs greater than
__NR_syscalls. A negative syscall ID (either passed to `syscall()` or as returned
by `do_syscall_trace_enter()` on error) will still satisfy this test and cause
the Linux kernel to access an invalid memory location and cause a kernel oops.
This has been fixed by also checking for r12 < 0.

Secondly, the current error recovery at line 378 returns using the wrong register
(r15 instead of r14) and does not restore the previous stack state. This has been
fixed by invoking `ret_from_trap` on error, setting r3 to `-ENOSYS`, similar to
what would happen when calling a valid syscall.
Signed-off-by: default avatarJamie Garside <jamie.garside@york.ac.uk>
Signed-off-by: default avatarMichal Simek <michal.simek@xilinx.com>
parent 074fa7e7
...@@ -348,6 +348,7 @@ C_ENTRY(_user_exception): ...@@ -348,6 +348,7 @@ C_ENTRY(_user_exception):
* The LP register should point to the location where the called function * The LP register should point to the location where the called function
* should return. [note that MAKE_SYS_CALL uses label 1] */ * should return. [note that MAKE_SYS_CALL uses label 1] */
/* See if the system call number is valid */ /* See if the system call number is valid */
blti r12, 5f
addi r11, r12, -__NR_syscalls; addi r11, r12, -__NR_syscalls;
bgei r11, 5f; bgei r11, 5f;
/* Figure out which function to use for this system call. */ /* Figure out which function to use for this system call. */
...@@ -375,7 +376,7 @@ C_ENTRY(_user_exception): ...@@ -375,7 +376,7 @@ C_ENTRY(_user_exception):
/* The syscall number is invalid, return an error. */ /* The syscall number is invalid, return an error. */
5: 5:
rtsd r15, 8; /* looks like a normal subroutine return */ braid ret_from_trap
addi r3, r0, -ENOSYS; addi r3, r0, -ENOSYS;
/* Entry point used to return from a syscall/trap */ /* Entry point used to return from a syscall/trap */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment