linux/arch/arm64
Catalin Marinas 588a513d34 arm64: Fix race condition on PG_dcache_clean in __sync_icache_dcache()
To ensure that instructions are observable in a new mapping, the arm64
set_pte_at() implementation cleans the D-cache and invalidates the
I-cache to the PoU. As an optimisation, this is only done on executable
mappings and the PG_dcache_clean page flag is set to avoid future cache
maintenance on the same page.

When two different processes map the same page (e.g. private executable
file or shared mapping) there's a potential race on checking and setting
PG_dcache_clean via set_pte_at() -> __sync_icache_dcache(). While on the
fault paths the page is locked (PG_locked), mprotect() does not take the
page lock. The result is that one process may see the PG_dcache_clean
flag set but the I/D cache maintenance not yet performed.

Avoid test_and_set_bit(PG_dcache_clean) in favour of separate test_bit()
and set_bit(). In the rare event of a race, the cache maintenance is
done twice.

Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Cc: <stable@vger.kernel.org>
Cc: Will Deacon <will@kernel.org>
Cc: Steven Price <steven.price@arm.com>
Reviewed-by: Steven Price <steven.price@arm.com>
Acked-by: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20210514095001.13236-1-catalin.marinas@arm.com
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2021-05-14 17:11:16 +01:00
..
boot pwm: Changes for v5.13-rc1 2021-05-05 12:53:16 -07:00
configs ARM: platform support for Apple M1 2021-04-26 12:30:36 -07:00
crypto arm64 updates for 5.13: 2021-04-26 10:25:03 -07:00
include arm64: Generate cpucaps.h 2021-05-10 10:16:37 +01:00
kernel Assorted arm64 fixes and clean-ups, the most important: 2021-05-07 12:11:05 -07:00
kvm ARM: 2021-05-01 10:14:08 -07:00
lib arm64: lib: Annotate {clear, copy}_page() as position-independent 2021-03-19 12:01:19 +00:00
mm arm64: Fix race condition on PG_dcache_clean in __sync_icache_dcache() 2021-05-14 17:11:16 +01:00
net bpf: Rename BPF_XADD and prepare to encode other atomics in .imm 2021-01-14 18:34:29 -08:00
tools arm64: tools: Add __ASM_CPUCAPS_H to the endif in cpucaps.h 2021-05-13 17:57:43 +01:00
xen
Kbuild
Kconfig Assorted arm64 fixes and clean-ups, the most important: 2021-05-07 12:11:05 -07:00
Kconfig.debug arm64: remove TEXT_OFFSET randomization 2020-06-15 13:10:59 +01:00
Kconfig.platforms This is the bulk of the pin control changes for the v5.13 kernel cycle 2021-04-30 13:04:30 -07:00
Makefile arm64: Generate cpucaps.h 2021-05-10 10:16:37 +01:00