Skip to content

Commit 3e6ef9c

Browse files
0x7f454c46KAGA-KOKO
authored andcommitted
x86/mm: Make mmap(MAP_32BIT) work correctly
mmap(MAP_32BIT) is broken due to the dependency on the TIF_ADDR32 thread flag. For 64bit applications MAP_32BIT will force legacy bottom-up allocations and the 1GB address space restriction even if the application issued a compat syscall, which should not be subject of these restrictions. For 32bit applications, which issue 64bit syscalls the newly introduced mmap base separation into 64-bit and compat bases changed the behaviour because now a 64-bit mapping is returned, but due to the TIF_ADDR32 dependency MAP_32BIT is ignored. Before the separation a 32-bit mapping was returned, so the MAP_32BIT handling was irrelevant. Replace the check for TIF_ADDR32 with a check for the compat syscall. That solves both the 64-bit issuing a compat syscall and the 32-bit issuing a 64-bit syscall problems. [ tglx: Massaged changelog ] Signed-off-by: Dmitry Safonov <[email protected]> Cc: [email protected] Cc: [email protected] Cc: Andy Lutomirski <[email protected]> Cc: Cyrill Gorcunov <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: "Kirill A. Shutemov" <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Thomas Gleixner <[email protected]>
1 parent 1b028f7 commit 3e6ef9c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

arch/x86/kernel/sys_x86_64.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ static unsigned long get_mmap_base(int is_legacy)
115115
static void find_start_end(unsigned long flags, unsigned long *begin,
116116
unsigned long *end)
117117
{
118-
if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
118+
if (!in_compat_syscall() && (flags & MAP_32BIT)) {
119119
/* This is usually used needed to map code in small
120120
model, so it needs to be in the first 31bit. Limit
121121
it to that. This means we need to move the
@@ -191,7 +191,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
191191
return addr;
192192

193193
/* for MAP_32BIT mappings we force the legacy mmap base */
194-
if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
194+
if (!in_compat_syscall() && (flags & MAP_32BIT))
195195
goto bottomup;
196196

197197
/* requesting a specific address */

0 commit comments

Comments
 (0)