From b6498daeb408bd527d5ed58adcf436cbca5fed79 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Sun, 16 Jul 2023 17:08:16 +0200 Subject: [PATCH] 5.4-stable patches added patches: mm-mmap-fix-extra-maple-tree-write.patch --- .../mm-mmap-fix-extra-maple-tree-write.patch | 50 +++++++++++++++++++ queue-5.4/series | 1 + 2 files changed, 51 insertions(+) create mode 100644 queue-5.4/mm-mmap-fix-extra-maple-tree-write.patch diff --git a/queue-5.4/mm-mmap-fix-extra-maple-tree-write.patch b/queue-5.4/mm-mmap-fix-extra-maple-tree-write.patch new file mode 100644 index 00000000000..447be2cc79e --- /dev/null +++ b/queue-5.4/mm-mmap-fix-extra-maple-tree-write.patch @@ -0,0 +1,50 @@ +From Liam.Howlett@oracle.com Sun Jul 16 17:02:51 2023 +From: "Liam R. Howlett" +Date: Thu, 6 Jul 2023 14:51:35 -0400 +Subject: mm/mmap: Fix extra maple tree write +To: linux-kernel@vger.kernel.org +Cc: Andrew Morton , "Liam R. Howlett" , John Hsu , stable@vger.kernel.org, linux-mm@kvack.org +Message-ID: <20230706185135.2235532-1-Liam.Howlett@oracle.com> + +From: "Liam R. Howlett" + +based on 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 +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 +Signed-off-by: Greg Kroah-Hartman +--- + 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 + diff --git a/queue-5.4/series b/queue-5.4/series index 38ab0be551d..56c0471bdce 100644 --- a/queue-5.4/series +++ b/queue-5.4/series @@ -178,3 +178,4 @@ btrfs-fix-race-when-deleting-quota-root-from-the-dirty-cow-roots-list.patch asoc-mediatek-mt8173-fix-irq-error-path.patch arm-orion5x-fix-d2net-gpio-initialization.patch fs-no-need-to-check-source.patch +mm-mmap-fix-extra-maple-tree-write.patch -- 2.47.3