]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
mm: call ->free_folio() directly in folio_unmap_invalidate()
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Mon, 13 Apr 2026 18:43:11 +0000 (19:43 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 22 Apr 2026 11:30:49 +0000 (13:30 +0200)
commitb667df39d98a7a24be7c2a40ff0863dac1ad2cd7
tree5e78f7869c274f10c463d457bf23ead191a009f3
parentc29ff288a2d97a6f4640a498a367cf0eb91312eb
mm: call ->free_folio() directly in folio_unmap_invalidate()

commit 615d9bb2ccad42f9e21d837431e401db2e471195 upstream.

We can only call filemap_free_folio() if we have a reference to (or hold a
lock on) the mapping.  Otherwise, we've already removed the folio from the
mapping so it no longer pins the mapping and the mapping can be removed,
causing a use-after-free when accessing mapping->a_ops.

Follow the same pattern as __remove_mapping() and load the free_folio
function pointer before dropping the lock on the mapping.  That lets us
make filemap_free_folio() static as this was the only caller outside
filemap.c.

Link: https://lore.kernel.org/20260413184314.3419945-1-willy@infradead.org
Fixes: fb7d3bc41493 ("mm/filemap: drop streaming/uncached pages when writeback completes")
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reported-by: Google Big Sleep <big-sleep-vuln-reports+bigsleep-501448199@google.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Jan Kara <jack@suse.cz>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
mm/filemap.c
mm/internal.h
mm/truncate.c