* [PATCH v2] dax: fix wrong error code returned from dax_dedupe_file_range_compare()
@ 2026-10-12 14:49 jianyungao89
2026-10-12 15:08 ` sashiko-bot
2026-10-12 16:38 ` Darrick J. Wong
0 siblings, 2 replies; 3+ messages in thread
From: jianyungao89 @ 2026-10-12 14:49 UTC (permalink / raw)
To: linux-kernel
Cc: Jianyun Gao, stable, Jan Kara, Dan Williams, Matthew Wilcox,
Alexander Viro, Christian Brauner, Darrick J. Wong, Brian Foster,
open list:FILESYSTEM DIRECT ACCESS (DAX),
open list:FILESYSTEM DIRECT ACCESS (DAX)
From: Jianyun Gao <jianyungao89@gmail.com>
When dax_range_compare_iter() returns a negative error code (e.g. -EIO),
dax_dedupe_file_range_compare() incorrectly returns 'ret' which holds the
positive return value from iomap_iter() indicating more iterations remain.
This positive value leaks to the caller, where vfs_dedupe_file_range()
interprets it as success (bytes_deduped = len), causing userspace to
incorrectly believe deduplication completed.
Return 'status' instead to propagate the actual error code.
Fixes: 39eb05112987 ("dax: advance the iomap_iter on dedupe range")
Cc: stable@vger.kernel.org
Signed-off-by: Jianyun Gao <jianyungao89@gmail.com>
Reviewed-by: Jan Kara <jack@suse.cz>
---
Changes in v2:
- Add Fixes tag and Cc stable
- Add Reviewed-by tag from Jan Kara
v1: Link: https://lore.kernel.org/lkml/20261010021010.19575-1-jianyungao89@gmail.com/
fs/dax.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/dax.c b/fs/dax.c
index 6ba50142eeb2..1f6a4fbb97bd 100644
--- a/fs/dax.c
+++ b/fs/dax.c
@@ -2261,7 +2261,7 @@ int dax_dedupe_file_range_compare(struct inode *src, loff_t srcoff,
status = dax_range_compare_iter(&src_iter, &dst_iter,
min(src_iter.len, dst_iter.len), same);
if (status < 0)
- return ret;
+ return status;
src_iter.status = dst_iter.status = status;
}
return ret;
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v2] dax: fix wrong error code returned from dax_dedupe_file_range_compare()
2026-10-12 14:49 [PATCH v2] dax: fix wrong error code returned from dax_dedupe_file_range_compare() jianyungao89
@ 2026-10-12 15:08 ` sashiko-bot
2026-10-12 16:38 ` Darrick J. Wong
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-10-12 15:08 UTC (permalink / raw)
To: jianyungao89; +Cc: nvdimm
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] fs/dax: out-of-bounds length and size calculations in dax_range_compare_iter()
--
commit 01ad9c7e5da5c800a76808134a31ff80911b589c
Author: Jianyun Gao <jianyungao89@gmail.com>
dax: fix wrong error code returned from dax_dedupe_file_range_compare()
When dax_range_compare_iter() returns a negative error code (e.g. -EIO),
dax_dedupe_file_range_compare() incorrectly returns ret which holds the
positive return value from iomap_iter() indicating more iterations remain.
This positive value leaks to the caller, where vfs_dedupe_file_range()
interprets it as success, causing userspace to incorrectly believe
deduplication completed.
> diff --git a/fs/dax.c b/fs/dax.c
> index 08adeaed2baf1..97b6212bfa898 100644
> --- a/fs/dax.c
> +++ b/fs/dax.c
> @@ -2254,7 +2254,7 @@ int dax_dedupe_file_range_compare(struct inode *src, loff_t srcoff,
> status = dax_range_compare_iter(&src_iter, &dst_iter,
> min(src_iter.len, dst_iter.len), same);
> if (status < 0)
> - return ret;
> + return status;
[Severity: High]
Does propagating this error code expose latent out-of-bounds calculations in
dax_range_compare_iter()?
Inside dax_range_compare_iter(), the length is incorrectly clamped using the
total extent length rather than the remaining mapped length:
fs/dax.c:dax_range_compare_iter() {
...
len = min(len, min(smap->length, dmap->length));
...
}
If the file offset is inside the extent and the requested length is large, len
will exceed the valid remaining mapped length. This directly triggers a
WARN_ON_ONCE(count > iomap_length(iter)) in iomap_iter_advance() and aborts
with -EIO.
Additionally, when calling dax_iomap_direct_access(), the size calculation
uses the absolute file offset instead of a page offset:
fs/dax.c:dax_range_compare_iter() {
...
ret = dax_iomap_direct_access(smap, pos1, ALIGN(pos1 + len, PAGE_SIZE),
&saddr, NULL);
...
}
Since pos1 is an absolute file offset, for large file offsets this massive
size exceeds the physical device bounds, causing dax_iomap_direct_access()
to fail with -EINVAL.
Now that the error code is correctly propagated, will these calculations
actively cause dedupe operations to fail?
> src_iter.status = dst_iter.status = status;
> }
> return ret;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261012144925.6728-1-jianyungao89@gmail.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH v2] dax: fix wrong error code returned from dax_dedupe_file_range_compare()
2026-10-12 14:49 [PATCH v2] dax: fix wrong error code returned from dax_dedupe_file_range_compare() jianyungao89
2026-10-12 15:08 ` sashiko-bot
@ 2026-10-12 16:38 ` Darrick J. Wong
1 sibling, 0 replies; 3+ messages in thread
From: Darrick J. Wong @ 2026-10-12 16:38 UTC (permalink / raw)
To: jianyungao89
Cc: linux-kernel, stable, Jan Kara, Dan Williams, Matthew Wilcox,
Alexander Viro, Christian Brauner, Brian Foster,
open list:FILESYSTEM DIRECT ACCESS (DAX),
open list:FILESYSTEM DIRECT ACCESS (DAX)
On Mon, Oct 12, 2026 at 10:49:24PM +0800, jianyungao89@gmail.com wrote:
> From: Jianyun Gao <jianyungao89@gmail.com>
>
> When dax_range_compare_iter() returns a negative error code (e.g. -EIO),
> dax_dedupe_file_range_compare() incorrectly returns 'ret' which holds the
> positive return value from iomap_iter() indicating more iterations remain.
> This positive value leaks to the caller, where vfs_dedupe_file_range()
> interprets it as success (bytes_deduped = len), causing userspace to
> incorrectly believe deduplication completed.
>
> Return 'status' instead to propagate the actual error code.
>
> Fixes: 39eb05112987 ("dax: advance the iomap_iter on dedupe range")
> Cc: stable@vger.kernel.org
> Signed-off-by: Jianyun Gao <jianyungao89@gmail.com>
> Reviewed-by: Jan Kara <jack@suse.cz>
Seems fine to me,
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
--D
> ---
>
> Changes in v2:
> - Add Fixes tag and Cc stable
> - Add Reviewed-by tag from Jan Kara
>
> v1: Link: https://lore.kernel.org/lkml/20261010021010.19575-1-jianyungao89@gmail.com/
>
> fs/dax.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/dax.c b/fs/dax.c
> index 6ba50142eeb2..1f6a4fbb97bd 100644
> --- a/fs/dax.c
> +++ b/fs/dax.c
> @@ -2261,7 +2261,7 @@ int dax_dedupe_file_range_compare(struct inode *src, loff_t srcoff,
> status = dax_range_compare_iter(&src_iter, &dst_iter,
> min(src_iter.len, dst_iter.len), same);
> if (status < 0)
> - return ret;
> + return status;
> src_iter.status = dst_iter.status = status;
> }
> return ret;
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-10-12 16:38 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-12 14:49 [PATCH v2] dax: fix wrong error code returned from dax_dedupe_file_range_compare() jianyungao89
2026-10-12 15:08 ` sashiko-bot
2026-10-12 16:38 ` Darrick J. Wong
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.