]> git.baikalelectronics.ru Git - kernel.git/commit
arm64: mte: Fix/clarify the PG_mte_tagged semantics
authorCatalin Marinas <catalin.marinas@arm.com>
Fri, 4 Nov 2022 01:10:35 +0000 (18:10 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 11 Mar 2023 12:55:44 +0000 (13:55 +0100)
commit53ff7153029de0310f74a9912fdb159581c47349
treefe21ecac93dd9984b6db9377c0fb3d8e9d83c4e1
parent19fa6bca75354a9276bf0c48a1716a61b182465d
arm64: mte: Fix/clarify the PG_mte_tagged semantics

commit 8d423db527eb4384bc1087788863d09346a40c12 upstream.

Currently the PG_mte_tagged page flag mostly means the page contains
valid tags and it should be set after the tags have been cleared or
restored. However, in mte_sync_tags() it is set before setting the tags
to avoid, in theory, a race with concurrent mprotect(PROT_MTE) for
shared pages. However, a concurrent mprotect(PROT_MTE) with a copy on
write in another thread can cause the new page to have stale tags.
Similarly, tag reading via ptrace() can read stale tags if the
PG_mte_tagged flag is set before actually clearing/restoring the tags.

Fix the PG_mte_tagged semantics so that it is only set after the tags
have been cleared or restored. This is safe for swap restoring into a
MAP_SHARED or CoW page since the core code takes the page lock. Add two
functions to test and set the PG_mte_tagged flag with acquire and
release semantics. The downside is that concurrent mprotect(PROT_MTE) on
a MAP_SHARED page may cause tag loss. This is already the case for KVM
guests if a VMM changes the page protection while the guest triggers a
user_mem_abort().

Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
[pcc@google.com: fix build with CONFIG_ARM64_MTE disabled]
Signed-off-by: Peter Collingbourne <pcc@google.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
Reviewed-by: Steven Price <steven.price@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Peter Collingbourne <pcc@google.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20221104011041.290951-3-pcc@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/arm64/include/asm/mte.h
arch/arm64/include/asm/pgtable.h
arch/arm64/kernel/cpufeature.c
arch/arm64/kernel/elfcore.c
arch/arm64/kernel/hibernate.c
arch/arm64/kernel/mte.c
arch/arm64/kvm/guest.c
arch/arm64/kvm/mmu.c
arch/arm64/mm/copypage.c
arch/arm64/mm/fault.c
arch/arm64/mm/mteswap.c