Skip to contentSkip to conversation

vfs: return -EOVERFLOW in generic_remap_checks() when overflow check fails

PATCH Applied Julian Sun 4 participants 8 messages Sep 20, 2024

Subsystems (2)

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore

Julian Sun

author
#0 lore raw

PATCH 3/3 vfs: return -EOVERFLOW in generic_remap_checks() when overflow check fails

Keep it consistent with the handling of the same check within generic_copy_file_checks().
Also, returning -EOVERFLOW in this case is more appropriate.

---
 fs/remap_range.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/remap_range.c +1 -1
index 6fdeb3c8cb70..a26521ded5c8 100644
@@ -42,7 +42,7 @@ static int generic_remap_checks(struct file *file_in, loff_t pos_in,
 
 	/* The start of both ranges must be aligned to an fs block. */
 	if (!IS_ALIGNED(pos_in, bs) || !IS_ALIGNED(pos_out, bs))
-		return -EINVAL;
+		return -EOVERFLOW;
 
 	/* Ensure offsets don't wrap. */
 	if (check_add_overflow(pos_in, count, &tmp) ||
Signature · 1 line
2.39.2
#1 lore raw
FYI: kernel test robot notices the stable kernel rule is not satisfied.

Hi,

Thanks for your patch.

FYI: kernel test robot notices the stable kernel rule is not satisfied.

The check is based on https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html#option-1

Rule: add the tag "Cc: [email protected]" in the sign-off area to have the patch automatically included in the stable tree.
Subject: [PATCH 3/3] vfs: return -EOVERFLOW in generic_remap_checks() when overflow check fails

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Reviewed-by on v1 3/3
#2 lore raw
In reply to Julian Sun
Quoted 3 lines · Julian Sun

Keep it consistent with the handling of the same check within generic_copy_file_checks().
Also, returning -EOVERFLOW in this case is more appropriate.

Maybe:

Keep the errno value consistent with the equivalent check in generic_copy_file_checks() that returns -EOVERFLOW, which feels like the more appropriate value to return compared to the overly generic -EINVAL.

Otherwise looks good:

#3 lore raw
Quoted 10 lines · Christoph Hellwig
Quoted 3 lines · Julian Sun

Keep it consistent with the handling of the same check within generic_copy_file_checks().
Also, returning -EOVERFLOW in this case is more appropriate.

Maybe:

Keep the errno value consistent with the equivalent check in generic_copy_file_checks() that returns -EOVERFLOW, which feels like the more appropriate value to return compared to the overly generic -EINVAL.

The manpage for clone/dedupe/exchange don't say anything about EOVERFLOW, but they do have this to say about EINVAL:

EINVAL
The filesystem does not support reflinking the ranges of the given files.

Does this errno code change cause any regressions in fstests?

--D

Quoted 4 lines

Otherwise looks good:

#4 lore raw
Quoted 12 lines · Darrick J. Wong
Quoted 10 lines · Christoph Hellwig
Quoted 3 lines · Julian Sun

Keep it consistent with the handling of the same check within generic_copy_file_checks().
Also, returning -EOVERFLOW in this case is more appropriate.

Maybe:

Keep the errno value consistent with the equivalent check in generic_copy_file_checks() that returns -EOVERFLOW, which feels like the more appropriate value to return compared to the overly generic -EINVAL.

Quoted 6 lines

The manpage for clone/dedupe/exchange don't say anything about EOVERFLOW, but they do have this to say about EINVAL:

EINVAL
The filesystem does not support reflinking the ranges of the given files.

Which isn't exactly the integer overflow case described here :)

Quoted 1 line

Does this errno code change cause any regressions in fstests?

Given our rather sparse test coverage of it I doubt it, but it would be great to have that confirmed by the submitter.

While we're talking about that - a simple exerciser for the overflow condition for xfstests would be very useful to have.

#5 lore raw
Quoted 13 lines · Christoph Hellwig
Quoted 12 lines · Darrick J. Wong
Quoted 10 lines · Christoph Hellwig
Quoted 3 lines · Julian Sun

Keep it consistent with the handling of the same check within generic_copy_file_checks().
Also, returning -EOVERFLOW in this case is more appropriate.

Maybe:

Keep the errno value consistent with the equivalent check in generic_copy_file_checks() that returns -EOVERFLOW, which feels like the more appropriate value to return compared to the overly generic -EINVAL.

Quoted 8 lines
Quoted 6 lines

The manpage for clone/dedupe/exchange don't say anything about EOVERFLOW, but they do have this to say about EINVAL:

EINVAL
The filesystem does not support reflinking the ranges of the given files.

Which isn't exactly the integer overflow case described here :)

Hm? This patch is touching the error code you get for failing alignment checks, not the one you get for failing check_add_overflow. EOVERFLOW seems like an odd return code for unaligned arguments. Though you're right that EINVAL is verrry vague.

Quoted 4 lines
Quoted 1 line

Does this errno code change cause any regressions in fstests?

Given our rather sparse test coverage of it I doubt it, but it would be great to have that confirmed by the submitter.

Yes. :)

Quoted 2 lines

While we're talking about that - a simple exerciser for the overflow condition for xfstests would be very useful to have.

Yes, there's <cough> supposed to be one that does that.

$ git grep -ci CLONE.*invalid.argument
common/filter.btrfs:1
tests/btrfs/035.out:1
tests/btrfs/052.out:12
tests/btrfs/096.out:1
tests/btrfs/112.out:16
tests/btrfs/113.out:1
tests/btrfs/229:1
tests/generic/157.out:6
tests/generic/303.out:4
tests/generic/518.out:1

--D

#6 lore raw
Quoted 6 lines · Darrick J. Wong
Quoted 1 line

Which isn't exactly the integer overflow case described here :)

Hm? This patch is touching the error code you get for failing alignment checks, not the one you get for failing check_add_overflow. EOVERFLOW seems like an odd return code for unaligned arguments. Though you're right that EINVAL is verrry vague.

I misread the patch (or rather mostly read the description). Yes, -EOVERFLOW is rather odd here. And generic_copy_file_checks doesn't even have alignment checks, so the message is wrong as well. I'll wait for Jun what the intention was here - maybe the diff got misapplied and this was supposed to be applied to an overflow check that returns -EINVAL?

author
#7 lore raw
Quoted 9 lines · Christoph Hellwig <[email protected]> 于2024年9月20日周五 23:07写道:
Quoted 6 lines · Darrick J. Wong
Quoted 1 line

Which isn't exactly the integer overflow case described here :)

Hm? This patch is touching the error code you get for failing alignment checks, not the one you get for failing check_add_overflow. EOVERFLOW seems like an odd return code for unaligned arguments. Though you're right that EINVAL is verrry vague.

Quoted 6 lines

I misread the patch (or rather mostly read the description). Yes, -EOVERFLOW is rather odd here. And generic_copy_file_checks doesn't even have alignment checks, so the message is wrong as well. I'll wait for Jun what the intention was here - maybe the diff got misapplied and this was supposed to be applied to an overflow check that returns -EINVAL?

Yeah... The patch was originally intended for overflow check and sourced from [1], differs from its description. After applying it to the latest kernel version, there were no warnings or errors, but I suspect there may be an issue with the git apply process. I'll fix it in the patch v2, thanks.

[1]: https://lore.kernel.org/linux-fsdevel/[email protected]/

Quoted 1 line

Thanks,

Signature · 1 line
Julian Sun <[email protected]>