Skip to content

Commit b2a84de

Browse files
willdeaconctmarinas
authored andcommitted
mm/mremap: Add comment explaining the untagging behaviour of mremap()
Commit dcde237 ("mm: Avoid creating virtual address aliases in brk()/mmap()/mremap()") changed mremap() so that only the 'old' address is untagged, leaving the 'new' address in the form it was passed from userspace. This prevents the unexpected creation of aliasing virtual mappings in userspace, but looks a bit odd when you read the code. Add a comment justifying the untagging behaviour in mremap(). Reported-by: Linus Torvalds <[email protected]> Acked-by: Linus Torvalds <[email protected]> Reviewed-by: Catalin Marinas <[email protected]> Signed-off-by: Will Deacon <[email protected]> Signed-off-by: Catalin Marinas <[email protected]>
1 parent 44ca0e0 commit b2a84de

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

mm/mremap.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,16 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
606606
LIST_HEAD(uf_unmap_early);
607607
LIST_HEAD(uf_unmap);
608608

609+
/*
610+
* There is a deliberate asymmetry here: we strip the pointer tag
611+
* from the old address but leave the new address alone. This is
612+
* for consistency with mmap(), where we prevent the creation of
613+
* aliasing mappings in userspace by leaving the tag bits of the
614+
* mapping address intact. A non-zero tag will cause the subsequent
615+
* range checks to reject the address as invalid.
616+
*
617+
* See Documentation/arm64/tagged-address-abi.rst for more information.
618+
*/
609619
addr = untagged_addr(addr);
610620

611621
if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))

0 commit comments

Comments
 (0)