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=-5.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=no 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 51FF0C11F68 for ; Fri, 2 Jul 2021 11:49:27 +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 1D2E56120D for ; Fri, 2 Jul 2021 11:49:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1D2E56120D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+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.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc: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=RH0FvoVmwmuV2lIuMnJunV6VIu37Y7N+EhUqna9lo5g=; b=dVYx8T6bQzyfuf 4QbNlSPY0xpRlwh98dcfDbHOq+KvmSxACnxlv8d97uZSrVELFzNGBrKb051r75UnP//bqb+tUkl6I wlruweMzzzkeCr0ZwzizXuNh76BF2FgD0a0P3G3a5cvUnLEEqVsuYivVAiQHeHWlgC8qEQvzZBa2v 3kOB/S6kZgGtBWARUCp+9ITTzsEdeQzA0dmmb3P5l8OLgswbvJVj7tQ85sRbfZmfH8u9VoP52poRu gJKhWxHXhGecW/5zsHAXTS3Rjg8uazqh8T1nIBIzhZrFEcu+lOwxm7BR5sg1EqW7c089kp2ZNX572 fcdaVRAxRKpFABsx18Sw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lzHeV-002wCj-0r; Fri, 02 Jul 2021 11:48:11 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lzHeR-002wCL-SL for linux-arm-kernel@lists.infradead.org; Fri, 02 Jul 2021 11:48:09 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2ED4E61402; Fri, 2 Jul 2021 11:48:05 +0000 (UTC) Date: Fri, 2 Jul 2021 12:48:02 +0100 From: Catalin Marinas To: Lokesh Gidra Cc: Peter Collingbourne , Vincenzo Frascino , Dave Martin , Will Deacon , Andrew Morton , Andrea Arcangeli , Alistair Delva , William McVicker , Evgenii Stepanov , Mitch Phillips , Linux ARM , Linux Memory Management List , stable@vger.kernel.org Subject: Re: [PATCH v2] userfaultfd: preserve user-supplied address tag in struct uffd_msg Message-ID: <20210702114802.GA685@arm.com> References: <20210630232931.3779403-1-pcc@google.com> <20210701155148.GB12484@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210702_044807_971138_2AE69AB2 X-CRM114-Status: GOOD ( 26.96 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Jul 01, 2021 at 10:27:31PM -0700, Lokesh Gidra wrote: > On Thu, Jul 1, 2021 at 10:50 AM Peter Collingbourne wrote: > > On Thu, Jul 1, 2021 at 8:51 AM Catalin Marinas wrote: > > > On Wed, Jun 30, 2021 at 04:29:31PM -0700, Peter Collingbourne wrote: > > > > If a user program uses userfaultfd on ranges of heap memory, it may > > > > end up passing a tagged pointer to the kernel in the range.start > > > > field of the UFFDIO_REGISTER ioctl. This can happen when using an > > > > MTE-capable allocator, or on Android if using the Tagged Pointers > > > > feature for MTE readiness [1]. > > > > > > When we added the tagged addr ABI, we realised it's nearly impossible to > > > sort out all ioctls, so we added a note to the documentation that any > > > address other than pointer to user structures as arguments to ioctl() > > > should be untagged. Arguably, userfaultfd is not a random device but if > > > we place it in the same category as mmap/mremap/brk, those don't allow > > > tagged pointers either. And we do expect some apps to break when they > > > rely on malloc() to return untagged pointers. > > > > Okay, so arguably another approach would be to make userfaultfd > > consistent with mmap/mremap/brk and let the UFFDIO_REGISTER fail if > > given a tagged address. > > This approach also seems reasonable. The problem, as things stand > today, is that UFFDIO_REGISTER doesn't complain when a tagged pointer > is used to register a memory range. But eventually the returned fault > address in messages are untagged. If UFFDIO_REGISTER were to fail on > passing a tagged pointer, then the userspace can address the issue. On the mmap etc. functions we get an error as a side effect of addr being larger than TASK_SIZE (unless explicitly untagged). The userfaultfd_register() function had similar checks but they were relaxed by commit 7d0325749a6c ("userfaultfd: untag user pointers"). I think we should revert the above, or part of it. We did something similar for mmap/mremap/brk when untagging the address broke glibc: commit dcde237319e6 ("mm: Avoid creating virtual address aliases in brk()/mmap()/mremap()"). -- Catalin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel