[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <BE930CC0-7F11-44AE-BCFB-C18A292140FB@gmail.com>
Date: Tue, 24 Sep 2024 13:49:54 +0900
From: Jeongjun Park <aha310510@...il.com>
To: Matthew Wilcox <willy@...radead.org>
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()
> Matthew Wilcox <willy@...radead.org> wrote:
>
> 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.
>
Thanks for the explanation. Then it seems appropriate to annotate
data-race in __folio_test_movable() so that KCSAN ignores it.
I will apply the change and send you a new patch.
Regards,
Jeongjun Park
Powered by blists - more mailing lists