Received: by 10.213.65.68 with SMTP id h4csp97427imn; Thu, 15 Mar 2018 18:32:13 -0700 (PDT) X-Google-Smtp-Source: AG47ELte3NLpxinawyR5Tvqyk6X3xWLg/JJHGXc/RqIaN/PLkRViQhsOmjoI2sKMH9J1/09ynEPN X-Received: by 10.99.120.142 with SMTP id t136mr7608pgc.300.1521163933282; Thu, 15 Mar 2018 18:32:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521163932; cv=none; d=google.com; s=arc-20160816; b=hnAZulNk8lRcXJF/HcQ5BXVMFEgNS+kloy0dtQ+jUnD3eTbvRrUsWBqOYxdy0SCEEd u/5NqBb9Mqw+r5HsCHbP3M7bA4po9hxS9IwJD3nzz8/q1V0CyBxSkpwDkMQMWUvZBr12 k3DqJEerFbiVNydNRAFNA38+b1hGRzd+LYVPrRhnTVjBJfjnOeJKLhtXsd261K9kqZcs bvs3cdPqGFbUyRQYBSF/gR6tZHUGN+PJoBv9mYVNBlGWQAAAEZjWwDwF57s7TUo/dwmO WnRB6Bq6WIB3pvkeZYo/C+PiT+CPyV8fDmzxO4wCBnkd6egtXxVUBbpvEb3HSfOKH6PH 8FHA== 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 :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=ekyUDS5pe8UtlmrU/aTzGk8YIHDTQA/K5pEQuY9CE/4=; b=aIrLt0IRHfiYamkZoOrmGPJ7QfCo2xWpJepapJcpHCD99pznVT2TMQs0NhyP3rq1dp ufDVP1Wu8zAs3eOdEvUnrEowuAerFIBxQwBRkdlUSQZizOTkf2CY0cV9KwZDsKmR7q4u RG8NjlC8Z5KystzVsOTT7lOD9d0A+kZ/25KJww0vo0CPRznftsPqRedSyFaltledcIzf INS1IlkhkdznQRTk0fqklbWAXNFhGrDAMxdJJrlgE9w3pNBPlyyMcokbWj0HaC8Il0gM 5qC8XTtT28UdV6+IbiqGjRsCLEY0MMGnaQpNC3+edZV9LWjbMI1oLG1+H+GThElHbonZ wZOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=txBYmc4Y; 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 z5-v6si4405345plo.727.2018.03.15.18.31.47; Thu, 15 Mar 2018 18:32:12 -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=txBYmc4Y; 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 S1752855AbeCPBLu (ORCPT + 99 others); Thu, 15 Mar 2018 21:11:50 -0400 Received: from mail-yw0-f195.google.com ([209.85.161.195]:41816 "EHLO mail-yw0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751497AbeCPBLr (ORCPT ); Thu, 15 Mar 2018 21:11:47 -0400 Received: by mail-yw0-f195.google.com with SMTP id w12so5948871ywa.8 for ; Thu, 15 Mar 2018 18:11:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=ekyUDS5pe8UtlmrU/aTzGk8YIHDTQA/K5pEQuY9CE/4=; b=txBYmc4YFAhPsCNZPERr8E+1bGitbYhATBIIrBHUYFTgfGct96joUDYyTVCZfzH4q2 CwRDOv1k81wPb574M3+hrsJGWI4GFnvMsKh9tvF/4d7l/S1icBbg12iNZTe3N3lb4neR UyK6m35MOYWoGo/py1PG0FigZBeyKz9L+0mAIh3hEQCvEqG/j/2EKhpUhvbuQWJ1IPXN FdxrUtZ025rt862BdyQ0AAwUDv9g0Ksyffp48bfdIjOVo2/wlsQFMH+j43EotfCRTjOp d/+LtVLLXI7iIoRwI0PW0XvVmjwVoijEW6R8S5ejzxCK8Ha9vQ6c4ys+Pq/jccpOLEOH Bl2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=ekyUDS5pe8UtlmrU/aTzGk8YIHDTQA/K5pEQuY9CE/4=; b=TBsj4DdJXyP5ClvERiO/JzvDlhaUvmgvn39z/pSgc/NAIu0VqBh3UzZTfDr781PMZ7 /eEb/AMDvOv5shqyY4P+I06mIjZ68T/uKuru4dFhWyKSpTygCKQ6/ZMGJLeshGFlS6K0 Mw2I1gfYinZ6OidnaMYQ9KVMnmYi0fhFMiPtcENHyjClLEpOJ/vPGmqIfZ7N90BNEZBq L3UbSZCgxSUsnQBP913KO3yJvA1wYApj4OwSvpxOp+5ceAX3B1JhdGUlJBgOprRoC8YM WP29qiM+sqikhk02rzHV+iCVYnFBXdzLG3m0zTdfAhnLzK5euXlOYl9uzorm3aQhRt6P HnnQ== X-Gm-Message-State: AElRT7FYufl1ARrxrPwwXgmMoyfBcTYl8WDuEN85pKJo5HG+0PTrMo5h eACwFbaKpPuBhTMFn0X89UDOUN1syCl28jdXr+T0rg== X-Received: by 10.129.51.11 with SMTP id z11mr7448031ywz.389.1521162706957; Thu, 15 Mar 2018 18:11:46 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a25:810b:0:0:0:0:0 with HTTP; Thu, 15 Mar 2018 18:11:46 -0700 (PDT) In-Reply-To: <20180314174442.lclslnqc3egfjg4c@armageddon.cambridge.arm.com> References: <20180309155315.4x44sbp3darractt@armageddon.cambridge.arm.com> <20180314174442.lclslnqc3egfjg4c@armageddon.cambridge.arm.com> From: Evgenii Stepanov Date: Thu, 15 Mar 2018 18:11:46 -0700 Message-ID: Subject: Re: [RFC PATCH 3/6] mm, arm64: untag user addresses in memory syscalls To: Catalin Marinas Cc: Andrey Konovalov , Mark Rutland , linux-arch@vger.kernel.org, Jacob Bramley , Arnd Bergmann , Ruben Ayrapetyan , Ramana Radhakrishnan , Will Deacon , LKML , Kostya Serebryany , Dmitry Vyukov , Lee Smith , Robin Murphy , Linux ARM 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, Mar 14, 2018 at 10:44 AM, Catalin Marinas wrote: > On Wed, Mar 14, 2018 at 04:45:20PM +0100, Andrey Konovalov wrote: >> On Fri, Mar 9, 2018 at 6:42 PM, Evgenii Stepanov wrote: >> > On Fri, Mar 9, 2018 at 9:31 AM, Andrey Konovalov wrote: >> >> On Fri, Mar 9, 2018 at 4:53 PM, Catalin Marinas wrote: >> >>> I'm not yet convinced these functions need to allow tagged pointers. >> >>> They are not doing memory accesses but rather dealing with the memory >> >>> range, hence an untagged pointer is better suited. There is probably a >> >>> reason why the "start" argument is "unsigned long" vs "void __user *" >> >>> (in the kernel, not the man page). >> >> >> >> So that would make the user to untag pointers before passing to these syscalls. >> >> >> >> Evgeniy, would that be possible to untag pointers in HWASan before >> >> using memory subsystem syscalls? Is there a reason for untagging them >> >> in the kernel? >> > >> > Generally, no. It's possible to intercept a libc call using symbol >> > interposition, but I don't know how to rewrite arguments of a raw >> > system call other than through ptrace, and that creates more problems >> > than it solves. > > With these patches, we are trying to relax the user/kernel ABI so that > tagged pointers can be passed into the kernel. Since this is a new ABI > (or an extension to the existing one), it might be ok to change the libc > so that the top byte is zeroed on specific syscalls before issuing the > SVC. > > I agree that it is problematic for HWASan if it only relies on > overriding malloc/free. > >> > AFAIU, it's valid for a program to pass an address obtained from >> > malloc or, better, posix_memalign to an mm syscall like mprotect(). >> > These arguments are pointers from the userspace point of view. >> >> Catalin, do you think this is a good reason to have the untagging done >> in the kernel? > > malloc() or posix_memalign() are C library implementations and it's the > C library (or overridden functions) setting a tag on the returned > pointers. Since the TBI hardware feature allows memory accesses with a > non-zero tag, we could allow them in the kernel for syscalls performing > such accesses on behalf of the user (e.g. get_user/put_user would not > need to clear the tag). > > madvise(), OTOH, does not perform a memory access on behalf of the user, > it's just advising the kernel about a range of virtual addresses. That's > where I think, from an ABI perspective, it doesn't make much sense to > allow tags into the kernel for these syscalls (even if it's simpler from > a user space perspective). > > (but I don't have a very strong opinion on this ;)) I don't have a strong opinion on this, either. Ideally, I would like tags to be fully transparent for user space code. MM syscalls used on a malloc/memalign address are not a very common pattern, so it might be OK to not allow tags there. But all such code will have to be changed with explicit knowledge of TBI.