linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs: trim: fix range start validity check
@ 2019-08-07  8:20 Anand Jain
  2019-08-07  8:44 ` Filipe Manana
  0 siblings, 1 reply; 9+ messages in thread
From: Anand Jain @ 2019-08-07  8:20 UTC (permalink / raw)
  To: linux-btrfs; +Cc: wqu

Commit 6ba9fc8e628b (btrfs: Ensure btrfs_trim_fs can trim the whole
filesystem) makes sure we always trim starting from the first block group.
However it also removed the range.start validity check which is set in the
context of the user, where its range is from 0 to maximum of filesystem
totalbytes and so we have to check its validity in the kernel.

Also as in the fstrim(8) [1] the kernel layers may modify the trim range.

[1]
Further, the kernel block layer reserves the right to adjust the discard
ranges to fit raid stripe geometry, non-trim capable devices in a LVM
setup, etc. These reductions would not be reflected in fstrim_range.len
(the --length option).

This patch undos the deleted range::start validity check.

Fixes: 6ba9fc8e628b (btrfs: Ensure btrfs_trim_fs can trim the whole filesystem)
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
  With this patch fstests generic/260 is successful now.

 fs/btrfs/ioctl.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index b431f7877e88..9345fcdf80c7 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -521,6 +521,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 > btrfs_super_total_bytes(fs_info->super_copy))
+		return -EINVAL;
 
 	/*
 	 * NOTE: Don't truncate the range using super->total_bytes.  Bytenr of
-- 
2.21.0 (Apple Git-120)


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2019-08-08  8:41 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-07  8:20 [PATCH] btrfs: trim: fix range start validity check Anand Jain
2019-08-07  8:44 ` Filipe Manana
2019-08-07  8:55   ` Qu Wenruo
2019-08-07  9:43     ` Anand Jain
2019-08-07 11:15       ` Qu Wenruo
2019-08-08  3:53         ` Anand Jain
2019-08-08  5:55           ` Qu Wenruo
2019-08-08  8:34             ` Anand Jain
2019-08-08  8:40               ` Qu Wenruo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).