Skip to contentSkip to conversation

exfat: preserve the 64-bit FITRIM minimum length

PATCH Applied Hungyu Lin 2 participants 2 messages Oct 31 – Nov 1

Subsystems (3)
lore
Share & tools
lore

Hungyu Lin

author
#0 lore raw

PATCH 1/1 exfat: preserve the 64-bit FITRIM minimum length

The FITRIM minimum length is a 64-bit value, but exfat_ioctl_fitrim() uses max_t(unsigned int, ...) to compare it with the discard granularity. This truncates the requested minimum on both 32-bit and 64-bit kernels.

For example, fstrim --minimum 4GiB can trim smaller free extents because the minimum wraps to zero before being raised to the device granularity.

Use a u64 comparison to preserve the userspace value. exfat_trim_fs() already stores the minimum cluster count in a u64.

Fixes 654762df2ec7 ("exfat: add support ioctl and FITRIM function")
---
 fs/exfat/file.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/exfat/file.c +2 -2
index 1386149916bb..4e7a2fb30279 100644
@@ -586,8 +586,8 @@ static int exfat_ioctl_fitrim(struct inode *inode, unsigned long arg)
 	if (copy_from_user(&range, (struct fstrim_range __user *)arg, sizeof(range)))
 		return -EFAULT;
 
-	range.minlen = max_t(unsigned int, range.minlen,
-				bdev_discard_granularity(inode->i_sb->s_bdev));
+	range.minlen = max_t(u64, range.minlen,
+			     bdev_discard_granularity(inode->i_sb->s_bdev));
 
 	ret = exfat_trim_fs(inode, &range);
 	if (ret < 0)
Signature · 1 line
2.43.0
maintainer Applied
#1 lore raw
Quoted 8 lines · Hungyu Lin

The FITRIM minimum length is a 64-bit value, but exfat_ioctl_fitrim() uses max_t(unsigned int, ...) to compare it with the discard granularity. This truncates the requested minimum on both 32-bit and 64-bit kernels.

For example, fstrim --minimum 4GiB can trim smaller free extents because the minimum wraps to zero before being raised to the device granularity.

Quoted 6 lines

Use a u64 comparison to preserve the userspace value. exfat_trim_fs() already stores the minimum cluster count in a u64.

Fixes 654762df2ec7 ("exfat: add support ioctl and FITRIM function")

Applied it to #dev.
Thanks!