Skip to content

Commit 5750676

Browse files
dgchinnertorvalds
authored andcommitted
fs/remap: constrain dedupe of EOF blocks
If dedupe of an EOF block is not constrainted to match against only other EOF blocks with the same EOF offset into the block, it can match against any other block that has the same matching initial bytes in it, even if the bytes beyond EOF in the source file do not match. Fix this by constraining the EOF block matching to only match against other EOF blocks that have identical EOF offsets and data. This allows "whole file dedupe" to continue to work without allowing eof blocks to randomly match against partial full blocks with the same data. Reported-by: Ansgar Lößer <ansgar.loesser@tu-darmstadt.de> Fixes: 1383a7e ("vfs: check file ranges before cloning files") Link: https://lore.kernel.org/linux-fsdevel/a7c93559-4ba1-df2f-7a85-55a143696405@tu-darmstadt.de/ Signed-off-by: Dave Chinner <dchinner@redhat.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent b047602 commit 5750676

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

fs/remap_range.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ static int generic_remap_checks(struct file *file_in, loff_t pos_in,
7171
* Otherwise, make sure the count is also block-aligned, having
7272
* already confirmed the starting offsets' block alignment.
7373
*/
74-
if (pos_in + count == size_in) {
74+
if (pos_in + count == size_in &&
75+
(!(remap_flags & REMAP_FILE_DEDUP) || pos_out + count == size_out)) {
7576
bcount = ALIGN(size_in, bs) - pos_in;
7677
} else {
7778
if (!IS_ALIGNED(count, bs))

0 commit comments

Comments
 (0)