Skip to contentSkip to conversation

FAILED: patch "[PATCH] mm/vma: correctly unaccount on mmap_prepare() failure" failed to apply to 6.18-stable tree

PATCH New [email protected] 2 participants 2 messages Sep 22

Subsystems (3)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

The patch below does not apply to the 6.18-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.18.y
git checkout FETCH_HEAD
git cherry-pick -x 6cc27d82196385fe06853319f74312a7d8019726
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026092235-visor-glance-dc8e@gregkh' --subject-prefix 'PATCH 6.18.y' 'HEAD^..'

Possible dependencies:

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 6cc27d82196385fe06853319f74312a7d8019726 Mon Sep 17 00:00:00 2001
From: "Lorenzo Stoakes (ARM)" <[email protected]>
Date: Wed, 2 Sep 2026 19:08:08 +0100
Subject: [PATCH] mm/vma: correctly unaccount on mmap_prepare() failure

__mmap_setup() accounts memory for relevant mappings via:

security_vm_enough_memory_mm()
-> __vm_enough_memory()

    -> vm_acct_memory()

If __mmap_setup() fails, this indicates that this accounting did not take place, and thus it's appropriate for __mmap_region() to jump to abort_munmap.

However if call_mmap_prepare() fails, it also jumps there and any accounted memory is not correctly unaccounted.

Fix this by handling each error separately.

Fixes c84bf6dd2b83 ("mm: introduce new .mmap_prepare() file callback")
Cc Jann Horn <[email protected]>
Cc Liam R. Howlett <[email protected]>
Cc Pedro Falcato <[email protected]>
Cc Vlastimil Babka <[email protected]>
mm/vma.c +4 -2
index 35e7a64855fa..f29abb30956b 100644
@@ -2859,10 +2859,12 @@ static unsigned long __mmap_region(struct file *file, unsigned long addr,
 	map.check_ksm_early = can_set_ksm_flags_early(&map);
 
 	error = __mmap_setup(&map, &desc, uf);
-	if (!error && have_mmap_prepare)
-		error = call_mmap_prepare(&map, &desc);
 	if (error)
 		goto abort_munmap;
+	if (have_mmap_prepare)
+		error = call_mmap_prepare(&map, &desc);
+	if (error)
+		goto unacct_error;
 
 	if (map.check_ksm_early)
 		update_ksm_flags(&map);
maintainer
#1 lore raw

PATCH 1/1 mm/vma: correctly unaccount on mmap_prepare() failure

From: "Lorenzo Stoakes (ARM)" <[email protected]>

[ Upstream commit 6cc27d82196385fe06853319f74312a7d8019726 ]

__mmap_setup() accounts memory for relevant mappings via:

security_vm_enough_memory_mm()
-> __vm_enough_memory()

    -> vm_acct_memory()

If __mmap_setup() fails, this indicates that this accounting did not take place, and thus it's appropriate for __mmap_region() to jump to abort_munmap.

However if call_mmap_prepare() fails, it also jumps there and any accounted memory is not correctly unaccounted.

Fix this by handling each error separately.

Fixes c84bf6dd2b83 ("mm: introduce new .mmap_prepare() file callback")
Cc Jann Horn <[email protected]>
Cc Liam R. Howlett <[email protected]>
Cc Pedro Falcato <[email protected]>
Cc Vlastimil Babka <[email protected]>
---
 mm/vma.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
mm/vma.c +4 -2
index 30148e6af7751..dcaa2d8998bfb 100644
@@ -2693,10 +2693,12 @@ static unsigned long __mmap_region(struct file *file, unsigned long addr,
 	map.check_ksm_early = can_set_ksm_flags_early(&map);
 
 	error = __mmap_prepare(&map, uf);
-	if (!error && have_mmap_prepare)
-		error = call_mmap_prepare(&map);
 	if (error)
 		goto abort_munmap;
+	if (have_mmap_prepare)
+		error = call_mmap_prepare(&map);
+	if (error)
+		goto unacct_error;
 
 	if (map.check_ksm_early)
 		update_ksm_flags(&map);
Signature · 1 line
2.53.0