]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
mm: arm64: fix the out-of-bounds issue in contpte_clear_young_dirty_ptes
authorBarry Song <v-songbaohua@oppo.com>
Fri, 24 May 2024 00:54:44 +0000 (12:54 +1200)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 6 Jun 2024 02:19:24 +0000 (19:19 -0700)
We are passing a huge nr to __clear_young_dirty_ptes() right now.  While
we should pass the number of pages, we are actually passing CONT_PTE_SIZE.
This is causing lots of crashes of MADV_FREE, panic oops could vary
everytime.

Link: https://lkml.kernel.org/r/20240524005444.135417-1-21cnbao@gmail.com
Fixes: 89e86854fb0a ("mm/arm64: override clear_young_dirty_ptes() batch helper")
Signed-off-by: Barry Song <v-songbaohua@oppo.com>
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Acked-by: Lance Yang <ioworker0@gmail.com>
Acked-by: David Hildenbrand <david@redhat.com>
Acked-by: Chris Li <chrisl@kernel.org>
Cc: Barry Song <21cnbao@gmail.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Jeff Xie <xiehuan09@gmail.com>
Cc: Kefeng Wang <wangkefeng.wang@huawei.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Muchun Song <songmuchun@bytedance.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Yang Shi <shy828301@gmail.com>
Cc: Yin Fengwei <fengwei.yin@intel.com>
Cc: Zach O'Keefe <zokeefe@google.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
arch/arm64/mm/contpte.c

index 9f9486de0004ddbabdfc18424f85c9e686a85119..a3edced29ac1383564f432139ed01def1913d28b 100644 (file)
@@ -376,7 +376,7 @@ void contpte_clear_young_dirty_ptes(struct vm_area_struct *vma,
         * clearing access/dirty for the whole block.
         */
        unsigned long start = addr;
-       unsigned long end = start + nr;
+       unsigned long end = start + nr * PAGE_SIZE;
 
        if (pte_cont(__ptep_get(ptep + nr - 1)))
                end = ALIGN(end, CONT_PTE_SIZE);
@@ -386,7 +386,7 @@ void contpte_clear_young_dirty_ptes(struct vm_area_struct *vma,
                ptep = contpte_align_down(ptep);
        }
 
-       __clear_young_dirty_ptes(vma, start, ptep, end - start, flags);
+       __clear_young_dirty_ptes(vma, start, ptep, (end - start) / PAGE_SIZE, flags);
 }
 EXPORT_SYMBOL_GPL(contpte_clear_young_dirty_ptes);