From: Matthew Wilcox <willy@infradead.org>
To: Dmitry Vyukov <dvyukov@google.com>
Cc: syzbot <syzbot+606f94dfeaaa45124c90@syzkaller.appspotmail.com>,
djwong@kernel.org, hch@infradead.org,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, linux-xfs@vger.kernel.org,
syzkaller-bugs@googlegroups.com
Subject: Re: [syzbot] [fs?] [mm?] KCSAN: data-race in __filemap_remove_folio / folio_mapping (2)
Date: Mon, 24 Apr 2023 15:10:52 +0100 [thread overview]
Message-ID: <ZEaN7PP794H2vbe/@casper.infradead.org> (raw)
In-Reply-To: <CACT4Y+YeV8zU2x+3dpJJFez5_33ic3q7B2_+KYrcNOQxooRWpw@mail.gmail.com>
On Mon, Apr 24, 2023 at 03:49:04PM +0200, Dmitry Vyukov wrote:
> On Mon, 24 Apr 2023 at 15:21, Matthew Wilcox <willy@infradead.org> wrote:
> >
> > On Mon, Apr 24, 2023 at 09:38:43AM +0200, Dmitry Vyukov wrote:
> > > On Mon, 24 Apr 2023 at 09:19, syzbot
> > > <syzbot+606f94dfeaaa45124c90@syzkaller.appspotmail.com> wrote:
> > > If I am reading this correctly, it can lead to NULL derefs in
> > > folio_mapping() if folio->mapping is read twice. I think
> > > folio->mapping reads/writes need to use READ/WRITE_ONCE if racy.
> >
> > You aren't reading it correctly.
> >
> > mapping = folio->mapping;
> > if ((unsigned long)mapping & PAGE_MAPPING_FLAGS)
> > return NULL;
> >
> > return mapping;
> >
> > The racing write is storing NULL. So it might return NULL or it might
> > return the old mapping, or it might return NULL. Either way, the caller
> > has to be prepared for NULL to be returned.
> >
> > It's a false posiive, but probably worth silencing with a READ_ONCE().
>
> Yes, but the end of the function does not limit effects of races. I
I thought it did. I was under the impression that the compiler was not
allowed to extract loads from within the function and move them outside.
Maybe that changed since C99.
> to this:
>
> if (!((unsigned long)folio->mapping & PAGE_MAPPING_FLAGS) && folio->mapping)
> if (test_bit(AS_UNEVICTABLE, &folio->mapping->flags))
>
> which does crash.
Yes, if the compiler is allowed to do that, then that's a possibility.
next prev parent reply other threads:[~2023-04-24 14:11 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-24 7:19 [syzbot] [fs?] [mm?] KCSAN: data-race in __filemap_remove_folio / folio_mapping (2) syzbot
2023-04-24 7:38 ` Dmitry Vyukov
2023-04-24 13:21 ` Matthew Wilcox
2023-04-24 13:49 ` Dmitry Vyukov
2023-04-24 14:10 ` Matthew Wilcox [this message]
2023-04-24 14:21 ` Dmitry Vyukov
2024-04-18 4:27 ` Jeongjun Park
2024-04-18 4:27 ` 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=ZEaN7PP794H2vbe/@casper.infradead.org \
--to=willy@infradead.org \
--cc=djwong@kernel.org \
--cc=dvyukov@google.com \
--cc=hch@infradead.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-xfs@vger.kernel.org \
--cc=syzbot+606f94dfeaaa45124c90@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.com \
/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;
as well as URLs for NNTP newsgroup(s).