[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <cover.1730224667.git.lorenzo.stoakes@oracle.com>
Date: Tue, 29 Oct 2024 18:11:43 +0000
From: Lorenzo Stoakes <lorenzo.stoakes@...cle.com>
To: Andrew Morton <akpm@...ux-foundation.org>
Cc: "Liam R . Howlett" <Liam.Howlett@...cle.com>,
Vlastimil Babka <vbabka@...e.cz>, Jann Horn <jannh@...gle.com>,
linux-kernel@...r.kernel.org, linux-mm@...ck.org,
Linus Torvalds <torvalds@...ux-foundation.org>,
Peter Xu <peterx@...hat.com>,
Catalin Marinas <catalin.marinas@....com>,
Will Deacon <will@...nel.org>, Mark Brown <broonie@...nel.org>,
"David S . Miller" <davem@...emloft.net>,
Andreas Larsson <andreas@...sler.com>,
"James E . J . Bottomley" <James.Bottomley@...senPartnership.com>,
Helge Deller <deller@....de>
Subject: [PATCH hotfix 6.12 v4 0/5] fix error handling in mmap_region() and refactor (hotfixes)
NOTE: This should be applied on mm-hotfixes-unstable in Andrew's mm tree as
it relies on other pending hotfixes.
The mmap_region() function is somewhat terrifying, with spaghetti-like
control flow and numerous means by which issues can arise and incomplete
state, memory leaks and other unpleasantness can occur.
A large amount of the complexity arises from trying to handle errors late
in the process of mapping a VMA, which forms the basis of recently observed
issues with resource leaks and observable inconsistent state.
This series goes to great lengths to simplify how mmap_region() works and
to avoid unwinding errors late on in the process of setting up the VMA for
the new mapping, and equally avoids such operations occurring while the VMA
is in an inconsistent state.
The patches in this series comprise the minimal changes required to resolve
existing issues in mmap_region() error handling, in order that they can be
hotfixed and backported. There is additionally a follow up series which
goes further, separated out from the v1 series and sent and updated
separately.
v4:
* Reworked solution to use arch_calc_vm_flag_bits() as suggested by
Catalin. This also ensures we do not break MTE in a KVM scenario.
v3:
* Added correct handling for arm64 MTE which was otherwise broken, as
reported by Mark Brown.
https://lore.kernel.org/all/cover.1730206735.git.lorenzo.stoakes@oracle.com/
v2:
* Marked first 4 patches as hotfixes, the rest as not.
* Improved comment in vma_close() as per Vlastimil.
* Updated hole byte count as per Jann.
* Updated comment in map_deny_write_exec() as per Jann.
* Dropped unnecessary vma_iter_free() as per Vlastimil, Liam.
* Corrected vms_abort_munmap_vmas() mistaken assumption about nr_pages as
per Vlastimil.
* Changed order of initial checks in mmap_region() to avoid user-visible
side effects as per Vlastimil, Liam.
* Corrected silly incorrect use of vma field.
* Various style corrects as per Liam.
* Fix horrid mistake with merge VMA, reworked the logic to avoid that
nonsense altogether.
* Add fields to map state rather than using vmg fields to avoid
confusion/risk of vmg state changing breaking things.
* Replaced last commit removing merge retry with one that retries the
merge, only sanely.
https://lore.kernel.org/all/cover.1729715266.git.lorenzo.stoakes@oracle.com/
v1:
https://lore.kernel.org/all/cover.1729628198.git.lorenzo.stoakes@oracle.com/
Lorenzo Stoakes (5):
mm: avoid unsafe VMA hook invocation when error arises on mmap hook
mm: unconditionally close VMAs on error
mm: refactor map_deny_write_exec()
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 ++-
arch/parisc/include/asm/mman.h | 5 +-
include/linux/mman.h | 28 +++++--
mm/internal.h | 45 ++++++++++++
mm/mmap.c | 130 ++++++++++++++++++---------------
mm/mprotect.c | 2 +-
mm/nommu.c | 9 +--
mm/shmem.c | 3 -
mm/vma.c | 14 ++--
mm/vma.h | 6 +-
10 files changed, 159 insertions(+), 93 deletions(-)
--
2.47.0
Powered by blists - more mailing lists