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

MIPS: Fix buffer overflow in syscall_get_arguments()

Since commit 4c21b8fd8f14 ("MIPS: seccomp: Handle indirect system calls
(o32)"), syscall_get_arguments() attempts to handle o32 indirect syscall
arguments by incrementing both the start argument number and the number
of arguments to fetch. However only the start argument number needs to
be incremented. The number of arguments does not change, they're just
shifted up by one, and in fact the output array is provided by the
caller and is likely only n entries long, so reading more arguments
overflows the output buffer.

In the case of seccomp, this results in it fetching 7 arguments starting
at the 2nd one, which overflows the unsigned long args[6] in
populate_seccomp_data(). This clobbers the $s0 register from
syscall_trace_enter() which __seccomp_phase1_filter() saved onto the
stack, into which syscall_trace_enter() had placed its syscall number
argument. This caused Chromium to crash.

Credit goes to Milko for tracking it down as far as $s0 being clobbered.

Fixes: 4c21b8fd8f14 ("MIPS: seccomp: Handle indirect system calls (o32)")
Reported-by: Milko Leporis <milko.leporis@imgtec.com>
Signed-off-by: James Hogan <james.hogan@imgtec.com>
Cc: linux-mips@linux-mips.org
Cc: <stable@vger.kernel.org> # 3.15-
Patchwork: https://patchwork.linux-mips.org/patch/12213/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>

authored by

James Hogan and committed by
Ralf Baechle
f4dce1ff 36f90b0a

+1 -3
+1 -3
arch/mips/include/asm/syscall.h
··· 101 101 /* O32 ABI syscall() - Either 64-bit with O32 or 32-bit */ 102 102 if ((config_enabled(CONFIG_32BIT) || 103 103 test_tsk_thread_flag(task, TIF_32BIT_REGS)) && 104 - (regs->regs[2] == __NR_syscall)) { 104 + (regs->regs[2] == __NR_syscall)) 105 105 i++; 106 - n++; 107 - } 108 106 109 107 while (n--) 110 108 ret |= mips_get_syscall_arg(args++, task, regs, i++);