Skip to content

Commit efd4149

Browse files
xzpeterakpm00
authored andcommitted
mm/smaps: don't access young/dirty bit if pte unpresent
These bits should only be valid when the ptes are present. Introducing two booleans for it and set it to false when !pte_present() for both pte and pmd accountings. The bug is found during code reading and no real world issue reported, but logically such an error can cause incorrect readings for either smaps or smaps_rollup output on quite a few fields. For example, it could cause over-estimate on values like Shared_Dirty, Private_Dirty, Referenced. Or it could also cause under-estimate on values like LazyFree, Shared_Clean, Private_Clean. Link: https://lkml.kernel.org/r/[email protected] Fixes: b1d4d9e ("proc/smaps: carefully handle migration entries") Fixes: c94b692 ("/proc/PID/smaps: Add PMD migration entry parsing") Signed-off-by: Peter Xu <[email protected]> Reviewed-by: Vlastimil Babka <[email protected]> Reviewed-by: David Hildenbrand <[email protected]> Reviewed-by: Yang Shi <[email protected]> Cc: Konstantin Khlebnikov <[email protected]> Cc: Huang Ying <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent a39c5d3 commit efd4149

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

fs/proc/task_mmu.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -527,10 +527,12 @@ static void smaps_pte_entry(pte_t *pte, unsigned long addr,
527527
struct vm_area_struct *vma = walk->vma;
528528
bool locked = !!(vma->vm_flags & VM_LOCKED);
529529
struct page *page = NULL;
530-
bool migration = false;
530+
bool migration = false, young = false, dirty = false;
531531

532532
if (pte_present(*pte)) {
533533
page = vm_normal_page(vma, addr, *pte);
534+
young = pte_young(*pte);
535+
dirty = pte_dirty(*pte);
534536
} else if (is_swap_pte(*pte)) {
535537
swp_entry_t swpent = pte_to_swp_entry(*pte);
536538

@@ -560,8 +562,7 @@ static void smaps_pte_entry(pte_t *pte, unsigned long addr,
560562
if (!page)
561563
return;
562564

563-
smaps_account(mss, page, false, pte_young(*pte), pte_dirty(*pte),
564-
locked, migration);
565+
smaps_account(mss, page, false, young, dirty, locked, migration);
565566
}
566567

567568
#ifdef CONFIG_TRANSPARENT_HUGEPAGE

0 commit comments

Comments
 (0)