linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH stable v6.1] mm/mmap: Fix extra maple tree write
@ 2023-07-06 18:51 Liam R. Howlett
  2023-07-07 15:55 ` Greg KH
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Liam R. Howlett @ 2023-07-06 18:51 UTC (permalink / raw)
  To: linux-kernel; +Cc: Andrew Morton, Liam R. Howlett, John Hsu, stable, linux-mm

commit 0503ea8f5ba73eb3ab13a81c1eefbaf51405385a upstream.

This was inadvertently fixed during the removal of __vma_adjust().

When __vma_adjust() is adjusting next with a negative value (pushing
vma->vm_end lower), there would be two writes to the maple tree.  The
first write is unnecessary and uses all allocated nodes in the maple
state.  The second write is necessary but will need to allocate nodes
since the first write has used the allocated nodes.  This may be a
problem as it may not be safe to allocate at this time, such as a low
memory situation.  Fix the issue by avoiding the first write and only
write the adjusted "next" VMA.

Reported-by: John Hsu <John.Hsu@mediatek.com>
Link: https://lore.kernel.org/lkml/9cb8c599b1d7f9c1c300d1a334d5eb70ec4d7357.camel@mediatek.com/
Cc: stable@vger.kernel.org
Cc: linux-mm@kvack.org
Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
---
 mm/mmap.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mm/mmap.c b/mm/mmap.c
index b8af52db3bbe..bb2e0ff0ef61 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -767,7 +767,8 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
 	}
 	if (end != vma->vm_end) {
 		if (vma->vm_end > end) {
-			if (!insert || (insert->vm_start != end)) {
+			if ((vma->vm_end + adjust_next != end) &&
+			    (!insert || (insert->vm_start != end))) {
 				vma_mas_szero(&mas, end, vma->vm_end);
 				mas_reset(&mas);
 				VM_WARN_ON(insert &&
-- 
2.39.2



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-07-16 15:08 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-06 18:51 [PATCH stable v6.1] mm/mmap: Fix extra maple tree write Liam R. Howlett
2023-07-07 15:55 ` Greg KH
2023-07-07 16:45   ` Liam R. Howlett
2023-07-12  0:54     ` Liam R. Howlett
2023-07-14 14:44       ` Vlastimil Babka
2023-07-14 15:00         ` Liam R. Howlett
2023-07-16 15:05       ` Greg KH
2023-07-16 15:05 ` Patch "mm/mmap: Fix extra maple tree write" has been added to the 6.1-stable tree gregkh
2023-07-16 15:08 ` Patch "mm/mmap: Fix extra maple tree write" has been added to the 5.4-stable tree gregkh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox