Skip to content

Commit c4c597f

Browse files
pccwilldeacon
authored andcommitted
arm64: mte: Do not set PG_mte_tagged if tags were not initialized
The mte_sync_page_tags() function sets PG_mte_tagged if it initializes page tags. Then we return to mte_sync_tags(), which sets PG_mte_tagged again. At best, this is redundant. However, it is possible for mte_sync_page_tags() to return without having initialized tags for the page, i.e. in the case where check_swap is true (non-compound page), is_swap_pte(old_pte) is false and pte_is_tagged is false. So at worst, we set PG_mte_tagged on a page with uninitialized tags. This can happen if, for example, page migration causes a PTE for an untagged page to be replaced. If the userspace program subsequently uses mprotect() to enable PROT_MTE for that page, the uninitialized tags will be exposed to userspace. Fix it by removing the redundant call to set_page_mte_tagged(). Fixes: e059853 ("arm64: mte: Fix/clarify the PG_mte_tagged semantics") Signed-off-by: Peter Collingbourne <pcc@google.com> Cc: <stable@vger.kernel.org> # 6.1 Link: https://linux-review.googlesource.com/id/Ib02d004d435b2ed87603b858ef7480f7b1463052 Reviewed-by: Catalin Marinas <catalin.marinas@arm.com> Reviewed-by: Alexandru Elisei <alexandru.elisei@arm.com> Link: https://lore.kernel.org/r/20230420214327.2357985-1-pcc@google.com Signed-off-by: Will Deacon <will@kernel.org>
1 parent 2efbafb commit c4c597f

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

arch/arm64/kernel/mte.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,10 @@ void mte_sync_tags(pte_t old_pte, pte_t pte)
6666
return;
6767

6868
/* if PG_mte_tagged is set, tags have already been initialised */
69-
for (i = 0; i < nr_pages; i++, page++) {
70-
if (!page_mte_tagged(page)) {
69+
for (i = 0; i < nr_pages; i++, page++)
70+
if (!page_mte_tagged(page))
7171
mte_sync_page_tags(page, old_pte, check_swap,
7272
pte_is_tagged);
73-
set_page_mte_tagged(page);
74-
}
75-
}
7673

7774
/* ensure the tags are visible before the PTE is set */
7875
smp_wmb();

0 commit comments

Comments
 (0)