Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp2503005ybd; Mon, 24 Jun 2019 07:33:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqytw1o5kfZClec17+k5AreKoZhEGDamNgpexOhdi+/Z4ydFunp70qmEPvj1UEuiDOIPay4z X-Received: by 2002:a63:5c15:: with SMTP id q21mr34089256pgb.248.1561386782761; Mon, 24 Jun 2019 07:33:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561386782; cv=none; d=google.com; s=arc-20160816; b=e+ovNDwwnqGah3Jlzvl7JF1VrxEQ2fB7nxJFyWtZDMp7f2IqpLFhFJhbxkXakG5WhU YH+KfwJcsMTjOuloDisfwmGQ6B3yOO3vVZE9IBXT8MVk9kkePihca2kgBDSexWRqbwrF IS9+SEfP2ea2S6SFO9LeiQx4I9md8FC2caKr7BUISui/NT/2FKLDc3VpB6daWjC9h9AI Vjhx0nJpe3zw2zQMDR4gEbVUW63EiLBG/W//FIH179yzaDwyrmJl0x4cAwEZZx6oN/+8 umiflWl40chBZlVJb/ytCamZKHz6/wCCVQ9i9eC01TFHQyMHVUicxsTcAxjcsW82Ohh0 FWfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=gAszyd6Rkh0AyBVnY2MGQeafDGFV/B/Xjwc7nOHGBTU=; b=botBZYg4Ggrd0/Dc108AaPyXjQmTMcYRVBYDnRyfmryQ3cFvFLKReaTgi5isqUY/uu GWJjvlCBKnKU0hnhHYqXJn5y4DPAWqzBt811FFhv2Gw+z7DRw9J2RIq3m9cwgstkSgvp M7oM/wydRu0N4R972qCVWISrWbaExyi+SFnqoeBtyc81uobNAzN9YwoEph7jFFrYvqK/ PBs24HwkWc5I8mMUGDZOupAl7M2BJtXiPi3SVQJGldRL+tiocLx/z3RavwtvGNGadcAP MUvAhOvHFu0lO4XR09d0uVdpJMZ9Zx56WkSYfR0//GzhQa2BgO3diQ7OIgNZw2L2Ih4P sA+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=km7JeQ3v; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a69si10551287pla.178.2019.06.24.07.32.46; Mon, 24 Jun 2019 07:33:02 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=km7JeQ3v; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727984AbfFXOWr (ORCPT + 99 others); Mon, 24 Jun 2019 10:22:47 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:39191 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727868AbfFXOWq (ORCPT ); Mon, 24 Jun 2019 10:22:46 -0400 Received: by mail-pl1-f196.google.com with SMTP id b7so6990064pls.6 for ; Mon, 24 Jun 2019 07:22:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=gAszyd6Rkh0AyBVnY2MGQeafDGFV/B/Xjwc7nOHGBTU=; b=km7JeQ3vyTD2UtwSHCAAp4q4at1sY/ltJPO5wzrrkqMzNLeQZPjXSnOQ7VtkWA81dl HEFVLO9l5VlkdkocDhA+ezC7dKtBn4IeaF4UZLWnOmGq0Ok4r2E9GR7Hoa79HLNOGJVe 0AHZ3EJWZEjcDwF6xOVW5nBJXR6vOtRMH7oBaouWSEKGFrWAIrbWb9kQA+Hlo7SIhUEB uGLPh5fQQfh1ibByxQrZM4UE+cDk+UJmRIBMFqrJwcIDdYtIIT+tU41CsIi86+tplFna 0qMXAZhS5viMtSm5pwtZ6YrDben3dB8l27s4Hd+Xtz7mclZlxhwdWOJHEC5Ft/EzKQyl VZSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=gAszyd6Rkh0AyBVnY2MGQeafDGFV/B/Xjwc7nOHGBTU=; b=fFfGhPtgJ/xYF+JIgutc/P19qsJqFKFk7CZ2J1ZB+OFMQCSwyrJCunlosM50XsqsHb twiE2wF42RsCIhQIy4AYbV2cRWxbi1jco+JkIQDNBkQfYB0RhyhUvLweQX8nCWC+4n+F u1wl8oydTQN55QI3/IuYyplBjPEjBD5NsvDGpI63/bU4LQjp2cVUqkG83n3/mjTvZZME 5YXOnVB/0FNalihZl5h9IA5U/4yUtA061/ftkpzNDKNxVxg3r5T98XRAhTjMJSGIWIIB YpxdRUV4Cra5oXF0aUMNQcQLZXWGwkAfePvGaST0EnJznB6ePnU2TT+nOPCGf3yWt0S0 Ve5w== X-Gm-Message-State: APjAAAWEnNJl6vIM+/yB8evGIS6roR+K0o84C+DVrefqSwI2QdaozF4z 6hJAc2a6Hkli5l7hMlpoKM4Ya4vMAgK1/w5OINAqGQ== X-Received: by 2002:a17:902:4183:: with SMTP id f3mr32179784pld.336.1561386165165; Mon, 24 Jun 2019 07:22:45 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Andrey Konovalov Date: Mon, 24 Jun 2019 16:22:34 +0200 Message-ID: Subject: Re: [PATCH v17 04/15] mm, arm64: untag user pointers passed to memory syscalls To: Khalid Aziz Cc: Linux ARM , Linux Memory Management List , LKML , amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-rdma@vger.kernel.org, linux-media@vger.kernel.org, kvm@vger.kernel.org, "open list:KERNEL SELFTEST FRAMEWORK" , Catalin Marinas , Vincenzo Frascino , Will Deacon , Mark Rutland , Andrew Morton , 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 , 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 Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 19, 2019 at 6:46 PM Khalid Aziz wrote: > > On 6/19/19 9:55 AM, Khalid Aziz wrote: > > On 6/12/19 5:43 AM, Andrey Konovalov wrote: > >> This patch is a part of a series that extends arm64 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: Catalin Marinas > >> Reviewed-by: Kees Cook > >> Signed-off-by: Andrey Konovalov > >> --- > > > > Reviewed-by: Khalid Aziz > > > > > > I would also recommend updating commit log for all the patches in this > series that are changing files under mm/ as opposed to arch/arm64 to not > reference arm64 kernel ABI since the change applies to every > architecture. So something along the lines of "This patch is part of a > series that extends kernel ABI to allow......." Sure, will do in v18, thanks! > > -- > Khalid > > > >> 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(-) > >> > >> diff --git a/mm/madvise.c b/mm/madvise.c > >> index 628022e674a7..39b82f8a698f 100644 > >> --- a/mm/madvise.c > >> +++ b/mm/madvise.c > >> @@ -810,6 +810,8 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior) > >> size_t len; > >> struct blk_plug plug; > >> > >> + start = untagged_addr(start); > >> + > >> if (!madvise_behavior_valid(behavior)) > >> return error; > >> > >> diff --git a/mm/mempolicy.c b/mm/mempolicy.c > >> index 01600d80ae01..78e0a88b2680 100644 > >> --- a/mm/mempolicy.c > >> +++ b/mm/mempolicy.c > >> @@ -1360,6 +1360,7 @@ static long kernel_mbind(unsigned long start, unsigned long len, > >> int err; > >> unsigned short mode_flags; > >> > >> + start = untagged_addr(start); > >> mode_flags = mode & MPOL_MODE_FLAGS; > >> mode &= ~MPOL_MODE_FLAGS; > >> if (mode >= MPOL_MAX) > >> @@ -1517,6 +1518,8 @@ static int kernel_get_mempolicy(int __user *policy, > >> int uninitialized_var(pval); > >> nodemask_t nodes; > >> > >> + addr = untagged_addr(addr); > >> + > >> if (nmask != NULL && maxnode < nr_node_ids) > >> return -EINVAL; > >> > >> diff --git a/mm/migrate.c b/mm/migrate.c > >> index f2ecc2855a12..d22c45cf36b2 100644 > >> --- a/mm/migrate.c > >> +++ b/mm/migrate.c > >> @@ -1616,7 +1616,7 @@ static int do_pages_move(struct mm_struct *mm, nodemask_t task_nodes, > >> goto out_flush; > >> if (get_user(node, nodes + i)) > >> goto out_flush; > >> - addr = (unsigned long)p; > >> + addr = (unsigned long)untagged_addr(p); > >> > >> err = -ENODEV; > >> if (node < 0 || node >= MAX_NUMNODES) > >> diff --git a/mm/mincore.c b/mm/mincore.c > >> index c3f058bd0faf..64c322ed845c 100644 > >> --- a/mm/mincore.c > >> +++ b/mm/mincore.c > >> @@ -249,6 +249,8 @@ SYSCALL_DEFINE3(mincore, unsigned long, start, size_t, len, > >> unsigned long pages; > >> unsigned char *tmp; > >> > >> + start = untagged_addr(start); > >> + > >> /* Check the start address: needs to be page-aligned.. */ > >> if (start & ~PAGE_MASK) > >> return -EINVAL;fixup_user_fault > >> diff --git a/mm/mlock.c b/mm/mlock.c > >> index 080f3b36415b..e82609eaa428 100644 > >> --- a/mm/mlock.c > >> +++ b/mm/mlock.c > >> @@ -674,6 +674,8 @@ static __must_check int do_mlock(unsigned long start, size_t len, vm_flags_t fla > >> unsigned long lock_limit; > >> int error = -ENOMEM; > >> > >> + start = untagged_addr(start); > >> + > >> if (!can_do_mlock()) > >> return -EPERM; > >> > >> @@ -735,6 +737,8 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len) > >> { > >> int ret; > >> > >> + start = untagged_addr(start); > >> + > >> len = PAGE_ALIGN(len + (offset_in_page(start))); > >> start &= PAGE_MASK; > >> > >> diff --git a/mm/mprotect.c b/mm/mprotect.c > >> index bf38dfbbb4b4..19f981b733bc 100644 > >> --- a/mm/mprotect.c > >> +++ b/mm/mprotect.c > >> @@ -465,6 +465,8 @@ static int do_mprotect_pkey(unsigned long start, size_t len, > >> const bool rier = (current->personality & READ_IMPLIES_EXEC) && > >> (prot & PROT_READ); > >> > >> + start = untagged_addr(start); > >> + > >> prot &= ~(PROT_GROWSDOWN|PROT_GROWSUP); > >> if (grows == (PROT_GROWSDOWN|PROT_GROWSUP)) /* can't be both */ > >> return -EINVAL; > >> diff --git a/mm/mremap.c b/mm/mremap.c > >> index fc241d23cd97..64c9a3b8be0a 100644 > >> --- a/mm/mremap.c > >> +++ b/mm/mremap.c > >> @@ -606,6 +606,13 @@ 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); > >> + > >> if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE)) > >> return ret; > >> > >> diff --git a/mm/msync.c b/mm/msync.c > >> index ef30a429623a..c3bd3e75f687 100644 > >> --- a/mm/msync.c > >> +++ b/mm/msync.c > >> @@ -37,6 +37,8 @@ SYSCALL_DEFINE3(msync, unsigned long, start, size_t, len, int, flags) > >> int unmapped_error = 0; > >> int error = -EINVAL; > >> > >> + start = untagged_addr(start); > >> + > >> if (flags & ~(MS_ASYNC | MS_INVALIDATE | MS_SYNC)) > >> goto out; > >> if (offset_in_page(start)) > >> > > > > > >