[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZvIjRZgyAGLmys7c@casper.infradead.org>
Date: Tue, 24 Sep 2024 03:26:13 +0100
From: Matthew Wilcox <willy@...radead.org>
To: Jeongjun Park <aha310510@...il.com>
Cc: David Hildenbrand <david@...hat.com>, akpm@...ux-foundation.org,
wangkefeng.wang@...wei.com, ziy@...dia.com, linux-mm@...ck.org,
linux-kernel@...r.kernel.org, stable@...r.kernel.org,
syzbot <syzkaller@...glegroups.com>
Subject: Re: [PATCH] mm: migrate: fix data-race in migrate_folio_unmap()
On Tue, Sep 24, 2024 at 09:28:44AM +0900, Jeongjun Park wrote:
> > Matthew Wilcox <willy@...radead.org> wrote:
> >
> > On Mon, Sep 23, 2024 at 05:56:40PM +0200, David Hildenbrand wrote:
> >>> On 22.09.24 17:17, Jeongjun Park wrote:
> >>> I found a report from syzbot [1]
> >>>
> >>> When __folio_test_movable() is called in migrate_folio_unmap() to read
> >>> folio->mapping, a data race occurs because the folio is read without
> >>> protecting it with folio_lock.
> >>>
> >>> This can cause unintended behavior because folio->mapping is initialized
> >>> to a NULL value. Therefore, I think it is appropriate to call
> >>> __folio_test_movable() under the protection of folio_lock to prevent
> >>> data-race.
> >>
> >> We hold a folio reference, would we really see PAGE_MAPPING_MOVABLE flip?
> >> Hmm
> >
> > No; this shows a page cache folio getting truncated. It's fine; really
> > a false alarm from the tool. I don't think the proposed patch
> > introduces any problems, but it's all a bit meh.
> >
>
> Well, I still don't understand why it's okay to read folio->mapping
> without folio_lock .
Because it can't be changed in a way which changes the value of
__folio_test_movable(). We have a refcount on the folio at this point,
so it can't be freed. And __folio_set_movable() happens at allocation.
Powered by blists - more mailing lists