linux-stable/arch/powerpc/mm
Ryan Roberts 7a2bc8b34e mm: fix race between __split_huge_pmd_locked() and GUP-fast
commit 3a5a8d343e upstream.

__split_huge_pmd_locked() can be called for a present THP, devmap or
(non-present) migration entry.  It calls pmdp_invalidate() unconditionally
on the pmdp and only determines if it is present or not based on the
returned old pmd.  This is a problem for the migration entry case because
pmd_mkinvalid(), called by pmdp_invalidate() must only be called for a
present pmd.

On arm64 at least, pmd_mkinvalid() will mark the pmd such that any future
call to pmd_present() will return true.  And therefore any lockless
pgtable walker could see the migration entry pmd in this state and start
interpretting the fields as if it were present, leading to BadThings (TM).
GUP-fast appears to be one such lockless pgtable walker.

x86 does not suffer the above problem, but instead pmd_mkinvalid() will
corrupt the offset field of the swap entry within the swap pte.  See link
below for discussion of that problem.

Fix all of this by only calling pmdp_invalidate() for a present pmd.  And
for good measure let's add a warning to all implementations of
pmdp_invalidate[_ad]().  I've manually reviewed all other
pmdp_invalidate[_ad]() call sites and believe all others to be conformant.

This is a theoretical bug found during code review.  I don't have any test
case to trigger it in practice.

Link: https://lkml.kernel.org/r/20240501143310.1381675-1-ryan.roberts@arm.com
Link: https://lore.kernel.org/all/0dd7827a-6334-439a-8fd0-43c98e6af22b@arm.com/
Fixes: 84c3fc4e9c ("mm: thp: check pmd migration entry in common path")
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
Acked-by: David Hildenbrand <david@redhat.com>
Cc: Andreas Larsson <andreas@gaisler.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Aneesh Kumar K.V <aneesh.kumar@kernel.org>
Cc: Borislav Petkov (AMD) <bp@alien8.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Naveen N. Rao <naveen.n.rao@linux.ibm.com>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will@kernel.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-06-16 13:41:38 +02:00
..
book3s32 - Yu Zhao's Multi-Gen LRU patches are here. They've been under test in 2022-10-10 17:53:04 -07:00
book3s64 mm: fix race between __split_huge_pmd_locked() and GUP-fast 2024-06-16 13:41:38 +02:00
kasan powerpc/kasan: Fix addr error caused by page alignment 2024-02-23 09:12:35 +01:00
nohash powerpc/64e: provide an addressing macro for use with TOC in alternate register 2022-09-28 19:22:12 +10:00
ptdump powerpc: Remove CONFIG_PPC_BOOK3E_MMU 2022-09-26 23:00:14 +10:00
cacheflush.c powerpc: Fix all occurences of "the the" 2022-05-22 15:59:43 +10:00
copro_fault.c powerpc/mm: convert coprocessor fault to lock_mm_and_find_vma() 2023-07-01 13:16:25 +02:00
dma-noncoherent.c
drmem.c powerpc: Add missing headers 2022-05-08 22:15:40 +10:00
fault.c powerpc/mm: Convert to using lock_mm_and_find_vma() 2023-07-01 13:16:24 +02:00
hugetlbpage.c powerpc/mm: Fix UBSAN warning reported on hugetlb 2022-09-30 18:35:52 +10:00
init-common.c powerpc/mm: Fix null-pointer dereference in pgtable_cache_add 2024-02-05 20:12:46 +00:00
init_32.c powerpc: Remove CONFIG_FSL_BOOKE 2022-09-26 22:47:37 +10:00
init_64.c powerpc/mm/altmap: Fix altmap boundary check 2023-08-11 12:08:25 +02:00
ioremap.c powerpc: make memremap_compat_align 64s-only 2021-12-02 22:57:24 +11:00
ioremap_32.c
ioremap_64.c
maccess.c powerpc/inst: Optimise copy_inst_from_kernel_nofault() 2021-12-09 22:41:21 +11:00
Makefile powerpc/mm: Convert to default topdown mmap layout 2022-05-05 22:11:58 +10:00
mem.c powerpc/mm: Fix boot crash with FLATMEM 2023-11-08 14:11:02 +01:00
mmu_context.c powerpc/mm: Switch obsolete dssall to .long 2021-12-23 22:35:13 +11:00
mmu_decl.h powerpc/64s: Fix CONFIG_NUMA=n build due to create_section_mapping() 2024-02-05 20:12:46 +00:00
numa.c powerpc/papr_scm: Update the NUMA distance table for the target node 2023-04-20 12:35:14 +02:00
pageattr.c powerpc: align address to page boundary in change_page_attr() 2022-05-08 22:15:41 +10:00
pgtable-frag.c powerpc: fix typos in comments 2022-05-05 22:12:44 +10:00
pgtable.c powerpc/mm: move protection_map[] inside the platform 2022-07-17 17:14:37 -07:00
pgtable_32.c powerpc: move __end_rodata to cover arch read-only sections 2022-09-26 20:58:16 +10:00
pgtable_64.c powerpc: Remove asm/prom.h from all files that don't need it 2022-05-08 22:15:04 +10:00