linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Vishal Moola <vishal.moola@gmail.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: syzbot <syzbot+ad1b592fc4483655438b@syzkaller.appspotmail.com>,
	 akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org,  muchun.song@linux.dev,
	syzkaller-bugs@googlegroups.com
Subject: Re: [syzbot] [mm?] KASAN: slab-use-after-free Read in __vma_reservation_common
Date: Mon, 15 Apr 2024 16:02:48 -0700	[thread overview]
Message-ID: <CAOzc2pzFSkwo21Uba3ys5u8=okYbtA2ptyc5bQJwHoS=H_UMtA@mail.gmail.com> (raw)
In-Reply-To: <Zh2m5_MfZ45Uk-vD@casper.infradead.org>

On Mon, Apr 15, 2024 at 3:15 PM Matthew Wilcox <willy@infradead.org> wrote:
>
> On Mon, Apr 15, 2024 at 03:05:44PM -0700, Vishal Moola wrote:
> > Commit 9acad7ba3e25 ("hugetlb: use vmf_anon_prepare() instead of
> > anon_vma_prepare()") may bailout after allocating a folio if we do not
> > hold the mmap lock. When this occurs, vmf_anon_prepare() will release the
> > vma lock. Hugetlb then attempts to call restore_reserve_on_error(),
> > which depends on the vma lock being held.
> >
> > We can move vmf_anon_prepare() prior to the folio allocation in order to
> > avoid calling restore_reserve_on_error() without the vma lock.
>
> But now you're calling vmf_anon_prepare() in the wrong place -- before
> we've determined that we need an anon folio.  So we'll create an
> anon_vma even when we don't need one for this vma.

That's true. Though that can be addressed through something like:

if (!(vma->vm_flags & VM_MAYSHARE)) {
                       ret = vmf_anon_prepare(vmf);
                       if (unlikely(ret))
                               goto out;
}

> This is definitely a pre-existing bug which you've exposed by making it
> happen more easily.  Needs a different fix though.

I interpreted the bug report to showcase how restore_reserve_on_error()
depends on the vma lock being held - and vmf_anon_prepare() drops that
lock by the time we get to restore_reserve_on_error(). In this case, this
would address it without reworking restore_reserve_on_error().

There very well could be something completely different going on, however
I have no ideas as to what that may be.


  reply	other threads:[~2024-04-15 23:03 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-12 13:32 syzbot
2024-04-13 18:34 ` syzbot
2024-04-15 22:05   ` Vishal Moola
2024-04-15 22:15     ` Matthew Wilcox
2024-04-15 23:02       ` Vishal Moola [this message]
2024-04-16  4:35         ` Matthew Wilcox
2024-04-16  5:36           ` Oscar Salvador
2024-04-16  8:13       ` Oscar Salvador
2024-04-17 21:31         ` Andrew Morton
2024-04-16  7:28     ` syzbot
2024-04-18 18:40 ` Vishal Moola
2024-04-18 18:40   ` syzbot
2024-04-18 18:45 ` Vishal Moola
2024-04-19  5:01   ` syzbot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAOzc2pzFSkwo21Uba3ys5u8=okYbtA2ptyc5bQJwHoS=H_UMtA@mail.gmail.com' \
    --to=vishal.moola@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=muchun.song@linux.dev \
    --cc=syzbot+ad1b592fc4483655438b@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox