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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id ADFC3C48286 for ; Thu, 1 Feb 2024 17:38:28 +0000 (UTC) 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=d3yXfhWuV9fC8AN+zZ+NrUTHz0LdopXHjZ6/E1YObj8=; b=gQVk0A/Gr9k1Ds K+6e9gSXGTtjPdgzk9n4tUaZijTjV8nBx0mx7mRTatuTO2w+mqHtyg+rPnIvMZ6SClq3OPMmtA1Ui IEn1gSN1PiYowtJSyKgjB2Ho+8dgk6u7Ht+p4RxikoAZKco6+o2RzaAUszcAgcrE2Il9KTM8LEjq1 B8hIWkizAgEwpOdJd8+qj3gh4LgSh+GnDA+hniq4MpRnA5ZOGxxjPOmDDdWk7Z4aYV2pCukvz5DmQ t1n/1Pd+8QmXopWovScGUEdjxVloHk8ouszBb6Shde2v0cW5/o3HzmbeHIa86B9ywzi9+R9QmcUzg fwOHxEGE6iu8ozTfjxqw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rVb0y-00000008pSq-3qar; Thu, 01 Feb 2024 17:38:16 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rVb0v-00000008pQ9-3zBj for linux-arm-kernel@lists.infradead.org; Thu, 01 Feb 2024 17:38:16 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 01D83DA7; Thu, 1 Feb 2024 09:38:55 -0800 (PST) Received: from raptor (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 50C163F738; Thu, 1 Feb 2024 09:38:07 -0800 (PST) Date: Thu, 1 Feb 2024 17:38:04 +0000 From: Alexandru Elisei To: Anshuman Khandual Cc: catalin.marinas@arm.com, will@kernel.org, oliver.upton@linux.dev, maz@kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, arnd@arndb.de, akpm@linux-foundation.org, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, mhiramat@kernel.org, rppt@kernel.org, hughd@google.com, pcc@google.com, steven.price@arm.com, vincenzo.frascino@arm.com, david@redhat.com, eugenis@google.com, kcc@google.com, hyesoo.yu@samsung.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org Subject: Re: [PATCH RFC v3 30/35] arm64: mte: ptrace: Handle pages with missing tag storage Message-ID: References: <20240125164256.4147-1-alexandru.elisei@arm.com> <20240125164256.4147-31-alexandru.elisei@arm.com> <30278898-c4b2-4dd6-ba68-a19575f81a65@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <30278898-c4b2-4dd6-ba68-a19575f81a65@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240201_093814_106952_C7D40A72 X-CRM114-Status: GOOD ( 24.92 ) 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 Hi, On Thu, Feb 01, 2024 at 02:51:39PM +0530, Anshuman Khandual wrote: > > > On 1/25/24 22:12, Alexandru Elisei wrote: > > A page can end up mapped in a MTE enabled VMA without the corresponding tag > > storage block reserved. Tag accesses made by ptrace in this case can lead > > to the wrong tags being read or memory corruption for the process that is > > using the tag storage memory as data. > > > > Reserve tag storage by treating ptrace accesses like a fault. > > > > Signed-off-by: Alexandru Elisei > > --- > > > > Changes since rfc v2: > > > > * New patch, issue reported by Peter Collingbourne. > > > > arch/arm64/kernel/mte.c | 26 ++++++++++++++++++++++++-- > > 1 file changed, 24 insertions(+), 2 deletions(-) > > > > diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c > > index faf09da3400a..b1fa02dad4fd 100644 > > --- a/arch/arm64/kernel/mte.c > > +++ b/arch/arm64/kernel/mte.c > > @@ -412,10 +412,13 @@ static int __access_remote_tags(struct mm_struct *mm, unsigned long addr, > > while (len) { > > struct vm_area_struct *vma; > > unsigned long tags, offset; > > + unsigned int fault_flags; > > + struct page *page; > > + vm_fault_t ret; > > void *maddr; > > - struct page *page = get_user_page_vma_remote(mm, addr, > > - gup_flags, &vma); > > > > +get_page: > > + page = get_user_page_vma_remote(mm, addr, gup_flags, &vma); > > But if there is valid page returned here in the first GUP attempt, will there > still be a subsequent handle_mm_fault() on the same vma and addr ? Only if it's missing tag storage. If it's missing tag storage, the page has been mapped as arch_fault_on_access_pte(), and handle_mm_fault()->..->arch_handle_folio_fault_on_access() will either reserve tag storage, or migrate it. > > > if (IS_ERR(page)) { > > err = PTR_ERR(page); > > break; > > @@ -433,6 +436,25 @@ static int __access_remote_tags(struct mm_struct *mm, unsigned long addr, > > put_page(page); > > break; > > } > > + > > + if (tag_storage_enabled() && !page_tag_storage_reserved(page)) { > > Should not '!page' be checked here as well ? I was under the impression that get_user_page_vma_remote() returns an error pointer if gup couldn't pin the page. Thanks, Alex > > > + fault_flags = FAULT_FLAG_DEFAULT | \ > > + FAULT_FLAG_USER | \ > > + FAULT_FLAG_REMOTE | \ > > + FAULT_FLAG_ALLOW_RETRY | \ > > + FAULT_FLAG_RETRY_NOWAIT; > > + if (write) > > + fault_flags |= FAULT_FLAG_WRITE; > > + > > + put_page(page); > > + ret = handle_mm_fault(vma, addr, fault_flags, NULL); > > + if (ret & VM_FAULT_ERROR) { > > + err = -EFAULT; > > + break; > > + } > > + goto get_page; > > + } > > + > > WARN_ON_ONCE(!page_mte_tagged(page)); > > > > /* limit access to the end of the page */ _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel