gfs2: Revalidate the cached writeback mapping after a punch
gfs2_writeback_range() keeps using the mapping cached in wpc->iomap
for every folio it covers, but punch_hole() can free blocks inside
that mapping while writeback is still walking the file.
This happens on an ordinary buffered write. gfs2_file_buffered_write()
runs with page faults disabled, so a source page that is not resident
makes the write come up short, and gfs2_iomap_end() punches the
unwritten blocks it had just allocated. The retry allocates new
blocks, but writeback writes the retried folios to the freed ones
through the stale mapping. The new blocks are never written and keep
whatever they held before, exposing another file's data. On a
cluster the freed blocks may already belong to another node.
Found in XenServer, where suspend images on GFS2 picked up other
guests' memory. A reproducer that writes 512 KiB extents from a buffer
whose tail is repeatedly dropped with MADV_DONTNEED, with
sync_file_range() running alongside, corrupted 11 blocks in 20 rounds
before this change and none after.
Count block allocations and deallocations per inode. In writeback,
treat a mapping as valid only while the count is unchanged.
Fixes: 2164f9b91869 ("gfs2: use iomap for buffered I/O in ordered and writeback mode")
Cc: Christoph Hellwig <hch@lst.de>
Cc: stable@vger.kernel.org
Co-developed-by: Andreas Gruenbacher <agruenba@redhat.com>
Signed-off-by: Mark Syms <mark.syms@citrix.com>
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
3 files changed