Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp495073ybl; Fri, 9 Aug 2019 09:04:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqzNbLaQlxvhOJcSPobqHKemMSI9H6syoAtOfPqcH4IkOCYU9lMSj8PMngo6yGs5UbJJHSyH X-Received: by 2002:a17:90a:21ac:: with SMTP id q41mr10349879pjc.31.1565366651814; Fri, 09 Aug 2019 09:04:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565366651; cv=none; d=google.com; s=arc-20160816; b=V5Ahyokr1AfTdxB17qRZ7houPDL2nqNOavtVaJoRXF6fH1xwxX731QQQnMtiBorX7K lv+DnF/6IEcK2MZRslxOG9MHDCELhsETy8R08b4QTsQLI2HJO7hmLUJSZ5sKuTc35mXj xh4Gp164WZysAQIQ4XZ2ti/wj1KY8JfRnGW8bvQ1P9sXI/F6Oh4kP1hHBSrZxKYLsKip Lt/NrcfcAO5Ge628tsI5bCeybTUsSRQyqi7/JPv31LHRUlkcp/VDUV+9zJtQg4qie97T xzp6XxiUvj9A2nfalNtPQ4x6utN6A6K1LPILyzhD/DZUsi0OpUoq7BqUC1I2QvYDVcRd LUyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=bKQctIR9RQ3N0yUOd7/19BsHR17UqL4s3TSC6lop2qE=; b=bSOFSqV/PGFSPe3NbEGa77nfpjPamNZxJ/Ud9Gw+XRnERcjAxVsCl6cJtziSmCcrmA i4qBg0DzEfGz4T16NJft9MRUkkjVV0J+GpI1fiUwH+fEfzfKZl3ix+CMjaNKZ4wwMpj1 /89a2avNVlXRsxebXowjJuVUO2x8plt1AP5WrLPgDYMNY4LLNIp3LlLqdNHEhgsep3Xz miez3w3dpuLauDJvLIGlO+M2s64wXg5CRM2V+wJh83xZ/yYCDYJ/sGswFMrm6RrGwP3u 9eP0xYM3ZLQidwZMChukqAZvjlk+3g8y7+jROq+hZcg+oY2rwIGkwnvAceMOpo6GOpAO w+Vg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q10si4639267pjq.46.2019.08.09.09.03.52; Fri, 09 Aug 2019 09:04:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2436963AbfHIQDK (ORCPT + 99 others); Fri, 9 Aug 2019 12:03:10 -0400 Received: from foss.arm.com ([217.140.110.172]:49390 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726421AbfHIQDJ (ORCPT ); Fri, 9 Aug 2019 12:03:09 -0400 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 979B315A2; Fri, 9 Aug 2019 09:03:08 -0700 (PDT) Received: from arrakis.emea.arm.com (arrakis.cambridge.arm.com [10.1.196.78]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C67723F575; Fri, 9 Aug 2019 09:03:03 -0700 (PDT) Date: Fri, 9 Aug 2019 17:03:01 +0100 From: Catalin Marinas To: Andrey Konovalov , Andrew Morton Cc: linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-rdma@vger.kernel.org, linux-media@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Vincenzo Frascino , Will Deacon , Mark Rutland , Greg Kroah-Hartman , Kees Cook , Yishai Hadas , Felix Kuehling , Alexander Deucher , Christian Koenig , Mauro Carvalho Chehab , Jens Wiklander , Alex Williamson , Leon Romanovsky , Luc Van Oostenryck , Dave Martin , Khalid Aziz , enh , Jason Gunthorpe , Christoph Hellwig , Dmitry Vyukov , Kostya Serebryany , Evgeniy Stepanov , Lee Smith , Ramana Radhakrishnan , Jacob Bramley , Ruben Ayrapetyan , Robin Murphy , Kevin Brodsky , Szabolcs Nagy , Dave Hansen Subject: Re: [PATCH v19 04/15] mm: untag user pointers passed to memory syscalls Message-ID: <20190809160301.GB23083@arrakis.emea.arm.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 23, 2019 at 07:58:41PM +0200, Andrey Konovalov wrote: > This patch is a part of a series that extends kernel ABI to allow to pass > tagged user pointers (with the top byte set to something else other than > 0x00) as syscall arguments. > > This patch allows tagged pointers to be passed to the following memory > syscalls: get_mempolicy, madvise, mbind, mincore, mlock, mlock2, mprotect, > mremap, msync, munlock, move_pages. > > The mmap and mremap syscalls do not currently accept tagged addresses. > Architectures may interpret the tag as a background colour for the > corresponding vma. > > Reviewed-by: Khalid Aziz > Reviewed-by: Vincenzo Frascino > Reviewed-by: Catalin Marinas > Reviewed-by: Kees Cook > Signed-off-by: Andrey Konovalov > --- > mm/madvise.c | 2 ++ > mm/mempolicy.c | 3 +++ > mm/migrate.c | 2 +- > mm/mincore.c | 2 ++ > mm/mlock.c | 4 ++++ > mm/mprotect.c | 2 ++ > mm/mremap.c | 7 +++++++ > mm/msync.c | 2 ++ > 8 files changed, 23 insertions(+), 1 deletion(-) More back and forth discussions on how to specify the exceptions here. I'm proposing just dropping the exceptions and folding in the diff below. Andrew, if you prefer a standalone patch instead, please let me know: ------------------8<---------------------------- From 9a5286acaa638c6a917d96986bf28dad35e24a0c Mon Sep 17 00:00:00 2001 From: Catalin Marinas Date: Fri, 9 Aug 2019 14:21:33 +0100 Subject: [PATCH] fixup! mm: untag user pointers passed to memory syscalls mmap, mremap, munmap, brk added to the list of syscalls that accept tagged pointers. Signed-off-by: Catalin Marinas --- mm/mmap.c | 5 +++++ mm/mremap.c | 6 +----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 7e8c3e8ae75f..b766b633b7ae 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -201,6 +201,8 @@ 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; @@ -1573,6 +1575,8 @@ 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); @@ -2874,6 +2878,7 @@ EXPORT_SYMBOL(vm_munmap); SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len) { + addr = untagged_addr(addr); profile_munmap(addr); return __vm_munmap(addr, len, true); } diff --git a/mm/mremap.c b/mm/mremap.c index 64c9a3b8be0a..1fc8a29fbe3f 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -606,12 +606,8 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len, LIST_HEAD(uf_unmap_early); LIST_HEAD(uf_unmap); - /* - * Architectures may interpret the tag passed to mmap as a background - * colour for the corresponding vma. For mremap we don't allow tagged - * new_addr to preserve similar behaviour to mmap. - */ addr = untagged_addr(addr); + new_addr = untagged_addr(new_addr); if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE)) return ret;