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=-13.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_IN_DEF_DKIM_WL 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 DE541C11F69 for ; Wed, 30 Jun 2021 23:29:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8EB10613F8 for ; Wed, 30 Jun 2021 23:29:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8EB10613F8 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 0674E8D01CC; Wed, 30 Jun 2021 19:29:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 03F138D01C8; Wed, 30 Jun 2021 19:29:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E495B8D01CC; Wed, 30 Jun 2021 19:29:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0242.hostedemail.com [216.40.44.242]) by kanga.kvack.org (Postfix) with ESMTP id C1A858D01C8 for ; Wed, 30 Jun 2021 19:29:50 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 8FFC7180269E3 for ; Wed, 30 Jun 2021 23:29:50 +0000 (UTC) X-FDA: 78311984940.17.F957948 Received: from mail-io1-f44.google.com (mail-io1-f44.google.com [209.85.166.44]) by imf12.hostedemail.com (Postfix) with ESMTP id 527C1100009D for ; Wed, 30 Jun 2021 23:29:50 +0000 (UTC) Received: by mail-io1-f44.google.com with SMTP id y76so5235146iof.6 for ; Wed, 30 Jun 2021 16:29:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=EJz2ovF4MUipNe5Dw70xnm7uqlE2Kpwq4GStz4hbbbo=; b=ViAd7w9V8EraTH2cvvPxQcucr59OxWYklRK2x/UWJYO+HOBLxRvlZ4muDcIYhgXPZM OuDIc/1/88lLQomX6I1rv6gEXBDCQX74kNKXXFtuihG5+1E4pJG16q8IUMVDTLDIUTU2 ChMeuMyV0sXzdC+BcjHIIt4eL4MQMdrt1Q2WpgF9up8vyHCZXtbklm4RhVKMTSGhIJAk OIxjugP1Jp4yVzhl61xUa6mqIvjHLbFq8HZDKfXdLEOgSjCiT+NWY499WRKlZSLNIXCP ssUXm6GfV6qBHHZPAAkpcsvu7pH5n5uYEO0ZPDu0odz8WrHKdXc4UoS1Fs9ifT8evIsa CO1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=EJz2ovF4MUipNe5Dw70xnm7uqlE2Kpwq4GStz4hbbbo=; b=Z/oWuoA0Q+tb03w8GETCImdlzvcY4/O5P3XLcNMqUzvMLJWnKns9FaNFTtaDF68SGa 8iTmCkDPRmxL7/pTLHMPWZDohCoaRa4cB2rriOFGzQvr4FD9Ka9Nvhzj5A0J+con3AJS kRQIu8GwM1MBjZOg/FWLO3MneLcBq1vI/ckH+ZvWjBiRFhq0B7LPMk0ceojoj3UHl/Gr IFekxIVqEJFpmAYNIrrpEy1fB6b/dRfHlarwW1R7xMBT1/Iyj4LHrGOLIr1mXBlhpRmf 5EHdSq3mLClt6bN6TJb+Cl5htNPG1wb8Tw+6wkCHnrMrK18J2zlqTjWDEbWaCiqchMKj zwEQ== X-Gm-Message-State: AOAM532/W69YduDyMEeePnSI/QEtGOJ9OIFd0qsKXlxZ8Og8Y0o5rV2S /yv9zHE1hgUARlV5htDIHd6Yy5d38E5je5aNwMA2bg== X-Google-Smtp-Source: ABdhPJx5IIeKemgoobVOSmkOxQRzkNb1VS2JcUs53K0WL/iQCsPcUDWhTQIDjbl0xu7tNQ4Ux7hmCWUWFYowiFta8JI= X-Received: by 2002:a02:cca6:: with SMTP id t6mr11070053jap.36.1625095789504; Wed, 30 Jun 2021 16:29:49 -0700 (PDT) MIME-Version: 1.0 References: <20210629012010.1948546-1-pcc@google.com> <20210630160831.cf30a5cfa1df524aed42f3bd@linux-foundation.org> In-Reply-To: <20210630160831.cf30a5cfa1df524aed42f3bd@linux-foundation.org> From: Peter Collingbourne Date: Wed, 30 Jun 2021 16:29:38 -0700 Message-ID: Subject: Re: [PATCH] userfaultfd: preserve user-supplied address tag in struct uffd_msg To: Andrew Morton Cc: Catalin Marinas , Vincenzo Frascino , Dave Martin , Will Deacon , Andrea Arcangeli , Alistair Delva , Lokesh Gidra , William McVicker , Evgenii Stepanov , Mitch Phillips , Linux ARM , Linux Memory Management List Content-Type: text/plain; charset="UTF-8" Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=ViAd7w9V; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf12.hostedemail.com: domain of pcc@google.com designates 209.85.166.44 as permitted sender) smtp.mailfrom=pcc@google.com X-Rspamd-Server: rspam02 X-Stat-Signature: n3ormreyn3e5q6z13di4sc8mdgwh944h X-Rspamd-Queue-Id: 527C1100009D X-HE-Tag: 1625095790-712699 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 Wed, Jun 30, 2021 at 4:08 PM Andrew Morton wrote: > > 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? Good point. I think this was an oversight in the original tagged address ABI, so the appropriate Fixes would be the one that introduced the prctl(). A stable backport seems reasonable, that's what we're planning to do in our Android kernel branch anyway. Added the tags in v2. Peter 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=-4.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 0BB7FC11F66 for ; Wed, 30 Jun 2021 23:31:34 +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 CC9C7613FD for ; Wed, 30 Jun 2021 23:31:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CC9C7613FD Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.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:Cc:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=6AMCFCSJSWYZwhUKKmyf1R8pFSaA1wEsHvZ8+ExT+Sg=; b=c9VOjD5XTs4PLK IZbHlOW4nBTI2+BV4oTUZ0Nk4L7G9rox3xd+isgulxr0EHL6Eg6GI+oEdUPzBWFkHgygvAhgzFC2l c3ph3tXepJnF9GnfCepHGoFLyh8wp0U/Mj0c5Isp6a0ZG3/rulXoWjJ4nC3zAO4MOC+T0P/yVd1Em wL+WeclxD/yZJnqVXUpiBoYr3/tLUpTD3rEEgzjEqBJKJlEUxDu6/umhkVL9XJMxif5cagmA7985L 0mfvyPDommne+FLB0FCcnxVytqqLTn0zXeHxA1Gpwch9TH3JeHOCLrXA0WsaIdKCiCTg8cShDN08O bIZCCublWWS8YKJNHYWw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lyjeV-00FYYj-H7; Wed, 30 Jun 2021 23:29:55 +0000 Received: from mail-io1-xd32.google.com ([2607:f8b0:4864:20::d32]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lyjeR-00FYXA-K5 for linux-arm-kernel@lists.infradead.org; Wed, 30 Jun 2021 23:29:52 +0000 Received: by mail-io1-xd32.google.com with SMTP id b15so5259287iow.4 for ; Wed, 30 Jun 2021 16:29:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=EJz2ovF4MUipNe5Dw70xnm7uqlE2Kpwq4GStz4hbbbo=; b=ViAd7w9V8EraTH2cvvPxQcucr59OxWYklRK2x/UWJYO+HOBLxRvlZ4muDcIYhgXPZM OuDIc/1/88lLQomX6I1rv6gEXBDCQX74kNKXXFtuihG5+1E4pJG16q8IUMVDTLDIUTU2 ChMeuMyV0sXzdC+BcjHIIt4eL4MQMdrt1Q2WpgF9up8vyHCZXtbklm4RhVKMTSGhIJAk OIxjugP1Jp4yVzhl61xUa6mqIvjHLbFq8HZDKfXdLEOgSjCiT+NWY499WRKlZSLNIXCP ssUXm6GfV6qBHHZPAAkpcsvu7pH5n5uYEO0ZPDu0odz8WrHKdXc4UoS1Fs9ifT8evIsa CO1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=EJz2ovF4MUipNe5Dw70xnm7uqlE2Kpwq4GStz4hbbbo=; b=BactFXKu7aPC0M+h+8Mf1wHeAvWol2vxziQS4UCTLZZu/U7+PBdfC6tr+qCF6WV5ar aQQHihKIvb+Be6B3snnp8/C/8SCQQZRi05cChrC6PAFHt8lurGUH90o4YmfsREiNBYAG 3loEm8q8NPujpYejxAQ9pdnQfguifL6Ti46om80bDqahdVjSSychng8Iy0DdXSvLTol4 jpw6VXwmNG4ZaN9j03qDLEP7Fpwf76dfwiaY4u2raNGbewTv17KcR+EiPvk5yiRzTqsa X3RNhBb+gJK71APVEiQ+zBMFtnk+1yZ47UBwW2dT8zH+d9nc1QxH6N+tiPtp2k+Hfr5Q w+ag== X-Gm-Message-State: AOAM530KvAvqO7rA5qG7xyieXigBin5Vx1qMNfahy/J9EAffT/P+pxrT PLX46Ir4fCknCCDm5WiP21pwP5khsAUwiaDahOY0GA== X-Google-Smtp-Source: ABdhPJx5IIeKemgoobVOSmkOxQRzkNb1VS2JcUs53K0WL/iQCsPcUDWhTQIDjbl0xu7tNQ4Ux7hmCWUWFYowiFta8JI= X-Received: by 2002:a02:cca6:: with SMTP id t6mr11070053jap.36.1625095789504; Wed, 30 Jun 2021 16:29:49 -0700 (PDT) MIME-Version: 1.0 References: <20210629012010.1948546-1-pcc@google.com> <20210630160831.cf30a5cfa1df524aed42f3bd@linux-foundation.org> In-Reply-To: <20210630160831.cf30a5cfa1df524aed42f3bd@linux-foundation.org> From: Peter Collingbourne Date: Wed, 30 Jun 2021 16:29:38 -0700 Message-ID: Subject: Re: [PATCH] userfaultfd: preserve user-supplied address tag in struct uffd_msg To: Andrew Morton Cc: Catalin Marinas , Vincenzo Frascino , Dave Martin , Will Deacon , Andrea Arcangeli , Alistair Delva , Lokesh Gidra , William McVicker , Evgenii Stepanov , Mitch Phillips , Linux ARM , Linux Memory Management List X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210630_162951_707355_E550A47A X-CRM114-Status: GOOD ( 25.40 ) 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 Wed, Jun 30, 2021 at 4:08 PM Andrew Morton wrote: > > 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? Good point. I think this was an oversight in the original tagged address ABI, so the appropriate Fixes would be the one that introduced the prctl(). A stable backport seems reasonable, that's what we're planning to do in our Android kernel branch anyway. Added the tags in v2. Peter _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel