]> git.itanic.dy.fi Git - linux-stable/commitdiff
xfs: only remap the written blocks in xfs_reflink_end_cow_extent
authorChristoph Hellwig <hch@lst.de>
Mon, 16 Oct 2023 15:28:52 +0000 (17:28 +0200)
committerChandan Babu R <chandanbabu@kernel.org>
Mon, 13 Nov 2023 03:39:19 +0000 (09:09 +0530)
xfs_reflink_end_cow_extent looks up the COW extent and the data fork
extent at offset_fsb, and then proceeds to remap the common subset
between the two.

It does however not limit the remapped extent to the passed in
[*offset_fsbm end_fsb] range and thus potentially remaps more blocks than
the one handled by the current I/O completion.  This means that with
sufficiently large data and COW extents we could be remapping COW fork
mappings that have not been written to, leading to a stale data exposure
on a powerfail event.

We use to have a xfs_trim_range to make the remap fit the I/O completion
range, but that got (apparently accidentally) removed in commit
df2fd88f8ac7 ("xfs: rewrite xfs_reflink_end_cow to use intents").

Note that I've only found this by code inspection, and a test case would
probably require very specific delay and error injection.

Fixes: df2fd88f8ac7 ("xfs: rewrite xfs_reflink_end_cow to use intents")
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
fs/xfs/xfs_reflink.c

index 658edee8381dcdca656135a74a9b5a1b6e13a8cb..e5b62dc2846644c142b04423fbec10e57d81c34d 100644 (file)
@@ -784,6 +784,7 @@ xfs_reflink_end_cow_extent(
                }
        }
        del = got;
+       xfs_trim_extent(&del, *offset_fsb, end_fsb - *offset_fsb);
 
        /* Grab the corresponding mapping in the data fork. */
        nmaps = 1;