linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 00/16] Avoid MAP_FIXED gap exposure
@ 2024-07-04 18:27 Liam R. Howlett
  2024-07-04 18:27 ` [PATCH v3 01/16] mm/mmap: Correctly position vma_iterator in __split_vma() Liam R. Howlett
                   ` (15 more replies)
  0 siblings, 16 replies; 78+ messages in thread
From: Liam R. Howlett @ 2024-07-04 18:27 UTC (permalink / raw)
  To: linux-mm, Andrew Morton
  Cc: Suren Baghdasaryan, Vlastimil Babka, Lorenzo Stoakes,
	Matthew Wilcox, sidhartha.kumar, Paul E . McKenney,
	Bert Karwatzki, Jiri Olsa, linux-kernel, Kees Cook,
	Liam R. Howlett

It is now possible to walk the vma tree using the rcu read locks and is
beneficial to do so to reduce lock contention.  Doing so while a
MAP_FIXED mapping is executing means that a reader may see a gap in the
vma tree that should never logically exist - and does not when using the
mmap lock in read mode.  The temporal gap exists because mmap_region()
calls munmap() prior to installing the new mapping.

This patch set stops rcu readers from seeing the temporal gap by
splitting up the munmap() function into two parts.  The first part
prepares the vma tree for modifications by doing the necessary splits
and tracks the vmas marked for removal in a side tree.  The second part
completes the munmapping of the vmas after the vma tree has been
overwritten (either by a MAP_FIXED replacement vma or by a NULL in the
munmap() case).

Please note that rcu walkers will still be able to see a temporary state
of split vmas that may be in the process of being removed, but the
temporal gap will not be exposed.  vma_start_write() are called on both
parts of the split vma, so this state is detectable.

RFC: https://lore.kernel.org/linux-mm/20240531163217.1584450-1-Liam.Howlett@oracle.com/
v1: https://lore.kernel.org/linux-mm/20240611180200.711239-1-Liam.Howlett@oracle.com/
v2: https://lore.kernel.org/all/20240625191145.3382793-1-Liam.Howlett@oracle.com/

Changes since v2:
 - Introduced vms_complete_pte_clear() helper needed in case of modules
   mmaping over MAP_FIXED area.
 - Reduced arguments to unmap_region()
 - Fixed potential free_pgtables() range issue on first/last VMA.
   Tested with stress-ng --vm-sigv

Liam R. Howlett (16):
  mm/mmap: Correctly position vma_iterator in __split_vma()
  mm/mmap: Introduce abort_munmap_vmas()
  mm/mmap: Introduce vmi_complete_munmap_vmas()
  mm/mmap: Extract the gathering of vmas from do_vmi_align_munmap()
  mm/mmap: Introduce vma_munmap_struct for use in munmap operations
  mm/mmap: Change munmap to use vma_munmap_struct() for accounting and
    surrounding vmas
  mm/mmap: Extract validate_mm() from vma_complete()
  mm/mmap: Inline munmap operation in mmap_region()
  mm/mmap: Expand mmap_region() munmap call
  mm/mmap: Reposition vma iterator in mmap_region()
  mm/mmap: Track start and end of munmap in vma_munmap_struct
  mm/mmap: Clean up unmap_region() argument list
  mm/mmap: Avoid zeroing vma tree in mmap_region()
  mm/mmap: Use PHYS_PFN in mmap_region()
  mm/mmap: Use vms accounted pages in mmap_region()
  mm/mmap: Move may_expand_vm() check in mmap_region()

 mm/internal.h |  25 +++
 mm/mmap.c     | 479 +++++++++++++++++++++++++++++++-------------------
 2 files changed, 321 insertions(+), 183 deletions(-)

-- 
2.43.0



^ permalink raw reply	[flat|nested] 78+ messages in thread

end of thread, other threads:[~2024-07-10 21:04 UTC | newest]

Thread overview: 78+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-04 18:27 [PATCH v3 00/16] Avoid MAP_FIXED gap exposure Liam R. Howlett
2024-07-04 18:27 ` [PATCH v3 01/16] mm/mmap: Correctly position vma_iterator in __split_vma() Liam R. Howlett
2024-07-04 18:27 ` [PATCH v3 02/16] mm/mmap: Introduce abort_munmap_vmas() Liam R. Howlett
2024-07-05 17:02   ` Lorenzo Stoakes
2024-07-05 18:12     ` Liam R. Howlett
2024-07-10 16:06       ` Suren Baghdasaryan
2024-07-04 18:27 ` [PATCH v3 03/16] mm/mmap: Introduce vmi_complete_munmap_vmas() Liam R. Howlett
2024-07-05 17:39   ` Lorenzo Stoakes
2024-07-10 16:07   ` Suren Baghdasaryan
2024-07-04 18:27 ` [PATCH v3 04/16] mm/mmap: Extract the gathering of vmas from do_vmi_align_munmap() Liam R. Howlett
2024-07-05 18:01   ` Lorenzo Stoakes
2024-07-05 18:41     ` Liam R. Howlett
2024-07-10 16:07   ` Suren Baghdasaryan
2024-07-10 16:32     ` Liam R. Howlett
2024-07-04 18:27 ` [PATCH v3 05/16] mm/mmap: Introduce vma_munmap_struct for use in munmap operations Liam R. Howlett
2024-07-05 18:39   ` Lorenzo Stoakes
2024-07-05 19:09     ` Liam R. Howlett
2024-07-10 16:07       ` Suren Baghdasaryan
2024-07-10 16:30         ` Liam R. Howlett
2024-07-04 18:27 ` [PATCH v3 06/16] mm/mmap: Change munmap to use vma_munmap_struct() for accounting and surrounding vmas Liam R. Howlett
2024-07-05 19:27   ` Lorenzo Stoakes
2024-07-05 19:59     ` Liam R. Howlett
2024-07-10 16:07       ` Suren Baghdasaryan
2024-07-10 17:29         ` Suren Baghdasaryan
2024-07-04 18:27 ` [PATCH v3 07/16] mm/mmap: Extract validate_mm() from vma_complete() Liam R. Howlett
2024-07-05 19:35   ` Lorenzo Stoakes
2024-07-10 16:06     ` Suren Baghdasaryan
2024-07-04 18:27 ` [PATCH v3 08/16] mm/mmap: Inline munmap operation in mmap_region() Liam R. Howlett
2024-07-05 19:39   ` Lorenzo Stoakes
2024-07-05 20:00     ` Liam R. Howlett
2024-07-10 16:15   ` Suren Baghdasaryan
2024-07-10 16:35     ` Liam R. Howlett
2024-07-04 18:27 ` [PATCH v3 09/16] mm/mmap: Expand mmap_region() munmap call Liam R. Howlett
2024-07-05 20:06   ` Lorenzo Stoakes
2024-07-05 20:30     ` Liam R. Howlett
2024-07-05 20:36       ` Lorenzo Stoakes
2024-07-08 14:49         ` Liam R. Howlett
2024-07-04 18:27 ` [PATCH v3 10/16] mm/mmap: Reposition vma iterator in mmap_region() Liam R. Howlett
2024-07-05 20:18   ` Lorenzo Stoakes
2024-07-05 20:56     ` Liam R. Howlett
2024-07-08 11:08       ` Lorenzo Stoakes
2024-07-08 16:43         ` Liam R. Howlett
2024-07-10 16:48   ` Suren Baghdasaryan
2024-07-10 17:18     ` Liam R. Howlett
2024-07-04 18:27 ` [PATCH v3 11/16] mm/mmap: Track start and end of munmap in vma_munmap_struct Liam R. Howlett
2024-07-05 20:27   ` Lorenzo Stoakes
2024-07-08 14:45     ` Liam R. Howlett
2024-07-10 17:14     ` Suren Baghdasaryan
2024-07-04 18:27 ` [PATCH v3 12/16] mm/mmap: Clean up unmap_region() argument list Liam R. Howlett
2024-07-05 20:33   ` Lorenzo Stoakes
2024-07-10 17:14     ` Suren Baghdasaryan
2024-07-04 18:27 ` [PATCH v3 13/16] mm/mmap: Avoid zeroing vma tree in mmap_region() Liam R. Howlett
2024-07-08 12:18   ` Lorenzo Stoakes
2024-07-08 19:10     ` Liam R. Howlett
2024-07-09 14:27       ` Lorenzo Stoakes
2024-07-09 18:43         ` Liam R. Howlett
2024-07-04 18:27 ` [PATCH v3 14/16] mm/mmap: Use PHYS_PFN " Liam R. Howlett
2024-07-08 12:21   ` Lorenzo Stoakes
2024-07-09 18:35     ` Liam R. Howlett
2024-07-09 18:42       ` Lorenzo Stoakes
2024-07-10 17:32     ` Suren Baghdasaryan
2024-07-04 18:27 ` [PATCH v3 15/16] mm/mmap: Use vms accounted pages " Liam R. Howlett
2024-07-08 12:43   ` Lorenzo Stoakes
2024-07-10 17:43     ` Suren Baghdasaryan
2024-07-04 18:27 ` [PATCH v3 16/16] mm/mmap: Move may_expand_vm() check " Liam R. Howlett
2024-07-08 12:52   ` Lorenzo Stoakes
2024-07-08 20:43     ` Liam R. Howlett
2024-07-09 14:42       ` Liam R. Howlett
2024-07-09 14:51         ` Lorenzo Stoakes
2024-07-09 14:52         ` Liam R. Howlett
2024-07-09 18:13           ` Dave Hansen
2024-07-09 14:45       ` Lorenzo Stoakes
2024-07-10 12:28         ` Michael Ellerman
2024-07-10 12:45           ` Lorenzo Stoakes
2024-07-10 12:59             ` LEROY Christophe
2024-07-10 16:09               ` Liam R. Howlett
2024-07-10 19:27                 ` Dmitry Safonov
2024-07-10 21:04                 ` LEROY Christophe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox