FAILED: patch "[PATCH] maple_tree: fix MA_STATE_PREALLOC flag in mas_preallocate()" failed to apply to 6.1-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.1-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.1.y
git checkout FETCH_HEAD
git cherry-pick -x fba46a5d83ca8decb338722fb4899026d8d9ead2
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2025063033-shrink-submersed-b5de@gregkh' --subject-prefix 'PATCH 6.1.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From fba46a5d83ca8decb338722fb4899026d8d9ead2 Mon Sep 17 00:00:00 2001
From: "Liam R. Howlett" <[email protected]>
Date: Mon, 16 Jun 2025 14:45:20 -0400
Subject: [PATCH] maple_tree: fix MA_STATE_PREALLOC flag in mas_preallocate()
Temporarily clear the preallocation flag when explicitly requesting allocations. Pre-existing allocations are already counted against the request through mas_node_count_gfp(), but the allocations will not happen if the MA_STATE_PREALLOC flag is set. This flag is meant to avoid re-allocating in bulk allocation mode, and to detect issues with preallocation calculations.
The MA_STATE_PREALLOC flag should also always be set on zero allocations so that detection of underflow allocations will print a WARN_ON() during consumption.
User visible effect of this flaw is a WARN_ON() followed by a null pointer dereference when subsequent requests for larger number of nodes is ignored, such as the vma merge retry in mmap_region() caused by drivers altering the vma flags (which happens in v6.6, at least)
lib/maple_tree.c +3 -1
@@ -5527,8 +5527,9 @@ int mas_preallocate(struct ma_state *mas, void *entry, gfp_t gfp) mas->store_type =mas_wr_store_type (&wr_mas); request =mas_prealloc_calc (&wr_mas, entry);if (!request) -return ret; + goto set_flag; + mas->mas_flags &= ~MA_STATE_PREALLOC ;mas_node_count_gfp (mas, request, gfp);if (mas_is_err (mas)) {mas_set_alloc_req (mas,0 );
@@ -5538,6 +5539,7 @@ int mas_preallocate(struct ma_state *mas, void *entry, gfp_t gfp)return ret; } +set_flag: mas->mas_flags |=MA_STATE_PREALLOC ;return ret; }
PATCH 1/1 maple_tree: fix MA_STATE_PREALLOC flag in mas_preallocate()
Temporarily clear the preallocation flag when explicitly requesting allocations. Pre-existing allocations are already counted against the request through mas_node_count_gfp(), but the allocations will not happen if the MA_STATE_PREALLOC flag is set. This flag is meant to avoid re-allocating in bulk allocation mode, and to detect issues with preallocation calculations.
The MA_STATE_PREALLOC flag should also always be set on zero allocations so that detection of underflow allocations will print a WARN_ON() during consumption.
User visible effect of this flaw is a WARN_ON() followed by a null pointer dereference when subsequent requests for larger number of nodes is ignored, such as the vma merge retry in mmap_region() caused by drivers altering the vma flags (which happens in v6.6, at least)
--- lib/maple_tree.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
lib/maple_tree.c +4 -2
@@ -5802,10 +5802,12 @@ int mas_preallocate(struct ma_state *mas, void *entry, gfp_t gfp) {int ret; + mas->mas_flags &= ~MA_STATE_PREALLOC ;mas_node_count_gfp (mas,1 +mas_mt_height (mas) *3 , gfp); - mas->mas_flags |=MA_STATE_PREALLOC ; -if (likely (!mas_is_err (mas))) +if (likely (!mas_is_err (mas))) { + mas->mas_flags |=MA_STATE_PREALLOC ;return 0 ; + }mas_set_alloc_req (mas,0 ); ret =xa_err (mas->node);
Signature · 1 line
2.47.2
Sasha Levin
maintainerRe: [PATCH 6.1.y] maple_tree: fix MA_STATE_PREALLOC flag in mas_preallocate()
[ Sasha's backport helper bot ]
Hi,
Summary of potential issues:
⚠️ Found matching upstream commit but patch is missing proper reference to it
Found matching upstream commit: fba46a5d83ca8decb338722fb4899026d8d9ead2
Status in newer kernel trees:
6.15.y | Present (different SHA1: 0c23ae32bfba)
6.12.y | Present (different SHA1: 1d026fb05207)
6.6.y | Not found
Note: The patch differs from the upstream commit:
---
1: fba46a5d83ca8 < -: ------------- maple_tree: fix MA_STATE_PREALLOC flag in mas_preallocate() -: ------------- > 1: 25bfd68644907 maple_tree: fix MA_STATE_PREALLOC flag in mas_preallocate()
---
Results of testing on various branches:
| Branch | Patch Apply | Build Test | |---------------------------|-------------|------------| | stable/linux-6.1.y | Success | Success |