Skip to content

Commit 8354fec

Browse files
ctmarinasgregkh
authored andcommitted
arm64: mte: Do not flag the zero page as PG_mte_tagged
commit f620d66 upstream. Commit 68d54ce ("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 d77e59a "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 <[email protected]> Fixes: 68d54ce ("arm64: mte: Allow PTRACE_PEEKMTETAGS access to the zero page") Reported-by: Gergely Kovacs <[email protected]> Cc: [email protected] # 5.10.x Cc: Will Deacon <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Lance Yang <[email protected]> Acked-by: Lance Yang <[email protected]> Reviewed-by: David Hildenbrand <[email protected]> Tested-by: Lance Yang <[email protected]> Signed-off-by: Will Deacon <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent e5137ed commit 8354fec

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

arch/arm64/kernel/cpufeature.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2408,17 +2408,21 @@ static void bti_enable(const struct arm64_cpu_capabilities *__unused)
24082408
#ifdef CONFIG_ARM64_MTE
24092409
static void cpu_enable_mte(struct arm64_cpu_capabilities const *cap)
24102410
{
2411+
static bool cleared_zero_page = false;
2412+
24112413
sysreg_clear_set(sctlr_el1, 0, SCTLR_ELx_ATA | SCTLR_EL1_ATA0);
24122414

24132415
mte_cpu_setup();
24142416

24152417
/*
24162418
* Clear the tags in the zero page. This needs to be done via the
2417-
* linear map which has the Tagged attribute.
2419+
* linear map which has the Tagged attribute. Since this page is
2420+
* always mapped as pte_special(), set_pte_at() will not attempt to
2421+
* clear the tags or set PG_mte_tagged.
24182422
*/
2419-
if (try_page_mte_tagging(ZERO_PAGE(0))) {
2423+
if (!cleared_zero_page) {
2424+
cleared_zero_page = true;
24202425
mte_clear_page_tags(lm_alias(empty_zero_page));
2421-
set_page_mte_tagged(ZERO_PAGE(0));
24222426
}
24232427

24242428
kasan_init_hw_tags_cpu();

arch/arm64/kernel/mte.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ static int __access_remote_tags(struct mm_struct *mm, unsigned long addr,
460460
if (folio_test_hugetlb(folio))
461461
WARN_ON_ONCE(!folio_test_hugetlb_mte_tagged(folio));
462462
else
463-
WARN_ON_ONCE(!page_mte_tagged(page));
463+
WARN_ON_ONCE(!page_mte_tagged(page) && !is_zero_page(page));
464464

465465
/* limit access to the end of the page */
466466
offset = offset_in_page(addr);

0 commit comments

Comments
 (0)