Skip to content

Commit 173431b

Browse files
adam900710kdave
authored andcommitted
btrfs: defrag: reject unknown flags of btrfs_ioctl_defrag_range_args
Add extra sanity check for btrfs_ioctl_defrag_range_args::flags. This is not really to enhance fuzzing tests, but as a preparation for future expansion on btrfs_ioctl_defrag_range_args. In the future we're going to add new members, allowing more fine tuning for btrfs defrag. Without the -ENONOTSUPP error, there would be no way to detect if the kernel supports those new defrag features. CC: stable@vger.kernel.org # 4.14+ Reviewed-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 3324d05 commit 173431b

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

fs/btrfs/ioctl.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2602,6 +2602,10 @@ static int btrfs_ioctl_defrag(struct file *file, void __user *argp)
26022602
ret = -EFAULT;
26032603
goto out;
26042604
}
2605+
if (range.flags & ~BTRFS_DEFRAG_RANGE_FLAGS_SUPP) {
2606+
ret = -EOPNOTSUPP;
2607+
goto out;
2608+
}
26052609
/* compression requires us to start the IO */
26062610
if ((range.flags & BTRFS_DEFRAG_RANGE_COMPRESS)) {
26072611
range.flags |= BTRFS_DEFRAG_RANGE_START_IO;

include/uapi/linux/btrfs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,9 @@ struct btrfs_ioctl_clone_range_args {
614614
*/
615615
#define BTRFS_DEFRAG_RANGE_COMPRESS 1
616616
#define BTRFS_DEFRAG_RANGE_START_IO 2
617+
#define BTRFS_DEFRAG_RANGE_FLAGS_SUPP (BTRFS_DEFRAG_RANGE_COMPRESS | \
618+
BTRFS_DEFRAG_RANGE_START_IO)
619+
617620
struct btrfs_ioctl_defrag_range_args {
618621
/* start of the defrag operation */
619622
__u64 start;

0 commit comments

Comments
 (0)