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.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS 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 937B1C11F66 for ; Wed, 30 Jun 2021 23:08:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0C6B361456 for ; Wed, 30 Jun 2021 23:08:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0C6B361456 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 194716B0095; Wed, 30 Jun 2021 19:08:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 145436B0098; Wed, 30 Jun 2021 19:08:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 00C6E8D01C8; Wed, 30 Jun 2021 19:08:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0052.hostedemail.com [216.40.44.52]) by kanga.kvack.org (Postfix) with ESMTP id D1C566B0095 for ; Wed, 30 Jun 2021 19:08:33 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 97ACD181AEF3C for ; Wed, 30 Jun 2021 23:08:33 +0000 (UTC) X-FDA: 78311931306.14.5D5B99C Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf14.hostedemail.com (Postfix) with ESMTP id 3845B6001A90 for ; Wed, 30 Jun 2021 23:08:33 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id C1ACD61453; Wed, 30 Jun 2021 23:08:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1625094512; bh=TQTgAztecyPmOx3VDfuWb+7ccS+Cor92RoHhoAAUp00=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=K3j3NmmK3hE/iPHiQV/z/RZy0+QQ4r7F70KQEFQuu6+SpcNk+oGkMAMR7lFof1CTO ehmuzxlcr/P11KoDQdqGJWW8XCncFZeJNkLDtfCqCTqq0ffL/Q4WmQkoVZ8R51wj7y msPwyPMklNLX528atavuDO43m5Tpw/DOyi1Rv2PU= Date: Wed, 30 Jun 2021 16:08:31 -0700 From: Andrew Morton To: Peter Collingbourne Cc: Catalin Marinas , Vincenzo Frascino , Dave Martin , Will Deacon , Andrea Arcangeli , Alistair Delva , Lokesh Gidra , William McVicker , Evgenii Stepanov , Mitch Phillips , Linux ARM , linux-mm@kvack.org Subject: Re: [PATCH] userfaultfd: preserve user-supplied address tag in struct uffd_msg Message-Id: <20210630160831.cf30a5cfa1df524aed42f3bd@linux-foundation.org> In-Reply-To: <20210629012010.1948546-1-pcc@google.com> References: <20210629012010.1948546-1-pcc@google.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=K3j3NmmK; dmarc=none; spf=pass (imf14.hostedemail.com: domain of akpm@linux-foundation.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-Rspamd-Server: rspam02 X-Stat-Signature: rhcsokk5fkr3uhz4wcktnrf8qrkn1an5 X-Rspamd-Queue-Id: 3845B6001A90 X-HE-Tag: 1625094513-746823 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 Mon, 28 Jun 2021 18:20:10 -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 a fault subsequently occurs, the tag is stripped from the fault > address returned to the application in the fault.address field > of struct uffd_msg. However, from the application's perspective, > the tagged address *is* the memory address, so if the application > is unaware of memory tags, it may get confused by receiving an > address that is, from its point of view, outside of the bounds of the > allocation. We observed this behavior in the kselftest for userfaultfd > [2] but other applications could have the same problem. > > Fix this by remembering which tag was used to originally register the > userfaultfd and passing that tag back in fault.address. In a future > enhancement, we may want to pass back the original fault address, > but like SA_EXPOSE_TAGBITS, this should be guarded by a flag. Do we have a Fixes: for this? Is a -stable backport warranted?