mirror of
https://github.com/torvalds/linux.git
synced 2026-11-20 13:03:48 +00:00
mm/vma: read anon_vma carefully in validate_mm()
Commit38564710f4("mm: implement and use vma_has_anon_rmap(), silence KCSAN") rather clumsily converted the read of vma->anon_vma into a vma_has_anon_rmap() without accounting for the separation between assignment of anon_vma and later use of it. vma_has_anon_rmap() is intended as an optimistic check, so doesn't need to protect against a torn read in vma->anon_vma. The caller is expected to take care of this themselves if they then in fact access the field. validate_mm() does indeed then reference the field, so resolve the issue via READ_ONCE(), and simplify the code by separating this into a new function validate_mm_anon_rmap(). Finally, add a vma_assert_stabilised() to make it clear the required state of the VMA. [[email protected]: reduce ifdeffery] Link: https://lore.kernel.org/auhn01dpDzK47igy@thinkstation Link: https://lore.kernel.org/[email protected] Fixes:38564710f4("mm: implement and use vma_has_anon_rmap(), silence KCSAN") Signed-off-by: Lorenzo Stoakes (ARM) <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Reported-by: <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Reported-by: Songsen Yang <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Cc: Liam R. Howlett <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: Jann Horn <[email protected]> Cc: Pedro Falcato <[email protected]> Cc: Kiryl Shutsemau <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Lance Yang <[email protected]>
This commit is contained in:
committed by
Andrew Morton
parent
ccf8bda05b
commit
ff82ce7f90
@@ -4370,9 +4370,7 @@ anon_rmap_tree_iter_first(struct anon_vma *anon_vma,
|
||||
struct anon_vma_chain *
|
||||
anon_rmap_tree_iter_next(struct anon_vma_chain *avc,
|
||||
pgoff_t pgoff_start, pgoff_t pgoff_last);
|
||||
#ifdef CONFIG_DEBUG_VM_RB
|
||||
void anon_rmap_tree_verify(struct anon_vma_chain *avc);
|
||||
#endif
|
||||
|
||||
#define anon_rmap_tree_foreach(avc, anon_vma, pgoff_start, pgoff_last) \
|
||||
for (avc = anon_rmap_tree_iter_first(anon_vma, pgoff_start, pgoff_last); \
|
||||
|
||||
@@ -676,6 +676,26 @@ static int dup_anon_vma(struct vm_area_struct *dst,
|
||||
}
|
||||
|
||||
#ifdef CONFIG_DEBUG_VM_MAPLE_TREE
|
||||
static void validate_mm_anon_rmap(struct vm_area_struct *vma)
|
||||
{
|
||||
struct anon_vma *anon_vma;
|
||||
struct anon_vma_chain *avc;
|
||||
|
||||
if (!IS_ENABLED(CONFIG_DEBUG_VM_RB))
|
||||
return;
|
||||
|
||||
vma_assert_stabilised(vma);
|
||||
|
||||
anon_vma = READ_ONCE(vma->anon_vma);
|
||||
if (!anon_vma)
|
||||
return;
|
||||
|
||||
anon_vma_lock_read(anon_vma);
|
||||
list_for_each_entry(avc, &vma->anon_vma_chain, same_vma)
|
||||
anon_rmap_tree_verify(avc);
|
||||
anon_vma_unlock_read(anon_vma);
|
||||
}
|
||||
|
||||
void validate_mm(struct mm_struct *mm)
|
||||
{
|
||||
int bug = 0;
|
||||
@@ -685,10 +705,6 @@ void validate_mm(struct mm_struct *mm)
|
||||
|
||||
mt_validate(&mm->mm_mt);
|
||||
for_each_vma(vmi, vma) {
|
||||
#ifdef CONFIG_DEBUG_VM_RB
|
||||
struct anon_vma *anon_vma = vma->anon_vma;
|
||||
struct anon_vma_chain *avc;
|
||||
#endif
|
||||
unsigned long vmi_start, vmi_end;
|
||||
bool warn = 0;
|
||||
|
||||
@@ -709,14 +725,8 @@ void validate_mm(struct mm_struct *mm)
|
||||
vma_iter_dump_tree(&vmi);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_DEBUG_VM_RB
|
||||
if (vma_has_anon_rmap(vma)) {
|
||||
anon_vma_lock_read(anon_vma);
|
||||
list_for_each_entry(avc, &vma->anon_vma_chain, same_vma)
|
||||
anon_rmap_tree_verify(avc);
|
||||
anon_vma_unlock_read(anon_vma);
|
||||
}
|
||||
#endif
|
||||
validate_mm_anon_rmap(vma);
|
||||
|
||||
/* Check for a infinite loop */
|
||||
if (++i > mm->map_count + 10) {
|
||||
i = -1;
|
||||
|
||||
Reference in New Issue
Block a user