linux-stable/mm
Lorenzo Stoakes 61765a1194 mm/mempolicy: correctly update prev when policy is equal on mbind
commit 00ca0f2e86 upstream.

The refactoring in commit f4e9e0e694 ("mm/mempolicy: fix use-after-free
of VMA iterator") introduces a subtle bug which arises when attempting to
apply a new NUMA policy across a range of VMAs in mbind_range().

The refactoring passes a **prev pointer to keep track of the previous VMA
in order to reduce duplication, and in all but one case it keeps this
correctly updated.

The bug arises when a VMA within the specified range has an equivalent
policy as determined by mpol_equal() - which unlike other cases, does not
update prev.

This can result in a situation where, later in the iteration, a VMA is
found whose policy does need to change.  At this point, vma_merge() is
invoked with prev pointing to a VMA which is before the previous VMA.

Since vma_merge() discovers the curr VMA by looking for the one
immediately after prev, it will now be in a situation where this VMA is
incorrect and the merge will not proceed correctly.

This is checked in the VM_WARN_ON() invariant case with end >
curr->vm_end, which, if a merge is possible, results in a warning (if
CONFIG_DEBUG_VM is specified).

I note that vma_merge() performs these invariant checks only after
merge_prev/merge_next are checked, which is debatable as it hides this
issue if no merge is possible even though a buggy situation has arisen.

The solution is simply to update the prev pointer even when policies are
equal.

This caused a bug to arise in the 6.2.y stable tree, and this patch
resolves this bug.

Link: https://lkml.kernel.org/r/83f1d612acb519d777bebf7f3359317c4e7f4265.1682866629.git.lstoakes@gmail.com
Fixes: f4e9e0e694 ("mm/mempolicy: fix use-after-free of VMA iterator")
Signed-off-by: Lorenzo Stoakes <lstoakes@gmail.com>
Reported-by: kernel test robot <oliver.sang@intel.com>
  Link: https://lore.kernel.org/oe-lkp/202304292203.44ddeff6-oliver.sang@intel.com
Cc: Liam R. Howlett <Liam.Howlett@oracle.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-05-11 23:11:35 +09:00
..
damon mm/damon/paddr: fix missing folio_put() 2023-03-10 09:29:41 +01:00
kasan kasan: hw_tags: avoid invalid virt_to_page() 2023-05-11 23:11:33 +09:00
kfence mm: kfence: fix handling discontiguous page 2023-04-13 17:02:49 +02:00
kmsan mm: kmsan: handle alloc failures in kmsan_vmap_pages_range_noflush() 2023-04-26 14:30:06 +02:00
Kconfig New Feature: 2022-12-17 14:06:53 -06:00
Kconfig.debug
Makefile
backing-dev.c writeback, cgroup: fix null-ptr-deref write in bdi_split_work_to_wbs 2023-04-26 14:30:05 +02:00
balloon_compaction.c
bootmem_info.c
cma.c
cma.h
cma_debug.c
cma_sysfs.c
compaction.c Revert "mm/compaction: fix set skip in fast_find_migrateblock" 2023-01-29 10:38:43 -08:00
debug.c
debug_page_ref.c
debug_vm_pgtable.c
dmapool.c
early_ioremap.c
fadvise.c
failslab.c
filemap.c mm/filemap: fix page end in filemap_get_read_batch 2023-02-16 18:11:58 -08:00
folio-compat.c
frontswap.c
gup.c mm/gup: add folio to list when folio_isolate_lru() succeed 2023-02-03 17:52:24 -08:00
gup_test.c mm/gup_test: free memory allocated via kvcalloc() using kvfree() 2022-12-15 16:37:48 -08:00
gup_test.h
highmem.c
hmm.c mm: Remove pointless barrier() after pmdp_get_lockless() 2022-12-15 10:37:27 -08:00
huge_memory.c mm/huge_memory.c: warn with pr_warn_ratelimited instead of VM_WARN_ON_ONCE_FOLIO 2023-04-26 14:30:06 +02:00
hugetlb.c mm/hugetlb: fix uffd wr-protection for CoW optimization path 2023-04-13 17:02:56 +02:00
hugetlb_cgroup.c
hugetlb_vmemmap.c sysctl: fix proc_dobool() usability 2023-03-10 09:28:46 +01:00
hugetlb_vmemmap.h
hwpoison-inject.c
init-mm.c
internal.h
interval_tree.c
io-mapping.c
ioremap.c
khugepaged.c mm/khugepaged: check again on anon uffd-wp during isolation 2023-04-26 14:30:06 +02:00
kmemleak.c mm: use stack_depot_early_init for kmemleak 2023-01-31 16:44:10 -08:00
ksm.c mm/ksm: fix race with VMA iteration and mm_struct teardown 2023-03-30 12:51:41 +02:00
list_lru.c
maccess.c
madvise.c mm: update mmap_sem comments to refer to mmap_lock 2023-01-11 16:14:22 -08:00
mapping_dirty_helpers.c mm: Rename pmd_read_atomic() 2022-12-15 10:37:27 -08:00
memblock.c Revert "mm: Always release pages to the buddy allocator in memblock_free_late()." 2023-02-07 13:07:37 +02:00
memcontrol.c mm: memcontrol: deprecate charge moving 2023-03-10 09:29:49 +01:00
memfd.c
memory-failure.c mm/hwpoison: convert TTU_IGNORE_HWPOISON to TTU_HWPOISON 2023-03-10 09:29:48 +01:00
memory-tiers.c memory tier: release the new_memtier in find_create_memory_tier() 2023-03-10 09:29:50 +01:00
memory.c mm: take a page reference when removing device exclusive entries 2023-04-13 17:02:57 +02:00
memory_hotplug.c
mempolicy.c mm/mempolicy: correctly update prev when policy is equal on mbind 2023-05-11 23:11:35 +09:00
mempool.c
memremap.c
memtest.c
migrate.c mm/migrate: fix wrongly apply write bit after mkdirty on sparc64 2023-02-17 15:07:05 -08:00
migrate_device.c
mincore.c mm: teach mincore_hugetlb about pte markers 2023-03-22 13:38:07 +01:00
mlock.c
mm_init.c
mm_slot.h
mmap.c mm/mmap: regression fix for unmapped_area{_topdown} 2023-04-26 14:30:07 +02:00
mmap_lock.c
mmu_gather.c
mmu_notifier.c
mmzone.c
mprotect.c mm: fix a few rare cases of using swapin error pte marker 2023-01-18 17:02:19 -08:00
mremap.c mm, mremap: fix mremap() expanding for vma's with vm_ops->close() 2023-01-31 16:44:08 -08:00
msync.c
nommu.c nommu: fix split_vma() map_count error 2023-01-11 16:14:23 -08:00
oom_kill.c
page-writeback.c
page_alloc.c mm/page_alloc: fix potential deadlock on zonelist_update_seq seqlock 2023-04-26 14:30:08 +02:00
page_counter.c
page_ext.c
page_idle.c
page_io.c
page_isolation.c
page_owner.c
page_poison.c
page_reporting.c
page_reporting.h
page_table_check.c
page_vma_mapped.c
pagewalk.c
percpu-internal.h
percpu-km.c
percpu-stats.c
percpu-vm.c
percpu.c
pgalloc-track.h
pgtable-generic.c
process_vm_access.c
ptdump.c
readahead.c
rmap.c mm/hwpoison: convert TTU_IGNORE_HWPOISON to TTU_HWPOISON 2023-03-10 09:29:48 +01:00
rodata_test.c
secretmem.c
shmem.c mm/shmem: restore SHMEM_HUGE_DENY precedence over MADV_COLLAPSE 2023-01-11 16:14:20 -08:00
shrinker_debug.c mm: shrinkers: fix deadlock in shrinker debugfs 2023-02-09 15:56:51 -08:00
shuffle.c
shuffle.h
slab.c mm/slab: Fix undefined init_cache_node_node() for NUMA and !SMP 2023-03-30 12:51:34 +02:00
slab.h
slab_common.c hardening updates for v6.2-rc1 2022-12-14 12:20:00 -08:00
slob.c
slub.c
sparse-vmemmap.c
sparse.c
swap.c
swap.h
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-04-13 17:02:56 +02:00
truncate.c
usercopy.c
userfaultfd.c New Feature: 2022-12-17 14:06:53 -06:00
util.c
vmalloc.c mm: kmsan: handle alloc failures in kmsan_vmap_pages_range_noflush() 2023-04-26 14:30:06 +02:00
vmpressure.c
vmscan.c mm: do not reclaim private data from pinned page 2023-05-11 23:11:33 +09:00
vmstat.c
workingset.c
z3fold.c
zbud.c
zpool.c
zsmalloc.c zsmalloc: fix a race with deferred_handles storing 2023-01-31 16:44:07 -08:00
zswap.c