Skip to content

Commit 2079454

Browse files
ctmarinaswilldeacon
authored andcommitted
arm64: kasan: Revert "arm64: mte: reset the page tag in page->flags"
This reverts commit e5b8d92. Pages mapped in user-space with PROT_MTE have the allocation tags either zeroed or copied/restored to some user values. In order for the kernel to access such pages via page_address(), resetting the tag in page->flags was necessary. This tag resetting was deferred to set_pte_at() -> mte_sync_page_tags() but it can race with another CPU reading the flags (via page_to_virt()): P0 (mte_sync_page_tags): P1 (memcpy from virt_to_page): Rflags!=0xff Wflags=0xff DMB (doesn't help) Wtags=0 Rtags=0 // fault Since now the post_alloc_hook() function resets the page->flags tag when unpoisoning is skipped for user pages (including the __GFP_ZEROTAGS case), revert the arm64 commit calling page_kasan_tag_reset(). Signed-off-by: Catalin Marinas <[email protected]> Cc: Will Deacon <[email protected]> Cc: Vincenzo Frascino <[email protected]> Cc: Andrey Konovalov <[email protected]> Cc: Peter Collingbourne <[email protected]> Reviewed-by: Vincenzo Frascino <[email protected]> Acked-by: Andrey Konovalov <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 6d05141 commit 2079454

File tree

4 files changed

+0
-32
lines changed

4 files changed

+0
-32
lines changed

arch/arm64/kernel/hibernate.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,11 +300,6 @@ static void swsusp_mte_restore_tags(void)
300300
unsigned long pfn = xa_state.xa_index;
301301
struct page *page = pfn_to_online_page(pfn);
302302

303-
/*
304-
* It is not required to invoke page_kasan_tag_reset(page)
305-
* at this point since the tags stored in page->flags are
306-
* already restored.
307-
*/
308303
mte_restore_page_tags(page_address(page), tags);
309304

310305
mte_free_tag_storage(tags);

arch/arm64/kernel/mte.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,6 @@ static void mte_sync_page_tags(struct page *page, pte_t old_pte,
4848
if (!pte_is_tagged)
4949
return;
5050

51-
page_kasan_tag_reset(page);
52-
/*
53-
* We need smp_wmb() in between setting the flags and clearing the
54-
* tags because if another thread reads page->flags and builds a
55-
* tagged address out of it, there is an actual dependency to the
56-
* memory access, but on the current thread we do not guarantee that
57-
* the new page->flags are visible before the tags were updated.
58-
*/
59-
smp_wmb();
6051
mte_clear_page_tags(page_address(page));
6152
}
6253

arch/arm64/mm/copypage.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,6 @@ void copy_highpage(struct page *to, struct page *from)
2323

2424
if (system_supports_mte() && test_bit(PG_mte_tagged, &from->flags)) {
2525
set_bit(PG_mte_tagged, &to->flags);
26-
page_kasan_tag_reset(to);
27-
/*
28-
* We need smp_wmb() in between setting the flags and clearing the
29-
* tags because if another thread reads page->flags and builds a
30-
* tagged address out of it, there is an actual dependency to the
31-
* memory access, but on the current thread we do not guarantee that
32-
* the new page->flags are visible before the tags were updated.
33-
*/
34-
smp_wmb();
3526
mte_copy_page_tags(kto, kfrom);
3627
}
3728
}

arch/arm64/mm/mteswap.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,6 @@ bool mte_restore_tags(swp_entry_t entry, struct page *page)
5353
if (!tags)
5454
return false;
5555

56-
page_kasan_tag_reset(page);
57-
/*
58-
* We need smp_wmb() in between setting the flags and clearing the
59-
* tags because if another thread reads page->flags and builds a
60-
* tagged address out of it, there is an actual dependency to the
61-
* memory access, but on the current thread we do not guarantee that
62-
* the new page->flags are visible before the tags were updated.
63-
*/
64-
smp_wmb();
6556
mte_restore_page_tags(page_address(page), tags);
6657

6758
return true;

0 commit comments

Comments
 (0)