ARC: entry: fix off-by-one error in syscall number validation
PATCH 1/1 ARC: entry: fix off-by-one error in syscall number validation
We have NR_syscall syscalls from [0 .. NR_syscall-1]. However the check for invalid syscall number is "> NR_syscall". This off-by-one error erronesously allows "NR_syscall" itself as valid and when passed causes out-of-bounds syscall-call table access leading to crash.
This problem showed up when testing glibc 2.33 (v5.10 kernel capable, includng faccessat2 syscall (439) against a v5.6 kernel with NR_syscalls=439 (0 to 438). Due to the bug, 439 was not returned with -ENOSYS but processed leading to a crash.
--- arch/arc/kernel/entry.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arc/kernel/entry.S +1 -1
@@ -255,7 +255,7 @@ ENTRY(EV_Trap) ;============ Normal syscall case ; syscall num shd not exceed the total system calls avail - cmp r8, NR_syscalls + cmp r8, NR_syscalls - 1 mov.hi r0, -ENOSYS bhi .Lret_from_system_call
Signature · 1 line
2.25.1
arch/arc/kernel/entry.S ENTRY(EV_Trap) · line 260
Quoted 12 lines · Vineet Gupta
arch/arc/kernel/entry.S +1
-1@@ -255,7 +255,7 @@ ENTRY(EV_Trap) ;============ Normal syscall case ; syscall num shd not exceed the total system calls avail - cmp r8, NR_syscalls + cmp r8, NR_syscalls - 1 mov.hi r0, -ENOSYS bhi .Lret_from_system_call
Same problem exists in "syscall Tracing" section:
; Do the Sys Call as we normally would.
; Validate the Sys Call number
cmp r8, NR_syscalls mov.hi r0, -ENOSYS bhi tracesys_exit
Signature · 1 line
Shahab
Quoted 15 lines · Shahab Vahedi
arch/arc/kernel/entry.S ENTRY(EV_Trap) · line 260
Quoted 12 lines · Vineet Gupta
arch/arc/kernel/entry.S +1
-1@@ -255,7 +255,7 @@ ENTRY(EV_Trap) ;============ Normal syscall case ; syscall num shd not exceed the total system calls avail - cmp r8, NR_syscalls + cmp r8, NR_syscalls - 1 mov.hi r0, -ENOSYS bhi .Lret_from_system_callSame problem exists in "syscall Tracing" section:
Quoted 5 lines
; Do the Sys Call as we normally would.
; Validate the Sys Call numbercmp r8, NR_syscalls mov.hi r0, -ENOSYS bhi tracesys_exit
Thanks for spotting this. I'll fix this up and repush (after the ongoing merge window).
-Vineet