Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp1497093imp; Fri, 22 Feb 2019 04:54:30 -0800 (PST) X-Google-Smtp-Source: AHgI3IaYVx35txDcRULwV4UwdsAnE3mjRMYEdyxH2hQl6fohKlvE/4W9p2tTL1zOB801HETpO5IS X-Received: by 2002:a63:68ca:: with SMTP id d193mr3825976pgc.53.1550840070588; Fri, 22 Feb 2019 04:54:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550840070; cv=none; d=google.com; s=arc-20160816; b=vNJiBfqx+rj5LB0ZGiXnwNoeDxWxeQ2LWqBw5lwPk4+hR/vvP2HKMvYiZp3UH5PYJe E2x6KckU6vh3f4zTT9hnzvqiZrs25G3MUBisU8tliBaSNMr6MFLcVJh2fpFOrIlk0/Tr 2L+eZl+r9VJnnGPoU3soRIrpPxZ4SV18azdum9CG+JH/GoGOTgw9QYE1NGtvTSmy5VdF +dSfF7iPCO+nngok8xhZKQukzfBlS14TpccwAnjC3DxejVvGfE7I+DyjaKZqUnQWhGXx k7uyQ61ES7Ylm7rtiZc7rLae18iZ1s2FCgpmvYuJUkWrN77WGnK4LUPuK5kQqJKTAnqa 50+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=RU+or7OE+xeHtjxzNrTm9G6GbA97mBxvO1lEjBNgYI4=; b=p9ZCbH+QAS6Rwn+rzDzIJiUJ10O0YNDQs94rqWIcJsPHesAX29kpDZ1yVRPrI/QY8g q/3LjLQCEXybG1eemqq6e6uu9FDt9+K+VG38jofqsiFBuJhW1mjcUIENqnzdDTu58C01 /wNDZoJTl8o3oED9j6mvVfn+UITpzIySvhBjBbTPxRiFdVcsv18ULULEypIt6BRzucOd q2bHW2wE1fpPPJ6JbRHJaIeYFaeQG0Irdl+kkgBAU3gEsnSW9wzqIt+LbibrEMq47A2y yYx9602NfpUfL4d2kDQCBMLxuu38NBvcm36/7GaelWvSVItsnAGKj+BQUtcytixX0kEY lIGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=LNQKgdMo; 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 v1si1267322pgn.583.2019.02.22.04.54.15; Fri, 22 Feb 2019 04:54:30 -0800 (PST) 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=LNQKgdMo; 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 S1726551AbfBVMxn (ORCPT + 99 others); Fri, 22 Feb 2019 07:53:43 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:55921 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727158AbfBVMxk (ORCPT ); Fri, 22 Feb 2019 07:53:40 -0500 Received: by mail-wm1-f66.google.com with SMTP id q187so1864068wme.5 for ; Fri, 22 Feb 2019 04:53:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RU+or7OE+xeHtjxzNrTm9G6GbA97mBxvO1lEjBNgYI4=; b=LNQKgdMoXLkk3vLgnA5PEOiEPK8fsk2VlYlLEiH/StERFEnr+McNBwQfGS9vvmjAMi QHTRwv032nohBRIotdakg7RO2p0g13+gcbIR/f7FS3M7GZntMbCdcTPNEc03llgebNcN A0xBE7hLwmM0ERnATLIP8CvfrkkQpkOb3O8KOUWOCCPwoN2j4oZKfYoZymy/mN+l2/kS hbDRlBHrLDPKxDTD4wcCjFAkP482/9puy/H3Ir4ZTTBolYjCVblrBDM0nO7Cb0lI7eDu hxtdRv+Oi1y5bBqs+F0RzEIPmxeQNS9IDhJoViWLDSaomrwJKnsrpHyIV8LLAV+1+HV0 9SoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RU+or7OE+xeHtjxzNrTm9G6GbA97mBxvO1lEjBNgYI4=; b=ZRfBmKuUyOJk06YJ+ZectlbTLiUsy/QhqAfZelNcQwf7XcE8C7gC1XY31XRD2BypB+ qDRWcn/D7+IswWik5fkf6vZsTk5w70yGLfwBdGqW7L5lCvy9oyc4gmMtlhWMboKCVv29 yIs+RFJXrsIwRqmlJWaTE+Fx/Xui2qQVqKx+bmC+qdh8er0YHu1Nd0B7lPpWIpuMnESP b2lYODaPy6dRnDlDPWt2rMNZzvNgi1b+iA9VQOuZSKDVK6wa6+pYCmRU16mU6VQTpIuL lTQ6xZqkutNoLPnT6p6YFLTf7EA0FHr9gTT7Rq7QhAbXMa19vpKnnzuedMq/MM1i762e ESVQ== X-Gm-Message-State: AHQUAuajF/TjHhHm3nL89L6KeT3z1cpp2OnTfZXRlz0YSQlj7ws9Mezg wnQG76mvRyOb0YVBMrYYplbtxQ== X-Received: by 2002:a7b:c84b:: with SMTP id c11mr2397913wml.108.1550840017928; Fri, 22 Feb 2019 04:53:37 -0800 (PST) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:13:8ce:d7fa:9f4c:492]) by smtp.gmail.com with ESMTPSA id o14sm808209wrp.34.2019.02.22.04.53.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Feb 2019 04:53:36 -0800 (PST) From: Andrey Konovalov To: Catalin Marinas , Will Deacon , Mark Rutland , Robin Murphy , Kees Cook , Kate Stewart , Greg Kroah-Hartman , Andrew Morton , Ingo Molnar , "Kirill A . Shutemov" , Shuah Khan , Vincenzo Frascino , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Dmitry Vyukov , Kostya Serebryany , Evgeniy Stepanov , Lee Smith , Ramana Radhakrishnan , Jacob Bramley , Ruben Ayrapetyan , Chintan Pandya , Luc Van Oostenryck , Dave Martin , Kevin Brodsky , Szabolcs Nagy , Andrey Konovalov Subject: [PATCH v10 04/12] mm, arm64: untag user pointers passed to memory syscalls Date: Fri, 22 Feb 2019 13:53:16 +0100 Message-Id: <3875fa863b755d8cb43afa7bb0fe543e5fd05a5d.1550839937.git.andreyknvl@google.com> X-Mailer: git-send-email 2.21.0.rc0.258.g878e2cd30e-goog In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This commit allows tagged pointers to be passed to the following memory syscalls: madvise, mbind, get_mempolicy, mincore, mlock, mlock2, brk, mmap_pgoff, old_mmap, munmap, remap_file_pages, mprotect, pkey_mprotect, mremap, msync and shmdt. Signed-off-by: Andrey Konovalov --- ipc/shm.c | 2 ++ mm/madvise.c | 2 ++ mm/mempolicy.c | 5 +++++ mm/migrate.c | 1 + mm/mincore.c | 2 ++ mm/mlock.c | 5 +++++ mm/mmap.c | 7 +++++++ mm/mprotect.c | 2 ++ mm/mremap.c | 2 ++ mm/msync.c | 2 ++ 10 files changed, 30 insertions(+) diff --git a/ipc/shm.c b/ipc/shm.c index 0842411cb0e9..f0fd9591d28f 100644 --- a/ipc/shm.c +++ b/ipc/shm.c @@ -1567,6 +1567,7 @@ SYSCALL_DEFINE3(shmat, int, shmid, char __user *, shmaddr, int, shmflg) unsigned long ret; long err; + shmaddr = untagged_addr(shmaddr); err = do_shmat(shmid, shmaddr, shmflg, &ret, SHMLBA); if (err) return err; @@ -1706,6 +1707,7 @@ long ksys_shmdt(char __user *shmaddr) SYSCALL_DEFINE1(shmdt, char __user *, shmaddr) { + shmaddr = untagged_addr(shmaddr); return ksys_shmdt(shmaddr); } diff --git a/mm/madvise.c b/mm/madvise.c index 21a7881a2db4..64e6d34a7f9b 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -809,6 +809,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 ee2bce59d2bf..0b5d5f794f4e 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -1334,6 +1334,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) @@ -1491,6 +1492,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; @@ -1576,6 +1579,8 @@ COMPAT_SYSCALL_DEFINE6(mbind, compat_ulong_t, start, compat_ulong_t, len, unsigned long nr_bits, alloc_size; nodemask_t bm; + start = untagged_addr(start); + nr_bits = min_t(unsigned long, maxnode-1, MAX_NUMNODES); alloc_size = ALIGN(nr_bits, BITS_PER_LONG) / 8; diff --git a/mm/migrate.c b/mm/migrate.c index d4fd680be3b0..b9f414e66af1 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1601,6 +1601,7 @@ static int do_pages_move(struct mm_struct *mm, nodemask_t task_nodes, if (get_user(node, nodes + i)) goto out_flush; addr = (unsigned long)p; + addr = untagged_addr(addr); err = -ENODEV; if (node < 0 || node >= MAX_NUMNODES) diff --git a/mm/mincore.c b/mm/mincore.c index 218099b5ed31..c4a3f4484b6b 100644 --- a/mm/mincore.c +++ b/mm/mincore.c @@ -228,6 +228,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; diff --git a/mm/mlock.c b/mm/mlock.c index 41cc47e28ad6..8fa29e7c0e73 100644 --- a/mm/mlock.c +++ b/mm/mlock.c @@ -715,6 +715,7 @@ static __must_check int do_mlock(unsigned long start, size_t len, vm_flags_t fla SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len) { + start = untagged_addr(start); return do_mlock(start, len, VM_LOCKED); } @@ -722,6 +723,8 @@ SYSCALL_DEFINE3(mlock2, unsigned long, start, size_t, len, int, flags) { vm_flags_t vm_flags = VM_LOCKED; + start = untagged_addr(start); + if (flags & ~MLOCK_ONFAULT) return -EINVAL; @@ -735,6 +738,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/mmap.c b/mm/mmap.c index f901065c4c64..fc8e908a97ba 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -199,6 +199,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; @@ -1571,6 +1573,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); @@ -2869,6 +2873,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); } @@ -2887,6 +2892,8 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size, unsigned long ret = -EINVAL; struct file *file; + start = untagged_addr(start); + pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. See Documentation/vm/remap_file_pages.rst.\n", current->comm, current->pid); diff --git a/mm/mprotect.c b/mm/mprotect.c index 36cb358db170..9d79594dabee 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -578,6 +578,7 @@ static int do_mprotect_pkey(unsigned long start, size_t len, SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len, unsigned long, prot) { + start = untagged_addr(start); return do_mprotect_pkey(start, len, prot, -1); } @@ -586,6 +587,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len, SYSCALL_DEFINE4(pkey_mprotect, unsigned long, start, size_t, len, unsigned long, prot, int, pkey) { + start = untagged_addr(start); return do_mprotect_pkey(start, len, prot, pkey); } diff --git a/mm/mremap.c b/mm/mremap.c index 3320616ed93f..cd0e79c6ce63 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -588,6 +588,8 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len, LIST_HEAD(uf_unmap_early); LIST_HEAD(uf_unmap); + 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)) -- 2.21.0.rc0.258.g878e2cd30e-goog