]> www.infradead.org Git - users/jedix/linux-maple.git/commit
mm: fix (harmless) type confusion in lock_vma_under_rcu()
authorJann Horn <jannh@google.com>
Mon, 5 Aug 2024 12:52:03 +0000 (14:52 +0200)
committerAndrew Morton <akpm@linux-foundation.org>
Sat, 17 Aug 2024 00:52:54 +0000 (17:52 -0700)
commit107d2107779061f49719dcd69f9d7879e11cd046
treedb3803a3193acfabe78edc905291e5bb352e1bb7
parent176f7818034b6b231451a90d7d988c118da1f17b
mm: fix (harmless) type confusion in lock_vma_under_rcu()

There is a (harmless) type confusion in lock_vma_under_rcu(): After
vma_start_read(), we have taken the VMA lock but don't know yet whether
the VMA has already been detached and scheduled for RCU freeing.  At this
point, ->vm_start and ->vm_end are accessed.

vm_area_struct contains a union such that ->vm_rcu uses the same memory as
->vm_start and ->vm_end; so accessing ->vm_start and ->vm_end of a
detached VMA is illegal and leads to type confusion between union members.

Fix it by reordering the vma->detached check above the address checks, and
document the rules for RCU readers accessing VMAs.

This will probably change the number of observed VMA_LOCK_MISS events
(since previously, trying to access a detached VMA whose ->vm_rcu has been
scheduled would bail out when checking the fault address against the
rcu_head members reinterpreted as VMA bounds).

Link: https://lkml.kernel.org/r/20240805-fix-vma-lock-type-confusion-v1-1-9f25443a9a71@google.com
Fixes: 50ee32537206 ("mm: introduce lock_vma_under_rcu to be used from arch-specific code")
Signed-off-by: Jann Horn <jannh@google.com>
Acked-by: Suren Baghdasaryan <surenb@google.com>
Cc: Matthew Wilcox <willy@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/mm_types.h
mm/memory.c