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 F3809C77B76 for ; Fri, 21 Apr 2023 12:25:15 +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=6LJBfovrbNfym4IO9uCGf4K5GX1WaluxYAgyvEczmiA=; b=QmxmT74dsgIKkl VwzAEk6qnKxXt1XSEGoON49qusESayhGlWyt+GOMp6bo9Mpdal2YcS0+B/E9ZvhHC2zRDi9tmpJzV /Sgy908B5JBHPIG5+rU0rGnhTUbw/BCbaauxXqaujgovyh+uxM9ARWMCXMeS22ML13u5ILzZh9qDc hJ1v34YuWLN+sIx/LtS50pJnwxmW4UVRrtIxH0xj+I04UskVMjwC3aUBtYkbWRdx73Xb6ol8/hD49 kMdmFQ7GOIzN++WT5ukakA0WPo1jqyUQB/XP5nvY9hGvwWIGTFqXQO2glwHSUffcpGWETy6xtJgIu V5EiGAxyUZkxdgOrjX2A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pppoI-00ArLd-3C; Fri, 21 Apr 2023 12:24:19 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pppoB-00ArJt-2S for linux-arm-kernel@lists.infradead.org; Fri, 21 Apr 2023 12:24:14 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 264F865043; Fri, 21 Apr 2023 12:24:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6E292C433EF; Fri, 21 Apr 2023 12:24:08 +0000 (UTC) Date: Fri, 21 Apr 2023 13:24:05 +0100 From: Catalin Marinas To: Peter Collingbourne Cc: andreyknvl@gmail.com, Qun-wei Lin =?utf-8?B?KOael+e+pOW0tCk=?= , Guangye Yang =?utf-8?B?KOadqOWFieS4mik=?= , linux-mm@kvack.org, Chinwen Chang =?utf-8?B?KOW8temMpuaWhyk=?= , kasan-dev@googlegroups.com, ryabinin.a.a@gmail.com, linux-arm-kernel@lists.infradead.org, vincenzo.frascino@arm.com, will@kernel.org, eugenis@google.com, stable@vger.kernel.org Subject: Re: [PATCH] arm64: Also reset KASAN tag if page is not PG_mte_tagged Message-ID: References: <20230420210945.2313627-1-pcc@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20230420210945.2313627-1-pcc@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230421_052412_878829_925815D4 X-CRM114-Status: GOOD ( 26.17 ) 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, Apr 20, 2023 at 02:09:45PM -0700, Peter Collingbourne wrote: > Consider the following sequence of events: > > 1) A page in a PROT_READ|PROT_WRITE VMA is faulted. > 2) Page migration allocates a page with the KASAN allocator, > causing it to receive a non-match-all tag, and uses it > to replace the page faulted in 1. > 3) The program uses mprotect() to enable PROT_MTE on the page faulted in 1. Ah, so there is no race here, it's simply because the page allocation for migration has a non-match-all kasan tag in page->flags. How do we handle the non-migration case with mprotect()? IIRC post_alloc_hook() always resets the page->flags since GFP_HIGHUSER_MOVABLE has the __GFP_SKIP_KASAN_UNPOISON flag. > As a result of step 3, we are left with a non-match-all tag for a page > with tags accessible to userspace, which can lead to the same kind of > tag check faults that commit e74a68468062 ("arm64: Reset KASAN tag in > copy_highpage with HW tags only") intended to fix. > > The general invariant that we have for pages in a VMA with VM_MTE_ALLOWED > is that they cannot have a non-match-all tag. As a result of step 2, the > invariant is broken. This means that the fix in the referenced commit > was incomplete and we also need to reset the tag for pages without > PG_mte_tagged. > > Fixes: e5b8d9218951 ("arm64: mte: reset the page tag in page->flags") This commit was reverted in 20794545c146 (arm64: kasan: Revert "arm64: mte: reset the page tag in page->flags"). It looks a bit strange to fix it up. > diff --git a/arch/arm64/mm/copypage.c b/arch/arm64/mm/copypage.c > index 4aadcfb01754..a7bb20055ce0 100644 > --- a/arch/arm64/mm/copypage.c > +++ b/arch/arm64/mm/copypage.c > @@ -21,9 +21,10 @@ void copy_highpage(struct page *to, struct page *from) > > copy_page(kto, kfrom); > > + if (kasan_hw_tags_enabled()) > + page_kasan_tag_reset(to); > + > if (system_supports_mte() && page_mte_tagged(from)) { > - if (kasan_hw_tags_enabled()) > - page_kasan_tag_reset(to); This should work but can we not do this at allocation time like we do for the source page and remove any page_kasan_tag_reset() here altogether? -- Catalin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel