arch/arm64/include/asm/mman.h | 10 ++- include/linux/mman.h | 7 +- mm/internal.h | 19 ++++++ mm/mmap.c | 119 ++++++++++++++++++---------------- mm/nommu.c | 9 ++- mm/shmem.c | 3 - mm/util.c | 33 ++++++++++ 7 files changed, 129 insertions(+), 71 deletions(-)
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.
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 | 119 ++++++++++++++++++----------------
mm/nommu.c | 9 ++-
mm/shmem.c | 3 -
mm/util.c | 33 ++++++++++
7 files changed, 129 insertions(+), 71 deletions(-)
--
2.47.0
* Lorenzo Stoakes <lorenzo.stoakes@oracle.com> [241115 07:40]:
> 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.
>
Besides that one line fix (thanks Vlastimil!), these look good.
Reviewed-by: Liam R. Howlett <Liam.Howlett@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 | 119 ++++++++++++++++++----------------
> mm/nommu.c | 9 ++-
> mm/shmem.c | 3 -
> mm/util.c | 33 ++++++++++
> 7 files changed, 129 insertions(+), 71 deletions(-)
>
> --
> 2.47.0
On 11/15/24 13:40, Lorenzo Stoakes wrote:
> 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().
Seems adding 9a9d0b829901 ("mm: move dummy_vm_ops out of a header") as
prerequisity would have been less work, but I didn't find a bug in your
adjustments so seems fine to me.
>
> * 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.
>
> 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
Aside from the suspected memory leak I reported for 4/4,
Reviewed-by: Vlastimil Babka <vbabka@suse.cz>
> arch/arm64/include/asm/mman.h | 10 ++-
> include/linux/mman.h | 7 +-
> mm/internal.h | 19 ++++++
> mm/mmap.c | 119 ++++++++++++++++++----------------
> mm/nommu.c | 9 ++-
> mm/shmem.c | 3 -
> mm/util.c | 33 ++++++++++
> 7 files changed, 129 insertions(+), 71 deletions(-)
>
> --
> 2.47.0
© 2016 - 2026 Red Hat, Inc.