Skip to content

Commit 6434e69

Browse files
Barry Songakpm00
authored andcommitted
mm: arm64: fix the out-of-bounds issue in contpte_clear_young_dirty_ptes
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/[email protected] Fixes: 89e8685 ("mm/arm64: override clear_young_dirty_ptes() batch helper") Signed-off-by: Barry Song <[email protected]> Reviewed-by: Baolin Wang <[email protected]> Acked-by: Lance Yang <[email protected]> Acked-by: David Hildenbrand <[email protected]> Acked-by: Chris Li <[email protected]> Cc: Barry Song <[email protected]> Cc: Ryan Roberts <[email protected]> Cc: Jeff Xie <[email protected]> Cc: Kefeng Wang <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Minchan Kim <[email protected]> Cc: Muchun Song <[email protected]> Cc: Peter Xu <[email protected]> Cc: Yang Shi <[email protected]> Cc: Yin Fengwei <[email protected]> Cc: Zach O'Keefe <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Will Deacon <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 94d46bf commit 6434e69

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

arch/arm64/mm/contpte.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ void contpte_clear_young_dirty_ptes(struct vm_area_struct *vma,
376376
* clearing access/dirty for the whole block.
377377
*/
378378
unsigned long start = addr;
379-
unsigned long end = start + nr;
379+
unsigned long end = start + nr * PAGE_SIZE;
380380

381381
if (pte_cont(__ptep_get(ptep + nr - 1)))
382382
end = ALIGN(end, CONT_PTE_SIZE);
@@ -386,7 +386,7 @@ void contpte_clear_young_dirty_ptes(struct vm_area_struct *vma,
386386
ptep = contpte_align_down(ptep);
387387
}
388388

389-
__clear_young_dirty_ptes(vma, start, ptep, end - start, flags);
389+
__clear_young_dirty_ptes(vma, start, ptep, (end - start) / PAGE_SIZE, flags);
390390
}
391391
EXPORT_SYMBOL_GPL(contpte_clear_young_dirty_ptes);
392392

0 commit comments

Comments
 (0)