[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHk-=wgw8oZwA6k8rVuzczkZUP26P2MAtFmM4k8TqdtfDr9eTg@mail.gmail.com>
Date: Tue, 21 Oct 2025 21:13:28 -1000
From: Linus Torvalds <torvalds@...ux-foundation.org>
To: Pedro Falcato <pfalcato@...e.de>
Cc: Kiryl Shutsemau <kirill@...temov.name>, Andrew Morton <akpm@...ux-foundation.org>,
David Hildenbrand <david@...hat.com>, Matthew Wilcox <willy@...radead.org>,
Alexander Viro <viro@...iv.linux.org.uk>, Christian Brauner <brauner@...nel.org>, Jan Kara <jack@...e.cz>,
linux-mm@...ck.org, linux-fsdevel@...r.kernel.org,
linux-kernel@...r.kernel.org, Kiryl Shutsemau <kas@...nel.org>
Subject: Re: [PATCH] mm/filemap: Implement fast short reads
On Tue, 21 Oct 2025 at 21:08, Pedro Falcato <pfalcato@...e.de> wrote:
>
> I think we may still have a problematic (rare, possibly theoretical) race here where:
>
> T0 T1 T3
> filemap_read_fast_rcu() | |
> folio = xas_load(&xas); | |
> /* ... */ | /* truncate or reclaim frees folio, bumps delete |
> | seq */ | folio_alloc() from e.g secretmem
> | | set_direct_map_invalid_noflush(!!)
> memcpy_from_file_folio() | |
>
> We may have to use copy_from_kernel_nofault() here? Or is something else stopping this from happening?
Explain how the sequence count doesn't catch this?
We read the sequence count before we do the xas_load(), and we verify
it after we've done the memcpy_from_folio.
The whole *point* is that the copy itself is not race-free. That's
*why* we do the sequence count.
And only after the sequence count has been verified do we then copy
the result to user space.
So the "maybe this buffer content is garbage" happens, but it only
happens in the temporary kernel on-stack buffer, not visibly to the
user.
Linus
Powered by blists - more mailing lists