From patchwork Tue Feb 14 01:52:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Collingbourne X-Patchwork-Id: 13139255 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 82804C636D4 for ; Tue, 14 Feb 2023 01:53:31 +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:Cc:To:From:Subject:Mime-Version: Message-Id:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=AdFsLhcMbMh/N0b1mDbUdGZ13lfrO+L5aan5CEZkOuw=; b=woU NXl6XhBWqFpgWJttRY+6oz2vxLVREy72zH2IHshmbUPV88814wZZ+YJg1fM9uDLCztnJ98WXuzzMq yxF88aZn5qzGTRI1rWZHUoRFIu+y5xpQ2DLX9UR9NTFqrHDqfzZfYUfabKiZqeqHkH6a6PrHNnYEL khNhPa/4BySiz1KzKspk6qFDGjsELi6RWyi60lmyDZLzln+7JcPpXe7qH/W7UvHdwQfaY1/KtyGWp Y+EXiEOHFlLxCeR9DAu/yL32uZLS33raIGDBnEKk52F1AYYfMw46zudvV45SiXanGje6rpC5NZJun 2oIqnXi1XJJllqI98cJ02VjtlHwofKQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pRkUn-00H2jH-6j; Tue, 14 Feb 2023 01:52:37 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pRkUj-00H2hq-Pg for linux-arm-kernel@lists.infradead.org; Tue, 14 Feb 2023 01:52:35 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-52f233aff21so44232177b3.7 for ; Mon, 13 Feb 2023 17:52:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=content-transfer-encoding:cc:to:from:subject:mime-version :message-id:date:from:to:cc:subject:date:message-id:reply-to; bh=2J+3GOG2P0hnwklMWKGq0tLBKfNtpEESwIEDcAq6rlI=; b=cF3vp2hnvMgG9ens+55wFDLcpBIkUkt4Nr/ypQnsswmAhEKnCMkvo8mhtgwk6R2oWI hnMGi8RcYBDYS6G4DDTcN8MUzkLnggjUk60MrjOF4qdbV194PhN2YZqViUOzWTyIcQJ6 brzQ5pW4Q58FaWVJNjaNBxB2xGQ4iKx4H373x7OOuRmEN96Xjvrh0gCNa6HTX6opFTlJ qOlGG819eQxpIR8i/XLQ64Ea+m3or5yzSsVe0t95k1uYg1O6kfvdyJDKv9u0PVB7y9r4 fjTDsRkGaP8mohZ7h8DRJ8Wp/HnJAyL73ibTgS74esVy7uZVBqUF5/4Op1M/HpywygD3 rtJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:from:subject:mime-version :message-id:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=2J+3GOG2P0hnwklMWKGq0tLBKfNtpEESwIEDcAq6rlI=; b=c2YKNXnvS1hVP0aJOVWJCX3uNMesKQ+2xvqRaIUKJO7ZJuDDi9Fe1ufyz6RzD2WNE4 GVsCF+JyGmC9WmR9AO6c7xNgyS+bKZc4jLBivv0Gn0FfYelq2p7ZNFJN1/PP9DJjKw46 k3zIgkEIWvr5vXEWQCIEg88dCQ5AMmi6Eo3N49Cw52I4gCyyjFfFRrQJtQ1yxHeY+qDO ShPSDnrN6qsOi3PqOe6afMxrMYVJgM5e60ZfMNUYtFlvGF7h1QAN32CIgU9oHRbeBT4x TLak6lYbFhSIUWLKwreEl+u5D7PE24Tupu1Xk6cJar1ciGZ4XsZQkZxzj1bU9zAaysqa 5JQg== X-Gm-Message-State: AO0yUKVc1PsMmOxi7XMQnkQTb+7d26knRZB+2jgV5+GlmbJ6LzEsgO7L 50MSrKrWIz58TqklKddTNCXcH7Y= X-Google-Smtp-Source: AK7set8JX2UCuUx1r/BRaJun6ZhAJ9kw7czlUn0qrE78/cOFud3HqDmluAZSD4UYPrIYk/Z3I/l8GIk= X-Received: from pcc-desktop.svl.corp.google.com ([2620:15c:2d3:205:6153:a2b0:1bfd:87af]) (user=pcc job=sendgmr) by 2002:a05:6902:1147:b0:8df:1fcb:f1c8 with SMTP id p7-20020a056902114700b008df1fcbf1c8mr9ybu.2.1676339549200; Mon, 13 Feb 2023 17:52:29 -0800 (PST) Date: Mon, 13 Feb 2023 17:52:14 -0800 Message-Id: <20230214015214.747873-1-pcc@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.39.1.581.gbfd45094c4-goog Subject: [PATCH] arm64: Reset KASAN tag in copy_highpage with HW tags only From: Peter Collingbourne To: catalin.marinas@arm.com, andreyknvl@gmail.com Cc: Peter Collingbourne , " =?utf-8?b?UXVuLXdlaSBMaW4gKA==?= =?utf-8?b?5p6X576k5bS0KQ==?= " , " =?utf-8?b?R3Vhbmd5ZSBZYW5nICjmnajlhYnkuJop?= " , linux-mm@kvack.org, " =?utf-8?b?Q2hpbndlbiBDaGFuZyAo5by16Yym5paHKQ==?= " , 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, " =?utf-8?b?S3Vhbi1ZaW5nIExlZSAo5p2O?= =?utf-8?b?5Yag56mOKQ==?= " , stable@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230213_175233_856612_B7FC9782 X-CRM114-Status: GOOD ( 15.70 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org During page migration, the copy_highpage function is used to copy the page data to the target page. If the source page is a userspace page with MTE tags, the KASAN tag of the target page must have the match-all tag in order to avoid tag check faults during subsequent accesses to the page by the kernel. However, the target page may have been allocated in a number of ways, some of which will use the KASAN allocator and will therefore end up setting the KASAN tag to a non-match-all tag. Therefore, update the target page's KASAN tag to match the source page. We ended up unintentionally fixing this issue as a result of a bad merge conflict resolution between commit e059853d14ca ("arm64: mte: Fix/clarify the PG_mte_tagged semantics") and commit 20794545c146 ("arm64: kasan: Revert "arm64: mte: reset the page tag in page->flags""), which preserved a tag reset for PG_mte_tagged pages which was considered to be unnecessary at the time. Because SW tags KASAN uses separate tag storage, update the code to only reset the tags when HW tags KASAN is enabled. Signed-off-by: Peter Collingbourne Link: https://linux-review.googlesource.com/id/If303d8a709438d3ff5af5fd85706505830f52e0c Reported-by: "Kuan-Ying Lee (李冠穎)" Cc: # 6.1 --- For the stable branch, e059853d14ca needs to be cherry-picked and the following merge conflict resolution is needed: - page_kasan_tag_reset(to); + if (kasan_hw_tags_enabled()) + page_kasan_tag_reset(to); - /* It's a new page, shouldn't have been tagged yet */ - WARN_ON_ONCE(!try_page_mte_tagging(to)); arch/arm64/mm/copypage.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/arm64/mm/copypage.c b/arch/arm64/mm/copypage.c index 8dd5a8fe64b4..4aadcfb01754 100644 --- a/arch/arm64/mm/copypage.c +++ b/arch/arm64/mm/copypage.c @@ -22,7 +22,8 @@ void copy_highpage(struct page *to, struct page *from) copy_page(kto, kfrom); if (system_supports_mte() && page_mte_tagged(from)) { - page_kasan_tag_reset(to); + if (kasan_hw_tags_enabled()) + page_kasan_tag_reset(to); /* It's a new page, shouldn't have been tagged yet */ WARN_ON_ONCE(!try_page_mte_tagging(to)); mte_copy_page_tags(kto, kfrom);