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=-6.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_NEOMUTT autolearn=unavailable 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 D8A24C282CE for ; Wed, 22 May 2019 11:49:28 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 98F772173C for ; Wed, 22 May 2019 11:49:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="HQikmHko" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 98F772173C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=B78F2U89f+Mu+9L7AWau4Em7OIz5ADrcgvmacCxlDWI=; b=HQikmHkoVyGJXr CRd2/ENiePp2bE8LA2Xm+XfO7pPLq4h9uNDKr6ylVVn1tnczwPmxXHXRo3m1hJqVtMJRuQemyMDBK tvd0useSPFKt3wynI4e1EhcwDCO2Sjr1mDFb6wpxWBOQKvVhwsHWlq5kHb1oyu8mHMZY/g/xrmHX0 m17a+0wReCUdBR6HC8edrZeYCdqwK2qzMonNKPy4TWgdUd9afGg5FzhzZ8TFGmYNW0RvwqcT3zkmE pRCKjhlyUixk0kK2tkYFZ1CcF+DHjD9hkJFOssnPfLqYDWFL6GLt2xAwnnOBFXTPYf1D5hh9OSREu 76X9prc/ccjUMJo0gBRw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hTPkJ-0002fm-Vs; Wed, 22 May 2019 11:49:23 +0000 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70] helo=foss.arm.com) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hTPkH-0002f9-3t for linux-arm-kernel@lists.infradead.org; Wed, 22 May 2019 11:49:22 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7DC8180D; Wed, 22 May 2019 04:49:19 -0700 (PDT) Received: from mbp (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id AE7643F575; Wed, 22 May 2019 04:49:13 -0700 (PDT) Date: Wed, 22 May 2019 12:49:10 +0100 From: Catalin Marinas To: Andrey Konovalov Subject: Re: [PATCH v15 05/17] arms64: untag user pointers passed to memory syscalls Message-ID: <20190522114910.emlckebwzv2qz42i@mbp> References: <00eb4c63fefc054e2c8d626e8fedfca11d7c2600.1557160186.git.andreyknvl@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <00eb4c63fefc054e2c8d626e8fedfca11d7c2600.1557160186.git.andreyknvl@google.com> User-Agent: NeoMutt/20170113 (1.7.2) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190522_044921_170737_F34A0EE3 X-CRM114-Status: GOOD ( 24.38 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , kvm@vger.kernel.org, Szabolcs Nagy , Will Deacon , dri-devel@lists.freedesktop.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, Felix Kuehling , Vincenzo Frascino , Jacob Bramley , Leon Romanovsky , linux-rdma@vger.kernel.org, amd-gfx@lists.freedesktop.org, Dmitry Vyukov , Dave Martin , Evgeniy Stepanov , linux-media@vger.kernel.org, Kevin Brodsky , Kees Cook , Ruben Ayrapetyan , Ramana Radhakrishnan , Alex Williamson , Mauro Carvalho Chehab , linux-arm-kernel@lists.infradead.org, Kostya Serebryany , Greg Kroah-Hartman , Yishai Hadas , linux-kernel@vger.kernel.org, Jens Wiklander , Lee Smith , Alexander Deucher , Andrew Morton , Robin Murphy , Christian Koenig , Luc Van Oostenryck Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, May 06, 2019 at 06:30:51PM +0200, 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: brk, get_mempolicy, madvise, mbind, mincore, mlock, mlock2, > mmap, mmap_pgoff, mprotect, mremap, msync, munlock, munmap, > remap_file_pages, shmat and shmdt. > > This is done by untagging pointers passed to these syscalls in the > prologues of their handlers. I'll go through them one by one to see if we can tighten the expected ABI while having the MTE in mind. > diff --git a/arch/arm64/kernel/sys.c b/arch/arm64/kernel/sys.c > index b44065fb1616..933bb9f3d6ec 100644 > --- a/arch/arm64/kernel/sys.c > +++ b/arch/arm64/kernel/sys.c > @@ -35,10 +35,33 @@ SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len, > { > if (offset_in_page(off) != 0) > return -EINVAL; > - > + addr = untagged_addr(addr); > return ksys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT); > } If user passes a tagged pointer to mmap() and the address is honoured (or MAP_FIXED is given), what is the expected return pointer? Does it need to be tagged with the value from the hint? With MTE, we may want to use this as a request for the default colour of the mapped pages (still under discussion). > +SYSCALL_DEFINE6(arm64_mmap_pgoff, unsigned long, addr, unsigned long, len, > + unsigned long, prot, unsigned long, flags, > + unsigned long, fd, unsigned long, pgoff) > +{ > + addr = untagged_addr(addr); > + return ksys_mmap_pgoff(addr, len, prot, flags, fd, pgoff); > +} We don't have __NR_mmap_pgoff on arm64. > +SYSCALL_DEFINE5(arm64_mremap, unsigned long, addr, unsigned long, old_len, > + unsigned long, new_len, unsigned long, flags, > + unsigned long, new_addr) > +{ > + addr = untagged_addr(addr); > + new_addr = untagged_addr(new_addr); > + return ksys_mremap(addr, old_len, new_len, flags, new_addr); > +} Similar comment as for mmap(), do we want the tag from new_addr to be preserved? In addition, should we check that the two tags are identical or mremap() should become a way to repaint a memory region? > +SYSCALL_DEFINE2(arm64_munmap, unsigned long, addr, size_t, len) > +{ > + addr = untagged_addr(addr); > + return ksys_munmap(addr, len); > +} This looks fine. > +SYSCALL_DEFINE1(arm64_brk, unsigned long, brk) > +{ > + brk = untagged_addr(brk); > + return ksys_brk(brk); > +} I wonder whether brk() should simply not accept tags, and should not return them (similar to the prctl(PR_SET_MM) discussion). We could document this in the ABI requirements. > +SYSCALL_DEFINE5(arm64_get_mempolicy, int __user *, policy, > + unsigned long __user *, nmask, unsigned long, maxnode, > + unsigned long, addr, unsigned long, flags) > +{ > + addr = untagged_addr(addr); > + return ksys_get_mempolicy(policy, nmask, maxnode, addr, flags); > +} > + > +SYSCALL_DEFINE3(arm64_madvise, unsigned long, start, > + size_t, len_in, int, behavior) > +{ > + start = untagged_addr(start); > + return ksys_madvise(start, len_in, behavior); > +} > + > +SYSCALL_DEFINE6(arm64_mbind, unsigned long, start, unsigned long, len, > + unsigned long, mode, const unsigned long __user *, nmask, > + unsigned long, maxnode, unsigned int, flags) > +{ > + start = untagged_addr(start); > + return ksys_mbind(start, len, mode, nmask, maxnode, flags); > +} > + > +SYSCALL_DEFINE2(arm64_mlock, unsigned long, start, size_t, len) > +{ > + start = untagged_addr(start); > + return ksys_mlock(start, len, VM_LOCKED); > +} > + > +SYSCALL_DEFINE2(arm64_mlock2, unsigned long, start, size_t, len) > +{ > + start = untagged_addr(start); > + return ksys_mlock(start, len, VM_LOCKED); > +} > + > +SYSCALL_DEFINE2(arm64_munlock, unsigned long, start, size_t, len) > +{ > + start = untagged_addr(start); > + return ksys_munlock(start, len); > +} > + > +SYSCALL_DEFINE3(arm64_mprotect, unsigned long, start, size_t, len, > + unsigned long, prot) > +{ > + start = untagged_addr(start); > + return ksys_mprotect_pkey(start, len, prot, -1); > +} > + > +SYSCALL_DEFINE3(arm64_msync, unsigned long, start, size_t, len, int, flags) > +{ > + start = untagged_addr(start); > + return ksys_msync(start, len, flags); > +} > + > +SYSCALL_DEFINE3(arm64_mincore, unsigned long, start, size_t, len, > + unsigned char __user *, vec) > +{ > + start = untagged_addr(start); > + return ksys_mincore(start, len, vec); > +} These look fine. > +SYSCALL_DEFINE5(arm64_remap_file_pages, unsigned long, start, > + unsigned long, size, unsigned long, prot, > + unsigned long, pgoff, unsigned long, flags) > +{ > + start = untagged_addr(start); > + return ksys_remap_file_pages(start, size, prot, pgoff, flags); > +} While this has been deprecated for some time, I presume user space still invokes it? > +SYSCALL_DEFINE3(arm64_shmat, int, shmid, char __user *, shmaddr, int, shmflg) > +{ > + shmaddr = untagged_addr(shmaddr); > + return ksys_shmat(shmid, shmaddr, shmflg); > +} > + > +SYSCALL_DEFINE1(arm64_shmdt, char __user *, shmaddr) > +{ > + shmaddr = untagged_addr(shmaddr); > + return ksys_shmdt(shmaddr); > +} Do we actually want to allow shared tagged memory? Who's going to tag it? If not, we can document it as not supported. -- Catalin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel