Skip to content

Commit

Permalink
mm: Avoid creating virtual address aliases in brk()/mmap()/mremap()
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
ctmarinas authored and willdeacon committed Feb 20, 2020
1 parent ce4a64e commit dcde237
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
11 changes: 9 additions & 2 deletions Documentation/arm64/tagged-address-abi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,15 @@ The AArch64 Tagged Address ABI has two stages of relaxation depending
how the user addresses are used by the kernel:

1. User addresses not accessed by the kernel but used for address space
management (e.g. ``mmap()``, ``mprotect()``, ``madvise()``). The use
of valid tagged pointers in this context is always allowed.
management (e.g. ``mprotect()``, ``madvise()``). The use of valid
tagged pointers in this context is allowed with the exception of
``brk()``, ``mmap()`` and the ``new_address`` argument to
``mremap()`` as these have the potential to alias with existing
user addresses.

NOTE: This behaviour changed in v5.6 and so some earlier kernels may
incorrectly accept valid tagged pointers for the ``brk()``,
``mmap()`` and ``mremap()`` system calls.

2. User addresses accessed by the kernel (e.g. ``write()``). This ABI
relaxation is disabled by default and the application thread needs to
Expand Down
4 changes: 0 additions & 4 deletions mm/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,6 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
bool downgraded = false;
LIST_HEAD(uf);

brk = untagged_addr(brk);

if (down_write_killable(&mm->mmap_sem))
return -EINTR;

Expand Down Expand Up @@ -1557,8 +1555,6 @@ unsigned long ksys_mmap_pgoff(unsigned long addr, unsigned long len,
struct file *file = NULL;
unsigned long retval;

addr = untagged_addr(addr);

if (!(flags & MAP_ANONYMOUS)) {
audit_mmap_fd(fd, flags);
file = fget(fd);
Expand Down
1 change: 0 additions & 1 deletion mm/mremap.c
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,6 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
LIST_HEAD(uf_unmap);

addr = untagged_addr(addr);
new_addr = untagged_addr(new_addr);

if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
return ret;
Expand Down

0 comments on commit dcde237

Please sign in to comment.