Skip to content

Commit 18ccb0c

Browse files
andreas-schwabwildea01
authored andcommitted
arm64: fix implementation of mmap2 compat syscall
The arm mmap2 syscall takes the offset in units of 4K, thus with 64K pages the offset needs to be scaled to units of pages. Signed-off-by: Andreas Schwab <schwab@suse.de> Signed-off-by: Alexander Graf <agraf@suse.de> [will: removed redundant lr parameter, localised PAGE_SHIFT #if check] Signed-off-by: Will Deacon <will.deacon@arm.com>
1 parent ad08fd4 commit 18ccb0c

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

‎arch/arm64/include/asm/unistd32.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ __SYSCALL(__NR_vfork, sys_vfork)
406406
#define __NR_ugetrlimit 191 /* SuS compliant getrlimit */
407407
__SYSCALL(__NR_ugetrlimit, compat_sys_getrlimit) /* SuS compliant getrlimit */
408408
#define __NR_mmap2 192
409-
__SYSCALL(__NR_mmap2, sys_mmap_pgoff)
409+
__SYSCALL(__NR_mmap2, compat_sys_mmap2_wrapper)
410410
#define __NR_truncate64 193
411411
__SYSCALL(__NR_truncate64, compat_sys_truncate64_wrapper)
412412
#define __NR_ftruncate64 194

‎arch/arm64/kernel/entry32.S‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919
*/
2020

2121
#include <linux/linkage.h>
22+
#include <linux/const.h>
2223

2324
#include <asm/assembler.h>
2425
#include <asm/asm-offsets.h>
26+
#include <asm/errno.h>
27+
#include <asm/page.h>
2528

2629
/*
2730
* System call wrappers for the AArch32 compatibility layer.
@@ -53,6 +56,21 @@ ENTRY(compat_sys_fstatfs64_wrapper)
5356
b compat_sys_fstatfs64
5457
ENDPROC(compat_sys_fstatfs64_wrapper)
5558

59+
/*
60+
* Note: off_4k (w5) is always in units of 4K. If we can't do the
61+
* requested offset because it is not page-aligned, we return -EINVAL.
62+
*/
63+
ENTRY(compat_sys_mmap2_wrapper)
64+
#if PAGE_SHIFT > 12
65+
tst w5, #~PAGE_MASK >> 12
66+
b.ne 1f
67+
lsr w5, w5, #PAGE_SHIFT - 12
68+
#endif
69+
b sys_mmap_pgoff
70+
1: mov x0, #-EINVAL
71+
ret
72+
ENDPROC(compat_sys_mmap2_wrapper)
73+
5674
/*
5775
* Wrappers for AArch32 syscalls that either take 64-bit parameters
5876
* in registers or that take 32-bit parameters which require sign

‎arch/arm64/kernel/sys32.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ asmlinkage long compat_sys_readahead_wrapper(void);
3737
asmlinkage long compat_sys_fadvise64_64_wrapper(void);
3838
asmlinkage long compat_sys_sync_file_range2_wrapper(void);
3939
asmlinkage long compat_sys_fallocate_wrapper(void);
40+
asmlinkage long compat_sys_mmap2_wrapper(void);
4041

4142
#undef __SYSCALL
4243
#define __SYSCALL(nr, sym) [nr] = sym,

0 commit comments

Comments
 (0)