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

ARC: Fix 32-bit wrap around in access_ok()

Anton reported

| LTP tests syscalls/process_vm_readv01 and process_vm_writev01 fail
| similarly in one testcase test_iov_invalid -> lvec->iov_base.
| Testcase expects errno EFAULT and return code -1,
| but it gets return code 1 and ERRNO is 0 what means success.

Essentially test case was passing a pointer of -1 which access_ok()
was not catching. It was doing [@addr + @sz <= TASK_SIZE] which would
pass for @addr == -1

Fixed that by rewriting as [@addr <= TASK_SIZE - @sz]

Reported-by: Anton Kolesov <Anton.Kolesov@synopsys.com>
Signed-off-by: Vineet Gupta <vgupta@synopsys.com>

+2 -2
+2 -2
arch/arc/include/asm/uaccess.h
··· 43 43 * Because it essentially checks if buffer end is within limit and @len is 44 44 * non-ngeative, which implies that buffer start will be within limit too. 45 45 * 46 - * The reason for rewriting being, for majorit yof cases, @len is generally 46 + * The reason for rewriting being, for majority of cases, @len is generally 47 47 * compile time constant, causing first sub-expression to be compile time 48 48 * subsumed. 49 49 * ··· 53 53 * 54 54 */ 55 55 #define __user_ok(addr, sz) (((sz) <= TASK_SIZE) && \ 56 - (((addr)+(sz)) <= get_fs())) 56 + ((addr) <= (get_fs() - (sz)))) 57 57 #define __access_ok(addr, sz) (unlikely(__kernel_ok) || \ 58 58 likely(__user_ok((addr), (sz)))) 59 59