From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DFE97C34026 for ; Tue, 18 Feb 2020 12:23:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A9501207FD for ; Tue, 18 Feb 2020 12:23:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A9501207FD Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 417D46B0003; Tue, 18 Feb 2020 07:23:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3C8CE6B0006; Tue, 18 Feb 2020 07:23:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2DE776B0007; Tue, 18 Feb 2020 07:23:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0240.hostedemail.com [216.40.44.240]) by kanga.kvack.org (Postfix) with ESMTP id 15BBB6B0003 for ; Tue, 18 Feb 2020 07:23:22 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id C59792C96 for ; Tue, 18 Feb 2020 12:23:21 +0000 (UTC) X-FDA: 76503163002.08.steam08_577f72e422953 X-HE-Tag: steam08_577f72e422953 X-Filterd-Recvd-Size: 4449 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf19.hostedemail.com (Postfix) with ESMTP for ; Tue, 18 Feb 2020 12:23:21 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5CA681FB; Tue, 18 Feb 2020 04:23:20 -0800 (PST) Received: from arrakis.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 27ACF3F6CF; Tue, 18 Feb 2020 04:23:19 -0800 (PST) From: Catalin Marinas To: linux-mm@kvack.org Cc: linux-arm-kernel@lists.infradead.org, Szabolcs Nagy , Andrey Konovalov , Will Deacon , Andrew Morton , Florian Weimer , Victor Stinner Subject: [PATCH] mm: Avoid creating virtual address aliases in brk()/mmap()/mremap() Date: Tue, 18 Feb 2020 12:23:10 +0000 Message-Id: <20200218122310.72710-1-catalin.marinas@arm.com> X-Mailer: git-send-email 2.25.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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. Remove untagging in the above functions by partially reverting commit ce18d171cb73 ("mm: untag user pointers in mmap/munmap/mremap/brk"). In addition, update the arm64 tagged-address-abi.rst document accordingly. Fixes: ce18d171cb73 ("mm: untag user pointers in mmap/munmap/mremap/brk") Cc: # 5.4.x- Cc: Andrey Konovalov Cc: Will Deacon Cc: Andrew Morton Cc: Florian Weimer Reported-by: Victor Stinner Signed-off-by: Catalin Marinas --- Documentation/arm64/tagged-address-abi.rst | 7 +++++-- mm/mmap.c | 4 ---- mm/mremap.c | 1 - 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Documentation/arm64/tagged-address-abi.rst b/Documentation/a= rm64/tagged-address-abi.rst index d4a85d535bf9..1771a8b5712e 100644 --- a/Documentation/arm64/tagged-address-abi.rst +++ b/Documentation/arm64/tagged-address-abi.rst @@ -44,8 +44,11 @@ The AArch64 Tagged Address ABI has two stages of relax= ation depending how the user addresses are used by the kernel: =20 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 of aliasing with existing + user addresses. =20 2. User addresses accessed by the kernel (e.g. ``write()``). This ABI relaxation is disabled by default and the application thread needs to diff --git a/mm/mmap.c b/mm/mmap.c index 6756b8bb0033..d681a20eb4ea 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -195,8 +195,6 @@ SYSCALL_DEFINE1(brk, unsigned long, brk) bool downgraded =3D false; LIST_HEAD(uf); =20 - brk =3D untagged_addr(brk); - if (down_write_killable(&mm->mmap_sem)) return -EINTR; =20 @@ -1557,8 +1555,6 @@ unsigned long ksys_mmap_pgoff(unsigned long addr, u= nsigned long len, struct file *file =3D NULL; unsigned long retval; =20 - addr =3D untagged_addr(addr); - if (!(flags & MAP_ANONYMOUS)) { audit_mmap_fd(fd, flags); file =3D fget(fd); diff --git a/mm/mremap.c b/mm/mremap.c index 122938dcec15..af363063ea23 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -607,7 +607,6 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned= long, old_len, LIST_HEAD(uf_unmap); =20 addr =3D untagged_addr(addr); - new_addr =3D untagged_addr(new_addr); =20 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE)) return ret;