Skip to content

Commit dcde237

Browse files
ctmarinaswilldeacon
authored andcommitted
mm: Avoid creating virtual address aliases in brk()/mmap()/mremap()
Currently the arm64 kernel ignores the top address byte passed to brk(), mmap() and mremap(). When the user is not aware of the 56-bit address limit or relies on the kernel to return an error, untagging such pointers has the potential to create address aliases in user-space. Passing a tagged address to munmap(), madvise() is permitted since the tagged pointer is expected to be inside an existing mapping. The current behaviour breaks the existing glibc malloc() implementation which relies on brk() with an address beyond 56-bit to be rejected by the kernel. Remove untagging in the above functions by partially reverting commit ce18d17 ("mm: untag user pointers in mmap/munmap/mremap/brk"). In addition, update the arm64 tagged-address-abi.rst document accordingly. Link: https://bugzilla.redhat.com/1797052 Fixes: ce18d17 ("mm: untag user pointers in mmap/munmap/mremap/brk") Cc: <[email protected]> # 5.4.x- Cc: Florian Weimer <[email protected]> Reviewed-by: Andrew Morton <[email protected]> Reported-by: Victor Stinner <[email protected]> Acked-by: Will Deacon <[email protected]> Acked-by: Andrey Konovalov <[email protected]> Signed-off-by: Catalin Marinas <[email protected]> Signed-off-by: Will Deacon <[email protected]>
1 parent ce4a64e commit dcde237

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

Documentation/arm64/tagged-address-abi.rst

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,15 @@ The AArch64 Tagged Address ABI has two stages of relaxation depending
4444
how the user addresses are used by the kernel:
4545

4646
1. User addresses not accessed by the kernel but used for address space
47-
management (e.g. ``mmap()``, ``mprotect()``, ``madvise()``). The use
48-
of valid tagged pointers in this context is always allowed.
47+
management (e.g. ``mprotect()``, ``madvise()``). The use of valid
48+
tagged pointers in this context is allowed with the exception of
49+
``brk()``, ``mmap()`` and the ``new_address`` argument to
50+
``mremap()`` as these have the potential to alias with existing
51+
user addresses.
52+
53+
NOTE: This behaviour changed in v5.6 and so some earlier kernels may
54+
incorrectly accept valid tagged pointers for the ``brk()``,
55+
``mmap()`` and ``mremap()`` system calls.
4956

5057
2. User addresses accessed by the kernel (e.g. ``write()``). This ABI
5158
relaxation is disabled by default and the application thread needs to

mm/mmap.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,6 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
195195
bool downgraded = false;
196196
LIST_HEAD(uf);
197197

198-
brk = untagged_addr(brk);
199-
200198
if (down_write_killable(&mm->mmap_sem))
201199
return -EINTR;
202200

@@ -1557,8 +1555,6 @@ unsigned long ksys_mmap_pgoff(unsigned long addr, unsigned long len,
15571555
struct file *file = NULL;
15581556
unsigned long retval;
15591557

1560-
addr = untagged_addr(addr);
1561-
15621558
if (!(flags & MAP_ANONYMOUS)) {
15631559
audit_mmap_fd(fd, flags);
15641560
file = fget(fd);

mm/mremap.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,6 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
607607
LIST_HEAD(uf_unmap);
608608

609609
addr = untagged_addr(addr);
610-
new_addr = untagged_addr(new_addr);
611610

612611
if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
613612
return ret;

0 commit comments

Comments
 (0)