Re: [syzbot] [mm?] WARNING: suspicious RCU usage in mas_walk (2)

From: Liam R. Howlett
Date: Thu Jul 27 2023 - 14:13:36 EST


* Jann Horn <jannh@xxxxxxxxxx> [230727 14:00]:
> On Thu, Jul 27, 2023 at 7:22 PM Suren Baghdasaryan <surenb@xxxxxxxxxx> wrote:
> > On Thu, Jul 27, 2023 at 9:48 AM Liam R. Howlett <Liam.Howlett@xxxxxxxxxx> wrote:
> > >
> > > * syzbot <syzbot+8645fe63c4d22c8d27b8@xxxxxxxxxxxxxxxxxxxxxxxxx> [230726 02:57]:
> > > > syzbot has bisected this issue to:
> > > >
> > > > commit a52f58b34afe095ebc5823684eb264404dad6f7b
> > > > Author: Matthew Wilcox (Oracle) <willy@xxxxxxxxxxxxx>
> > > > Date: Mon Jul 24 18:54:10 2023 +0000
> > > >
> > > > mm: handle faults that merely update the accessed bit under the VMA lock
> > > >
> > > > bisection log: https://syzkaller.appspot.com/x/bisect.txt?x=1783585ea80000
> > > > start commit: [unknown]
> > > > git tree: linux-next
> > > > final oops: https://syzkaller.appspot.com/x/report.txt?x=1443585ea80000
> > > > console output: https://syzkaller.appspot.com/x/log.txt?x=1043585ea80000
> > > > kernel config: https://syzkaller.appspot.com/x/.config?x=f481ab36ce878b84
> > > > dashboard link: https://syzkaller.appspot.com/bug?extid=8645fe63c4d22c8d27b8
> > > > syz repro: https://syzkaller.appspot.com/x/repro.syz?x=1697cec9a80000
> > > > C reproducer: https://syzkaller.appspot.com/x/repro.c?x=1566986ea80000
> > > >
> > > > Reported-by: syzbot+8645fe63c4d22c8d27b8@xxxxxxxxxxxxxxxxxxxxxxxxx
> > > > Fixes: a52f58b34afe ("mm: handle faults that merely update the accessed bit under the VMA lock")
> > > >
> > > > For information about bisection process see: https://goo.gl/tpsmEJ#bisection
> > >
> > > This is caused by walking the maple tree without holding the mmap or rcu
> > > read lock when per-vma locking is used for the page fault.
> > >
> > > We could wrap the find_mergeable_anon_vma() walk with an rcu read lock,
> > > but I am unsure if that's the correct way to handle this as the anon_vma
> > > lock is taken later in __anon_vma_prepare(). Note that the anon_vma
> > > lock is per-anon_vma, so we cannot just relocate that lock.
> >
> > Hmm. lock_vma_under_rcu() specifically checks for vma->anon_vma==NULL
> > condition (see [1]) to avoid going into find_mergeable_anon_vma() (a
> > check inside anon_vma_prepare() should prevent that). So, it should
> > fall back to mmap_lock'ing.
>
> This syzkaller report applies to a tree with Willy's in-progress patch
> series, where lock_vma_under_rcu() only checks for vma->anon_vma if
> vma_is_anonymous() is true - it permits private non-anonymous VMAs
> (which require an anon_vma for handling write faults) even if they
> don't have an anon_vma.
>
> The commit bisected by syzkaller
> (https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=a52f58b34afe095ebc5823684eb264404dad6f7b)
> removes the vma_is_anonymous() check in handle_pte_fault(), so it lets
> us reach do_wp_page() with a non-anonymous private VMA without
> anon_vma, even though that requires allocation of an anon_vma.
>
> So I think this is pretty clearly an issue with Willy's in-progress
> patch series that syzkaller blamed correctly.
>

Thanks for the analysis and quick response Jann and Suren.

I'll stop digging now.

Regards,
Liam