Skip to content

fix error handling in mmap_region() and refactor (hotfixes)

Lorenzo Stoakes linux-mm lkml stable 2 versions – Applied

Status from this message: This is a note to let you know that I've just added the patch titled

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest4 patches 6 repliesApplied
  2. v15 patches 10 repliesApplied

Changes in v2 from the cover letter

* Fix 6.1-specific memory leak if second attempt at merge succeeds.

Patches in v2 Applied

#Subject and filesSizeRepliesApplied
1/4mm: avoid unsafe VMA hook invocation when error arises on mmap hookmm/internal.h mm/mmap.c mm/nommu.c +1 more+34 -41 reply
2/4mm: unconditionally close VMAs on errormm/internal.h mm/mmap.c mm/nommu.c +1 more+27 -101 reply
3/4mm: refactor arch_calc_vm_flag_bits() and arm64 MTE handlingarch/arm64/include/asm/mman.h include/linux/mman.h mm/mmap.c +2 more+13 -113 replies
4/4mm: resolve faulty mmap_region() error path behaviourmm/mmap.c+57 -471 reply

Reviews trailers per patch

All 4 patches have a Reviewed-by or Acked-by.

PatchLiam R. HowlettVlastimil BabkaJann HornMark BrownCatalin Marinas
1/4R-b R-b R-b R-b R-b R-b
2/4R-b R-b R-b R-b R-b R-b
3/4R-b R-b R-b R-b
4/4R-b R-b R-b R-b T-b T-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 5 reviewers.

Read the v2 thread

Cover letter [PATCH 6.1.y v2 0/4] fix error handling in mmap_region() and refactor (hotfixes)

Critical fixes for mmap_region(), backported to 6.1.y.

Some notes on differences from upstream:

* We do NOT take commit 0fb4a7ad270b ("mm: refactor map_deny_write_exec()"), as this refactors code only introduced in 6.2.

* We make reference in "mm: refactor arch_calc_vm_flag_bits() and arm64 MTE handling" to parisc, but the referenced functionality does not exist in this kernel.

* In this kernel is_shared_maywrite() does not exist and the code uses VM_SHARED to determine whether mapping_map_writable() / mapping_unmap_writable() should be invoked. This backport therefore follows suit.

* The vma_dummy_vm_ops static global doesn't exist in this kernel, so we use a local static variable in mmap_file() and vma_close().

* Each version of these series is confronted by a slightly different mmap_region(), so we must adapt the change for each stable version. The approach remains the same throughout, however, and we correctly avoid closing the VMA part way through any __mmap_region() operation.

* This version of the kernel uses mas_preallocate() rather than the vma_iter_prealloc() wrapper and mas_destroy() rather than the vma_iter_free() wrapper, however the logic of rearranging the positioning of these remains the same, as well as avoiding the iterator leak we previously had on some error paths.

v2:
* Fix 6.1-specific memory leak if second attempt at merge succeeds.

v1:
https://lore.kernel.org/all/4cb9b846f0c4efcc4a2b21453eea4e4d0136efc8.1731671441.git.lorenzo.stoakes@oracle.com/

Lorenzo Stoakes (4):
mm: avoid unsafe VMA hook invocation when error arises on mmap hook
mm: unconditionally close VMAs on error
mm: refactor arch_calc_vm_flag_bits() and arm64 MTE handling
mm: resolve faulty mmap_region() error path behaviour

 arch/arm64/include/asm/mman.h |  10 ++-
 include/linux/mman.h          |   7 +-
 mm/internal.h                 |  19 ++++++
 mm/mmap.c                     | 120 ++++++++++++++++++----------------
 mm/nommu.c                    |   9 ++-
 mm/shmem.c                    |   3 -
 mm/util.c                     |  33 ++++++++++
 7 files changed, 130 insertions(+), 71 deletions(-)

--
2.47.0