Skip to contentSkip to conversation

btrfs: Return EINVAL when length to trim is less than FSB

PATCH In review Lukas Czerner 2 participants 3 messages Oct 16, 2012 – Oct 24, 2012 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: Return EINVAL when length to trim is less than FSB

Currently if len argument in btrfs_ioctl_fitrim() is smaller than one FSB we will continue and finally return 0 bytes discarded. However if the length to discard is smaller then file system block we should really return EINVAL.

---
 fs/btrfs/ioctl.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
fs/btrfs/ioctl.c +2 -1
index 6116880..3b8b509 100644
@@ -343,7 +343,8 @@ static noinline int btrfs_ioctl_fitrim(struct file *file, void __user *arg)
 		return -EOPNOTSUPP;
 	if (copy_from_user(&range, arg, sizeof(range)))
 		return -EFAULT;
-	if (range.start > total_bytes)
+	if (range.start > total_bytes ||
+	    range.len < fs_info->sb->s_blocksize)
 		return -EINVAL;
 
 	range.len = min(range.len, total_bytes - range.start);
Signature · 1 line
1.7.7.6
#1 lore raw
Quoted 10 lines · Lukas Czerner

Date: Tue, 16 Oct 2012 11:34:36 +0200
From: Lukas Czerner <[email protected]>
To: [email protected]
Cc: [email protected], Lukas Czerner <[email protected]>
Subject: [PATCH] btrfs: Return EINVAL when length to trim is less than FSB

Currently if len argument in btrfs_ioctl_fitrim() is smaller than one FSB we will continue and finally return 0 bytes discarded. However if the length to discard is smaller then file system block we should really return EINVAL.

ping

Quoted 21 lines
---
 fs/btrfs/ioctl.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
fs/btrfs/ioctl.c +2 -1
index 6116880..3b8b509 100644
@@ -343,7 +343,8 @@ static noinline int btrfs_ioctl_fitrim(struct file *file, void __user *arg)
 		return -EOPNOTSUPP;
 	if (copy_from_user(&range, arg, sizeof(range)))
 		return -EFAULT;
-	if (range.start > total_bytes)
+	if (range.start > total_bytes ||
+	    range.len < fs_info->sb->s_blocksize)
 		return -EINVAL;
 
 	range.len = min(range.len, total_bytes - range.start);
#2 lore raw
Quoted 8 lines · Lukáš Czerner
Quoted 6 lines · Lukas Czerner

Date: Tue, 16 Oct 2012 11:34:36 +0200
From: Lukas Czerner <[email protected]>
To: [email protected]
Cc: [email protected], Lukas Czerner <[email protected]>
Subject: [PATCH] btrfs: Return EINVAL when length to trim is less than FSB

Quoted 7 lines
Quoted 4 lines

Currently if len argument in btrfs_ioctl_fitrim() is smaller than one FSB we will continue and finally return 0 bytes discarded. However if the length to discard is smaller then file system block we should really return EINVAL.

ping

This patch has already sit in Josef's btrfs-next tree:

http://git.kernel.org/?p=linux/kernel/git/josef/btrfs-next.git;a=commit;h=cd50b6b30f09446eafdd715db6d59299fcc5b19a