Ubuntu-focal-kernel/mm
Zi Yan 94cab76106 mm/cma: use nth_page() in place of direct struct page manipulation
BugLink: https://bugs.launchpad.net/bugs/2049069

commit 2e7cfe5cd5b6b0b98abf57a3074885979e187c1c upstream.

Patch series "Use nth_page() in place of direct struct page manipulation",
v3.

On SPARSEMEM without VMEMMAP, struct page is not guaranteed to be
contiguous, since each memory section's memmap might be allocated
independently.  hugetlb pages can go beyond a memory section size, thus
direct struct page manipulation on hugetlb pages/subpages might give wrong
struct page.  Kernel provides nth_page() to do the manipulation properly.
Use that whenever code can see hugetlb pages.

This patch (of 5):

When dealing with hugetlb pages, manipulating struct page pointers
directly can get to wrong struct page, since struct page is not guaranteed
to be contiguous on SPARSEMEM without VMEMMAP.  Use nth_page() to handle
it properly.

Without the fix, page_kasan_tag_reset() could reset wrong page tags,
causing a wrong kasan result.  No related bug is reported.  The fix
comes from code inspection.

Link: https://lkml.kernel.org/r/20230913201248.452081-1-zi.yan@sent.com
Link: https://lkml.kernel.org/r/20230913201248.452081-2-zi.yan@sent.com
Fixes: 2813b9c029 ("kasan, mm, arm64: tag non slab memory allocated via pagealloc")
Signed-off-by: Zi Yan <ziy@nvidia.com>
Reviewed-by: Muchun Song <songmuchun@bytedance.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Mike Rapoport (IBM) <rppt@kernel.org>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Manuel Diewald <manuel.diewald@canonical.com>
Signed-off-by: Roxana Nicolescu <roxana.nicolescu@canonical.com>
2024-02-02 14:13:10 +01:00
..
kasan panic: Consolidate open-coded panic_on_warn checks 2023-03-21 10:09:01 +01:00
Kconfig
Kconfig.debug
Makefile
backing-dev.c mm: bdi: initialize bdi_min_ratio when bdi is unregistered 2022-02-03 18:57:49 +01:00
balloon_compaction.c
cleancache.c
cma.c mm/cma: use nth_page() in place of direct struct page manipulation 2024-02-02 14:13:10 +01:00
cma.h
cma_debug.c
compaction.c mm, compaction: fix fast_isolate_around() to stay within boundaries 2023-02-01 15:23:20 +01:00
debug.c
debug_page_ref.c
dmapool.c
early_ioremap.c
fadvise.c
failslab.c
filemap.c mm: allow a controlled amount of unfairness in the page lock 2023-10-30 11:42:02 +01:00
frame_vector.c v4l2: don't fall back to follow_pfn() if pin_user_pages_fast() fails 2023-02-01 15:21:48 +01:00
frontswap.c treewide: Remove uninitialized_var() usage 2023-08-09 12:25:41 +02:00
gup.c mm/hugetlb: fix races when looking up a CONT-PTE/PMD size hugetlb page 2023-02-01 15:22:01 +01:00
gup_benchmark.c
highmem.c
hmm.c
huge_memory.c mm/thp: check and bail out if page in deferred queue already 2023-05-12 17:15:11 +02:00
hugetlb.c mm/hugetlb: fix races when looking up a CONT-PTE/PMD size hugetlb page 2023-02-01 15:22:01 +01:00
hugetlb_cgroup.c
hwpoison-inject.c
init-mm.c
internal.h
interval_tree.c
khugepaged.c mm/khugepaged: fix collapse_pte_mapped_thp() to allow anon_vma 2023-03-21 10:08:56 +01:00
kmemleak-test.c
kmemleak.c Revert "mm: kmemleak: take a full lowmem check in kmemleak_*_phys()" 2022-11-24 10:27:44 +01:00
ksm.c treewide: Remove uninitialized_var() usage 2023-08-09 12:25:41 +02:00
list_lru.c
maccess.c
madvise.c mm: fix madivse_pageout mishandling on non-LRU page 2022-11-24 10:29:04 +01:00
memblock.c Revert "mm: Always release pages to the buddy allocator in memblock_free_late()." 2023-04-18 17:21:04 +02:00
memcontrol.c treewide: Remove uninitialized_var() usage 2023-08-09 12:25:41 +02:00
memfd.c memfd: fix F_SEAL_WRITE after shmem huge page allocated 2022-05-20 15:17:31 +02:00
memory-failure.c
memory.c mm: hugetlb: fix missing cache flush in copy_huge_page_from_user() 2022-07-11 16:39:57 +02:00
memory_hotplug.c
mempolicy.c treewide: Remove uninitialized_var() usage 2023-08-09 12:25:41 +02:00
mempool.c
memremap.c
memtest.c
migrate.c mm/migrate_device.c: flush TLB while holding PTL 2022-11-24 10:29:04 +01:00
mincore.c
mlock.c
mm_init.c
mmap.c mm: Fix TLB flush for not-first PFNMAP mappings in unmap_region() 2022-11-24 10:28:21 +01:00
mmu_context.c
mmu_gather.c mm/khugepaged: fix GUP-fast interaction by sending IPI 2023-02-01 15:21:52 +01:00
mmu_notifier.c
mmzone.c arm: remove CONFIG_ARCH_HAS_HOLES_MEMORYMODEL 2022-07-11 16:39:53 +02:00
mprotect.c
mremap.c mm/mremap: hold the rmap lock in write mode when moving page table entries. 2022-10-17 15:00:11 +02:00
msync.c
nommu.c
oom_kill.c oom_kill.c: futex: delay the OOM reaper to allow time for proper futex cleanup 2022-06-22 14:50:52 +02:00
page-writeback.c mm: make wait_on_page_writeback() wait for multiple pending writebacks 2023-10-02 12:11:59 +02:00
page_alloc.c mm/page_alloc: fix potential deadlock on zonelist_update_seq seqlock 2023-08-09 12:25:27 +02:00
page_counter.c
page_ext.c
page_idle.c
page_io.c mm: fix unexpected zeroed page mapping with zram swap 2022-07-11 16:39:44 +02:00
page_isolation.c
page_owner.c
page_poison.c
page_vma_mapped.c
pagewalk.c mm: pagewalk: Fix race between unmap and page walker 2022-11-24 10:29:15 +01:00
percpu-internal.h
percpu-km.c
percpu-stats.c
percpu-vm.c
percpu.c treewide: Remove uninitialized_var() usage 2023-08-09 12:25:41 +02:00
pgtable-generic.c
prfile.c
process_vm_access.c
readahead.c vfs: fix readahead(2) on block devices 2024-02-02 14:13:01 +01:00
rmap.c mm/rmap.c: don't reuse anon_vma if we just want a copy 2022-11-23 16:34:53 -03:00
rodata_test.c
shmem.c tmpfs: verify {g,u}id mount options correctly 2023-10-30 11:42:07 +01:00
shuffle.c
shuffle.h
slab.c
slab.h mm: kmemleak: slob: respect SLAB_NOLEAKTRACE flag 2022-01-13 18:43:04 +01:00
slab_common.c usercopy: mark dma-kmalloc caches as usercopy caches 2022-01-13 18:41:38 +01:00
slob.c
slub.c treewide: Remove uninitialized_var() usage 2023-08-09 12:25:41 +02:00
sparse-vmemmap.c
sparse.c
swap.c treewide: Remove uninitialized_var() usage 2023-08-09 12:25:41 +02:00
swap_cgroup.c
swap_slots.c
swap_state.c
swapfile.c mm/swap: fix swap_info_struct race between swapoff and get_swap_pages() 2023-07-10 17:22:10 +02:00
truncate.c
usercopy.c mm/usercopy: return 1 from hardened_usercopy __setup() handler 2022-05-20 15:19:37 +02:00
userfaultfd.c mm: userfaultfd: fix missing cache flush in mcopy_atomic_pte() and __mcopy_atomic() 2022-07-11 16:39:58 +02:00
util.c random: move randomize_page() into mm where it belongs 2022-08-26 11:10:33 +02:00
vmacache.c
vmalloc.c
vmpressure.c
vmscan.c
vmstat.c arm: remove CONFIG_ARCH_HAS_HOLES_MEMORYMODEL 2022-07-11 16:39:53 +02:00
workingset.c
z3fold.c
zbud.c
zpool.c
zsmalloc.c zsmalloc: fix races between asynchronous zspage free and page migration 2022-08-26 11:07:02 +02:00
zswap.c