]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
arm64: mte: Do not flag the zero page as PG_mte_tagged
authorCatalin Marinas <catalin.marinas@arm.com>
Fri, 17 Oct 2025 12:40:20 +0000 (08:40 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 19 Oct 2025 14:21:55 +0000 (16:21 +0200)
[ Upstream commit f620d66af3165838bfa845dcf9f5f9b4089bf508 ]

Commit 68d54ceeec0e ("arm64: mte: Allow PTRACE_PEEKMTETAGS access to the
zero page") attempted to fix ptrace() reading of tags from the zero page
by marking it as PG_mte_tagged during cpu_enable_mte(). The same commit
also changed the ptrace() tag access permission check to the VM_MTE vma
flag while turning the page flag test into a WARN_ON_ONCE().

Attempting to set the PG_mte_tagged flag early with
CONFIG_DEFERRED_STRUCT_PAGE_INIT enabled may either hang (after commit
d77e59a8fccd "arm64: mte: Lock a page for MTE tag initialisation") or
have the flags cleared later during page_alloc_init_late(). In addition,
pages_identical() -> memcmp_pages() will reject any comparison with the
zero page as it is marked as tagged.

Partially revert the above commit to avoid setting PG_mte_tagged on the
zero page. Update the __access_remote_tags() warning on untagged pages
to ignore the zero page since it is known to have the tags initialised.

Note that all user mapping of the zero page are marked as pte_special().
The arm64 set_pte_at() will not call mte_sync_tags() on such pages, so
PG_mte_tagged will remain cleared.

Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Fixes: 68d54ceeec0e ("arm64: mte: Allow PTRACE_PEEKMTETAGS access to the zero page")
Reported-by: Gergely Kovacs <Gergely.Kovacs2@arm.com>
Cc: stable@vger.kernel.org # 5.10.x
Cc: Will Deacon <will@kernel.org>
Cc: David Hildenbrand <david@redhat.com>
Cc: Lance Yang <lance.yang@linux.dev>
Acked-by: Lance Yang <lance.yang@linux.dev>
Reviewed-by: David Hildenbrand <david@redhat.com>
Tested-by: Lance Yang <lance.yang@linux.dev>
Signed-off-by: Will Deacon <will@kernel.org>
[ replaced page_mte_tagged() and is_zero_page() with test_bit() and is_zero_pfn() ]
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/arm64/kernel/cpufeature.c
arch/arm64/kernel/mte.c

index e9d1e429456f1263c75a691fdf38a60575f77be1..a2518ccc5e9802f3e810231f6a2a2d5f96fefc8a 100644 (file)
@@ -1948,16 +1948,22 @@ static void bti_enable(const struct arm64_cpu_capabilities *__unused)
 #ifdef CONFIG_ARM64_MTE
 static void cpu_enable_mte(struct arm64_cpu_capabilities const *cap)
 {
+       static bool cleared_zero_page = false;
+
        sysreg_clear_set(sctlr_el1, 0, SCTLR_ELx_ATA | SCTLR_EL1_ATA0);
 
        mte_cpu_setup();
 
        /*
         * Clear the tags in the zero page. This needs to be done via the
-        * linear map which has the Tagged attribute.
+        * linear map which has the Tagged attribute. Since this page is
+        * always mapped as pte_special(), set_pte_at() will not attempt to
+        * clear the tags or set PG_mte_tagged.
         */
-       if (!test_and_set_bit(PG_mte_tagged, &ZERO_PAGE(0)->flags))
+       if (!cleared_zero_page) {
+               cleared_zero_page = true;
                mte_clear_page_tags(lm_alias(empty_zero_page));
+       }
 
        kasan_init_hw_tags_cpu();
 }
index a3898bac5ae6fa3ddb7b416734b75d8b8745049c..7f77fedb090146280fd9a86d99287d5ccfa3107d 100644 (file)
@@ -370,7 +370,8 @@ static int __access_remote_tags(struct mm_struct *mm, unsigned long addr,
                        put_page(page);
                        break;
                }
-               WARN_ON_ONCE(!test_bit(PG_mte_tagged, &page->flags));
+               WARN_ON_ONCE(!test_bit(PG_mte_tagged, &page->flags) &&
+                            !is_zero_pfn(page_to_pfn(page)));
 
                /* limit access to the end of the page */
                offset = offset_in_page(addr);