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.3 required=3.0 tests=BAYES_00, 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 7CEE7C11F69 for ; Fri, 2 Jul 2021 11:48:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 065F06141D for ; Fri, 2 Jul 2021 11:48:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 065F06141D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 58C796B0011; Fri, 2 Jul 2021 07:48:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 515A86B0036; Fri, 2 Jul 2021 07:48:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 38EAE6B005D; Fri, 2 Jul 2021 07:48:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0049.hostedemail.com [216.40.44.49]) by kanga.kvack.org (Postfix) with ESMTP id 0EE726B0011 for ; Fri, 2 Jul 2021 07:48:09 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id AD975808E1A2 for ; Fri, 2 Jul 2021 11:48:08 +0000 (UTC) X-FDA: 78317474256.22.73D0D79 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf21.hostedemail.com (Postfix) with ESMTP id 43711D000193 for ; Fri, 2 Jul 2021 11:48:08 +0000 (UTC) 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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 43711D000193 X-Stat-Signature: a83u3q1t58593i3ubaw6edtwk3c6mnrs Authentication-Results: imf21.hostedemail.com; dkim=none; spf=pass (imf21.hostedemail.com: domain of cmarinas@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=cmarinas@kernel.org; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none) X-HE-Tag: 1625226488-896589 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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