From patchwork Wed Feb 15 05:09:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Collingbourne X-Patchwork-Id: 13141323 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 19E6DC636CC for ; Wed, 15 Feb 2023 05:10:24 +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=Kjkadxcj35S/NTyPRGSWR1x9POZllMZQ6NxWgSUorog=; b=pqX OZuE0TwpQr5p3n4CM/tpVKDNFd4ehtK87uHopOGwgi1yAur4/himhrfgXRjjqAIIKYYv2w2tEG9Ch /4DHesiIB6H1l4kqKv8vMgRQnp0S7Dsrq4UtrdwB6TWKcsQ3ehSAjKRCRoG2g9TeQ8rjWh81AEGF8 zLkLKmWRbbCCtF6voKKJ+DpugSMWnc5aEJ9qsVgFVY904kYo/9PxWZ8wV+J/Q2rWNugfp6hpUey91 uLZHfOKjcI+dxerAv38SwemoVZjaZK3YpdVTcboP+Z5H+SNixR80fT1LwGPjmNPutYiR1qlASftTR awxhFrkAL1zBSRO5q8dPVJNg+dTrmHQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pSA2m-004kAu-EO; Wed, 15 Feb 2023 05:09:24 +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 1pSA2j-004kAN-5P for linux-arm-kernel@lists.infradead.org; Wed, 15 Feb 2023 05:09:22 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-52eb75aeecdso183663387b3.13 for ; Tue, 14 Feb 2023 21:09:19 -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=oz1c94+PpSpdOwRxmJhtyfwix/rF7URLVnLJpJ4OuRQ=; b=PAVs9wTHuHqSwdcXMccaVRi59RVMu0fidE3NSoZW9Pmt84r9A7VI97aWIZJzb8OYfV XB9svOI3UGKkfvMLPWWpv5fCkxC3Ez+vBsJRjEYxoLotr34BEi+4cCL+f8c6akzvKJgY HO7rMm0aUhukTkjHLUbwDKw3cdz7BMWzOpLwMtGuPYRDHRU2ShL3LnmPac+F5HFZRzpF 02J7y2OeS0bSMab5TdzI4cLbo0T3SegMO0IGmQK3hUOW/2hkexLAXB3Shg/bUbwQ2FEm qg739zx4pTnFrmjYMgixcf28HbVJS75iGYe4pNgbFfRyTG1wFmoAk7aSs+DITRWMkY5g rdOg== 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=oz1c94+PpSpdOwRxmJhtyfwix/rF7URLVnLJpJ4OuRQ=; b=CshITB7petB/7R2pqeNagS2Xt7Aimn+qnuTvWE4mY93iWawoNiS8/n0k/agCj2KIM5 n4BDTEzrEfVtrz01JA9MC8EhwSqeENxzMmraXoHox22ZRik9bNmZN85hnpFX3xTJl3Sm twd9b68DIxyO70kpoMDktPC2Mdv2pasd+gY+WI5mh902TVSAhbem84piYLzWkUFrSUbo tUWQYWqhMxYbnKpG+465tEnFQbLYBQNS5BfgHpPPWJdrWQ/hN/+k2JPcdMCHLlFQJvDb AW2gqLEWpBwtVnzuBR3z1ejbpk5/ORMCoEXh1jlFNExslYyXkE5fet9y9HFuKMjIxVQj /Rig== X-Gm-Message-State: AO0yUKV88zce/GOnVqV5rKxEmE7pPTdCDjJtmv1cAWsTyE8BhJ6oYc1q rEjAEZ0ocL5JJ6Qxbqh3ZR2cHqI= X-Google-Smtp-Source: AK7set8Jv69dLvHNhXRcipzuj+FaMPD6itu9fekdMrlFGOW8fqWQ+CBzIrkh2Nr4ezQ+OweciUym0ms= X-Received: from pcc-desktop.svl.corp.google.com ([2620:15c:2d3:205:d5d8:eed0:c0c1:29d7]) (user=pcc job=sendgmr) by 2002:a05:6902:341:b0:8bb:3a1:e811 with SMTP id e1-20020a056902034100b008bb03a1e811mr129660ybs.348.1676437758447; Tue, 14 Feb 2023 21:09:18 -0800 (PST) Date: Tue, 14 Feb 2023 21:09:11 -0800 Message-Id: <20230215050911.1433132-1-pcc@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.39.1.581.gbfd45094c4-goog Subject: [PATCH v2] 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-20230214_210921_243921_66A4454E X-CRM114-Status: GOOD ( 16.05 ) 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 Fixes: 20794545c146 ("arm64: kasan: Revert "arm64: mte: reset the page tag in page->flags"") Reviewed-by: Andrey Konovalov --- v2: - added Fixes tag 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);