FIDEDUPERANGE allows the VFS to shorten each destination range. An unaligned, non-EOF request shorter than the filesystem block size can therefore be shortened to zero. vfs_dedupe_file_range_one() then returns zero, but vfs_dedupe_file_range() reports the original length and success even though it made no progress. Reporting the actual return value would expose this as a successful zero-byte operation. While diagnosing the over-reporting, Darrick Wong pointed out that a caller such as duperemove, which advances only by bytes_deduped and has no zero-progress guard, can retry that range forever. Return per-destination -EINVAL when a nonzero request is shortened to zero. Keep the historical result for an explicit zero-length request: bytes_deduped remains zero with FILE_DEDUPE_RANGE_SAME. Other destinations in the same ioctl continue to be processed. Apply this guard before correcting bytes_deduped so that no intermediate kernel exposes a successful zero-progress result. With this guard and the following reporting correction, installed duperemove rounded its match to 98304 bytes and exited with status 0. Installed rmlint exercised the guard: it received 98304 bytes of progress, then 0/-EINVAL for the 1696-byte remainder, and exited with status 1 rather than retrying indefinitely. Link: https://lore.kernel.org/linux-fsdevel/Y93BkIA4Nd3IJAk+@magnolia/ Signed-off-by: Matthias Goergens --- fs/remap_range.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/remap_range.c b/fs/remap_range.c index 26afbbbfb10c2..53330aa26b86f 100644 --- a/fs/remap_range.c +++ b/fs/remap_range.c @@ -555,6 +555,8 @@ int vfs_dedupe_file_range(struct file *file, struct file_dedupe_range *same) info->status = FILE_DEDUPE_RANGE_DIFFERS; else if (deduped < 0) info->status = deduped; + else if (!deduped && len) + info->status = -EINVAL; else info->bytes_deduped = len; -- 2.55.0 FIDEDUPERANGE promises to return the number of bytes successfully deduplicated in bytes_deduped. vfs_dedupe_file_range_one() can shorten a request and returns the resulting byte count. However, vfs_dedupe_file_range() discards that value and reports the original request length. The VFS ioctl originally accumulated the returned byte count in commit 54dbc1517237 ("vfs: hoist the btrfs deduplication ioctl to the vfs"). Commit 5740c99e9d30 ("vfs: dedupe: return int") changed the filesystem callback to return status and substituted the requested length. The helper once again returns a loff_t byte count, but the stale assignment remained. Ansgar Lößer corrected the assignment in commit 4a57a8400075 ("vf/remap: return the amount of bytes actually deduplicated"), after reports from Max Schlecht and Björn Scheuermann. The change was reverted the next day after generic/517 exposed its expectation of the over-reported value and the userspace impact still needed investigation. Restore that correction. A nonzero request shortened to zero now fails with -EINVAL due to the preceding change. Callers that advance by bytes_deduped therefore cannot retry such a range forever. Updated generic/517 and raw multi-destination coverage in generic/806 pass on both btrfs and XFS. Installed duperemove rounded its match to 98304 bytes and exited with status 0. Installed rmlint received 98304 bytes of progress followed by 0/-EINVAL for the 1696-byte remainder and exited with status 1 instead of silently accepting the over-reported request. Link: https://lore.kernel.org/linux-fsdevel/5548ef63-62f9-4f46-5793-03165ceccacc@tu-darmstadt.de/ Link: https://lore.kernel.org/all/20220714223238.GH3600936@dread.disaster.area/ Signed-off-by: Matthias Goergens --- fs/remap_range.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/remap_range.c b/fs/remap_range.c index 53330aa26b86f..9fedc22b52761 100644 --- a/fs/remap_range.c +++ b/fs/remap_range.c @@ -558,7 +558,7 @@ int vfs_dedupe_file_range(struct file *file, struct file_dedupe_range *same) else if (!deduped && len) info->status = -EINVAL; else - info->bytes_deduped = len; + info->bytes_deduped = deduped; next_loop: if (fatal_signal_pending(current)) -- 2.55.0