opnsense-src/sys/vm
Mark Johnston afbe2bb9e9 vm_object: Fix handling of wired map entries in vm_object_split()
Suppose a vnode is mapped with MAP_PROT and MAP_PRIVATE, mlock() is
called on the mapping, and then the vnode is truncated such that the
last page of the mapping becomes invalid.  The now-invalid page will be
unmapped, but stays resident in the VM object to preserve the invariant
that a range of pages mapped by a wired map entry is always resident.
This invariant is checked by vm_object_unwire(), for example.

Then, suppose that the mapping is upgraded to PROT_READ|PROT_WRITE.  We
will copy the invalid page into a new anonymous VM object.  If the
process then forks, vm_object_split() may then be called on the object.
Upon encountering an invalid page, rather than moving it into the
destination object, it is removed.  However, this is wrong when the
entry is wired, since the invalid page's wiring belongs to the map
entry; this behaviour also violates the invariant mentioned above.

Fix this by moving invalid pages into the destination object if the map
entry is wired.  In this case we must not dirty the page, so add a flag
to vm_page_iter_rename() to control this.

Reported by:	syzkaller
Reviewed by:	dougm, kib
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D49443

(cherry picked from commit 43c1eb894a57ef30562a02708445c512610d4f02)
2025-04-18 13:53:55 +00:00
..
_vm_phys.h sys: Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:11 -06:00
_vm_radix.h sys: Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:11 -06:00
device_pager.c device_pager: rename the un_pager.devp.dev field to handle 2024-11-13 01:19:18 +02:00
memguard.c sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
memguard.h sys: Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:11 -06:00
phys_pager.c sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
pmap.h pmap: move the smp_targeted_tlb_shutdown pointer stuff to amd64 pmap.h 2024-07-01 13:07:38 +00:00
redzone.c sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
redzone.h sys: Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:11 -06:00
sg_pager.c Add sysctl kern.proc.kqueue 2025-04-07 04:28:20 +03:00
swap_pager.c swap_pager: Ensure that swapoff puts swapped-in pages in page queues 2024-11-28 14:38:17 +00:00
swap_pager.h sys: Remove $FreeBSD$: one-line .h pattern 2023-08-16 11:54:18 -06:00
uma.h uma: Permit specifying max of cache line and some custom alignment 2023-11-16 10:07:18 -05:00
uma_align_mask.h uma: Make the cache alignment mask unsigned 2023-11-16 10:07:16 -05:00
uma_core.c uma: Avoid excessive per-CPU draining 2025-03-31 18:35:33 +00:00
uma_dbg.c uma: Micro-optimize memory trashing 2023-12-08 21:32:43 -05:00
uma_dbg.h sys: Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:11 -06:00
uma_int.h sys: Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:11 -06:00
vm.h sys: Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:11 -06:00
vm_domainset.c sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
vm_domainset.h sys: Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:11 -06:00
vm_dumpset.h sys: Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:11 -06:00
vm_extern.h vm: Add kva_alloc_aligned 2024-09-02 08:43:18 +00:00
vm_fault.c sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
vm_glue.c thread: Simplify sanitizer integration with thread creation 2025-02-07 14:46:53 +00:00
vm_init.c Adjust comments referencing vm_mem_init() 2024-06-06 11:23:01 -03:00
vm_kern.c vm: Add kva_alloc_aligned 2024-09-02 08:43:18 +00:00
vm_kern.h sys: Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:11 -06:00
vm_map.c vm_map: add vm_map_find_locked(9) 2024-10-05 10:08:54 +03:00
vm_map.h vm_map: add vm_map_find_locked(9) 2024-10-05 10:08:54 +03:00
vm_meter.c vm_meter: Fix laundry accounting 2024-10-29 13:04:25 +00:00
vm_mmap.c vm_object: do not assume that un_pager.devp.dev is cdev 2024-11-13 01:19:18 +02:00
vm_object.c vm_object: Fix handling of wired map entries in vm_object_split() 2025-04-18 13:53:55 +00:00
vm_object.h vm_object: do not assume that un_pager.devp.dev is cdev 2024-11-13 01:19:18 +02:00
vm_page.c vm_object: Fix handling of wired map entries in vm_object_split() 2025-04-18 13:53:55 +00:00
vm_page.h vm_page_free_pages_toq(): return the count of freed pages 2024-10-05 10:08:56 +03:00
vm_pageout.c vm_pageout: Add a chicken switch for multithreaded PQ_INACTIVE scanning 2025-01-23 13:58:07 +00:00
vm_pageout.h sys: Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:11 -06:00
vm_pagequeue.h vm_pageout: Add a chicken switch for multithreaded PQ_INACTIVE scanning 2025-01-23 13:58:07 +00:00
vm_pager.c sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
vm_pager.h sys: Remove $FreeBSD$: one-line .h pattern 2023-08-16 11:54:18 -06:00
vm_param.h sys: Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:11 -06:00
vm_phys.c vm_phys_early_startup(): Panic if phys_avail[] is empty 2025-04-08 15:38:22 +02:00
vm_phys.h sys: Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:11 -06:00
vm_radix.c sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
vm_radix.h sys: Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:11 -06:00
vm_reserv.c vm_reserv_reclaim_contig: Return NULL not false 2024-04-17 10:33:26 -04:00
vm_reserv.h sys: Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:11 -06:00
vm_swapout.c sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
vm_swapout_dummy.c sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
vm_unix.c sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
vnode_pager.c buf: Add a runningbufclaim() helper 2024-12-06 14:51:09 +00:00
vnode_pager.h Add vnode_pager_clean_{a,}sync(9) 2024-01-18 02:51:33 +02:00