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

syscalls: mmap(): use unsigned offset type consistently

Most architectures that implement the old-style mmap() with byte offset
use 'unsigned long' as the type for that offset, but microblaze and
riscv have the off_t type that is shared with userspace, matching the
prototype in include/asm-generic/syscalls.h.

Make this consistent by using an unsigned argument everywhere. This
changes the behavior slightly, as the argument is shifted to a page
number, and an user input with the top bit set would result in a
negative page offset rather than a large one as we use elsewhere.

For riscv, the 32-bit sys_mmap2() definition actually used a custom
type that is different from the global declaration, but this was
missed due to an incorrect type check.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>

+6 -6
+1 -1
arch/csky/kernel/syscall.c
··· 20 20 unsigned long, prot, 21 21 unsigned long, flags, 22 22 unsigned long, fd, 23 - off_t, offset) 23 + unsigned long, offset) 24 24 { 25 25 if (unlikely(offset & (~PAGE_MASK >> 12))) 26 26 return -EINVAL;
+1 -1
arch/loongarch/kernel/syscall.c
··· 22 22 #define __SYSCALL(nr, call) [nr] = (call), 23 23 24 24 SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len, unsigned long, 25 - prot, unsigned long, flags, unsigned long, fd, off_t, offset) 25 + prot, unsigned long, flags, unsigned long, fd, unsigned long, offset) 26 26 { 27 27 if (offset & ~PAGE_MASK) 28 28 return -EINVAL;
+1 -1
arch/microblaze/kernel/sys_microblaze.c
··· 35 35 36 36 SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len, 37 37 unsigned long, prot, unsigned long, flags, unsigned long, fd, 38 - off_t, pgoff) 38 + unsigned long, pgoff) 39 39 { 40 40 if (pgoff & ~PAGE_MASK) 41 41 return -EINVAL;
+2 -2
arch/riscv/kernel/sys_riscv.c
··· 23 23 #ifdef CONFIG_64BIT 24 24 SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len, 25 25 unsigned long, prot, unsigned long, flags, 26 - unsigned long, fd, off_t, offset) 26 + unsigned long, fd, unsigned long, offset) 27 27 { 28 28 return riscv_sys_mmap(addr, len, prot, flags, fd, offset, 0); 29 29 } ··· 32 32 #if defined(CONFIG_32BIT) || defined(CONFIG_COMPAT) 33 33 SYSCALL_DEFINE6(mmap2, unsigned long, addr, unsigned long, len, 34 34 unsigned long, prot, unsigned long, flags, 35 - unsigned long, fd, off_t, offset) 35 + unsigned long, fd, unsigned long, offset) 36 36 { 37 37 /* 38 38 * Note that the shift for mmap2 is constant (12),
+1 -1
include/asm-generic/syscalls.h
··· 19 19 #ifndef sys_mmap 20 20 asmlinkage long sys_mmap(unsigned long addr, unsigned long len, 21 21 unsigned long prot, unsigned long flags, 22 - unsigned long fd, off_t pgoff); 22 + unsigned long fd, unsigned long off); 23 23 #endif 24 24 25 25 #ifndef sys_rt_sigreturn