linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/mremap: Add comment explaining the untagging behaviour of mremap()
@ 2020-03-25 11:13 Will Deacon
  2020-03-25 11:23 ` Catalin Marinas
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Will Deacon @ 2020-03-25 11:13 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-arm-kernel, kernel-team, Will Deacon, Catalin Marinas,
	Linus Torvalds

Commit dcde237319e6 ("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().

Cc: Catalin Marinas <catalin.marinas@arm.com>
Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Will Deacon <will@kernel.org>
---
 mm/mremap.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/mm/mremap.c b/mm/mremap.c
index af363063ea23..d28f08a36b96 100644
--- a/mm/mremap.c
+++ b/mm/mremap.c
@@ -606,6 +606,16 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
 	LIST_HEAD(uf_unmap_early);
 	LIST_HEAD(uf_unmap);
 
+	/*
+	 * There is a deliberate asymmetry here: we strip the pointer tag
+	 * from the old address but leave the new address alone. This is
+	 * for consistency with mmap(), where we prevent the creation of
+	 * aliasing mappings in userspace by leaving the tag bits of the
+	 * mapping address intact. A non-zero tag will cause the subsequent
+	 * range checks to reject the address as invalid.
+	 *
+	 * See Documentation/arm64/tagged-address-abi.rst for more information.
+	 */
 	addr = untagged_addr(addr);
 
 	if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
-- 
2.25.1.696.g5e7596f4ac-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm/mremap: Add comment explaining the untagging behaviour of mremap()
  2020-03-25 11:13 [PATCH] mm/mremap: Add comment explaining the untagging behaviour of mremap() Will Deacon
@ 2020-03-25 11:23 ` Catalin Marinas
  2020-03-25 17:33 ` Linus Torvalds
  2020-03-26 11:33 ` Catalin Marinas
  2 siblings, 0 replies; 4+ messages in thread
From: Catalin Marinas @ 2020-03-25 11:23 UTC (permalink / raw)
  To: Will Deacon; +Cc: linux-kernel, linux-arm-kernel, kernel-team, Linus Torvalds

On Wed, Mar 25, 2020 at 11:13:46AM +0000, Will Deacon wrote:
> Commit dcde237319e6 ("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().
> 
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
> Signed-off-by: Will Deacon <will@kernel.org>

Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm/mremap: Add comment explaining the untagging behaviour of mremap()
  2020-03-25 11:13 [PATCH] mm/mremap: Add comment explaining the untagging behaviour of mremap() Will Deacon
  2020-03-25 11:23 ` Catalin Marinas
@ 2020-03-25 17:33 ` Linus Torvalds
  2020-03-26 11:33 ` Catalin Marinas
  2 siblings, 0 replies; 4+ messages in thread
From: Linus Torvalds @ 2020-03-25 17:33 UTC (permalink / raw)
  To: Will Deacon
  Cc: Linux Kernel Mailing List, Linux ARM, Android Kernel Team,
	Catalin Marinas

On Wed, Mar 25, 2020 at 4:13 AM Will Deacon <will@kernel.org> wrote:
>
> Add a comment justifying the untagging behaviour in mremap().

Ack. This makes that odd "do it on one address, not the other" thing clear.

Otherwise I bet somebody would come along in a few years and go "Oh,
people missed that other case".

             Linus

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm/mremap: Add comment explaining the untagging behaviour of mremap()
  2020-03-25 11:13 [PATCH] mm/mremap: Add comment explaining the untagging behaviour of mremap() Will Deacon
  2020-03-25 11:23 ` Catalin Marinas
  2020-03-25 17:33 ` Linus Torvalds
@ 2020-03-26 11:33 ` Catalin Marinas
  2 siblings, 0 replies; 4+ messages in thread
From: Catalin Marinas @ 2020-03-26 11:33 UTC (permalink / raw)
  To: Will Deacon; +Cc: linux-kernel, linux-arm-kernel, kernel-team, Linus Torvalds

On Wed, Mar 25, 2020 at 11:13:46AM +0000, Will Deacon wrote:
> Commit dcde237319e6 ("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().
> 
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
> Signed-off-by: Will Deacon <will@kernel.org>

I queued this patch via the arm64 tree (for 5.7-rc1). Thanks.

-- 
Catalin

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-03-26 11:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-25 11:13 [PATCH] mm/mremap: Add comment explaining the untagging behaviour of mremap() Will Deacon
2020-03-25 11:23 ` Catalin Marinas
2020-03-25 17:33 ` Linus Torvalds
2020-03-26 11:33 ` Catalin Marinas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).