Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc/kernel: Switch to using MAX_ERRNO

Currently on powerpc we have our own #define for the highest (negative)
errno value, called _LAST_ERRNO. This is defined to be 516, for reasons
which are not clear.

The generic code, and x86, use MAX_ERRNO, which is defined to be 4095.

In particular seccomp uses MAX_ERRNO to restrict the value that a
seccomp filter can return.

Currently with the mismatch between _LAST_ERRNO and MAX_ERRNO, a seccomp
tracer wanting to return 600, expecting it to be seen as an error, would
instead find on powerpc that userspace sees a successful syscall with a
return value of 600.

To avoid this inconsistency, switch powerpc to use MAX_ERRNO.

We are somewhat confident that generic syscalls that can return a
non-error value above negative MAX_ERRNO have already been updated to
use force_successful_syscall_return().

I have also checked all the powerpc specific syscalls, and believe that
none of them expect to return a non-error value between -MAX_ERRNO and
-516. So this change should be safe ...

Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Reviewed-by: Kees Cook <keescook@chromium.org>

+5 -5
-2
arch/powerpc/include/uapi/asm/errno.h
··· 6 6 #undef EDEADLOCK 7 7 #define EDEADLOCK 58 /* File locking deadlock error */ 8 8 9 - #define _LAST_ERRNO 516 10 - 11 9 #endif /* _ASM_POWERPC_ERRNO_H */
+2 -1
arch/powerpc/kernel/entry_32.S
··· 20 20 */ 21 21 22 22 #include <linux/errno.h> 23 + #include <linux/err.h> 23 24 #include <linux/sys.h> 24 25 #include <linux/threads.h> 25 26 #include <asm/reg.h> ··· 355 354 SYNC 356 355 MTMSRD(r10) 357 356 lwz r9,TI_FLAGS(r12) 358 - li r8,-_LAST_ERRNO 357 + li r8,-MAX_ERRNO 359 358 andi. r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP|_TIF_USER_WORK_MASK|_TIF_PERSYSCALL_MASK) 360 359 bne- syscall_exit_work 361 360 cmplw 0,r3,r8
+3 -2
arch/powerpc/kernel/entry_64.S
··· 19 19 */ 20 20 21 21 #include <linux/errno.h> 22 + #include <linux/err.h> 22 23 #include <asm/unistd.h> 23 24 #include <asm/processor.h> 24 25 #include <asm/page.h> ··· 208 207 #endif /* CONFIG_PPC_BOOK3E */ 209 208 210 209 ld r9,TI_FLAGS(r12) 211 - li r11,-_LAST_ERRNO 210 + li r11,-MAX_ERRNO 212 211 andi. r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP|_TIF_USER_WORK_MASK|_TIF_PERSYSCALL_MASK) 213 212 bne- syscall_exit_work 214 213 cmpld r3,r11 ··· 278 277 beq+ 0f 279 278 REST_NVGPRS(r1) 280 279 b 2f 281 - 0: cmpld r3,r11 /* r10 is -LAST_ERRNO */ 280 + 0: cmpld r3,r11 /* r11 is -MAX_ERRNO */ 282 281 blt+ 1f 283 282 andi. r0,r9,_TIF_NOERROR 284 283 bne- 1f