From: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: "Liam R . Howlett" <Liam.Howlett@oracle.com>,
Vlastimil Babka <vbabka@suse.cz>, Jann Horn <jannh@google.com>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
Linus Torvalds <torvalds@linux-foundation.org>,
Peter Xu <peterx@redhat.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>, Mark Brown <broonie@kernel.org>,
"David S . Miller" <davem@davemloft.net>,
Andreas Larsson <andreas@gaisler.com>
Subject: [PATCH hotfix 6.12 v3 0/5] fix error handling in mmap_region() and refactor (hotfixes)
Date: Tue, 29 Oct 2024 13:03:42 +0000 [thread overview]
Message-ID: <cover.1730206735.git.lorenzo.stoakes@oracle.com> (raw)
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.
v3:
* Added correct handling for arm64 MTE which was otherwise broken, as
reported by Mark Brown.
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_validate_flags() and arm64 MTE handling
mm: resolve faulty mmap_region() error path behaviour
arch/arm64/include/asm/mman.h | 29 ++++++--
arch/sparc/include/asm/mman.h | 5 +-
include/linux/mman.h | 23 ++++--
mm/internal.h | 45 ++++++++++++
mm/mmap.c | 128 ++++++++++++++++++----------------
mm/mprotect.c | 4 +-
mm/nommu.c | 7 +-
mm/shmem.c | 3 -
mm/vma.c | 14 ++--
mm/vma.h | 6 +-
10 files changed, 173 insertions(+), 91 deletions(-)
--
2.47.0
next reply other threads:[~2024-10-29 13:04 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-29 13:03 Lorenzo Stoakes [this message]
2024-10-29 13:03 ` [PATCH hotfix 6.12 v3 1/5] mm: avoid unsafe VMA hook invocation when error arises on mmap hook Lorenzo Stoakes
2024-10-29 13:03 ` [PATCH hotfix 6.12 v3 2/5] mm: unconditionally close VMAs on error Lorenzo Stoakes
2024-10-29 13:03 ` [PATCH hotfix 6.12 v3 3/5] mm: refactor map_deny_write_exec() Lorenzo Stoakes
2024-10-29 13:03 ` [PATCH hotfix 6.12 v3 4/5] mm: refactor arch_validate_flags() and arm64 MTE handling Lorenzo Stoakes
2024-10-29 14:38 ` Liam R. Howlett
2024-10-29 15:23 ` Lorenzo Stoakes
2024-10-29 15:43 ` Yang Shi
2024-10-29 15:52 ` Lorenzo Stoakes
2024-10-29 16:08 ` Yang Shi
2024-10-29 16:21 ` Lorenzo Stoakes
2024-10-29 13:03 ` [PATCH hotfix 6.12 v3 5/5] mm: resolve faulty mmap_region() error path behaviour Lorenzo Stoakes
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cover.1730206735.git.lorenzo.stoakes@oracle.com \
--to=lorenzo.stoakes@oracle.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=andreas@gaisler.com \
--cc=broonie@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=davem@davemloft.net \
--cc=jannh@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=peterx@redhat.com \
--cc=torvalds@linux-foundation.org \
--cc=vbabka@suse.cz \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox