소스 검색

btrfs: check unsupported filters in balance arguments

We don't verify that all the balance filter arguments supplemented by
the flags are actually known to the kernel. Thus we let it silently pass
and do nothing.

At the moment this means only the 'limit' filter, but we're going to add
a few more soon so it's better to have that fixed. Also in older stable
kernels so that it works with newer userspace tools.

Cc: stable@vger.kernel.org # 3.16+
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Chris Mason <clm@fb.com>
David Sterba 9 년 전
부모
커밋
8eb934591f
2개의 변경된 파일13개의 추가작업 그리고 0개의 파일을 삭제
  1. 5 0
      fs/btrfs/ioctl.c
  2. 8 0
      fs/btrfs/volumes.h

+ 5 - 0
fs/btrfs/ioctl.c

@@ -4639,6 +4639,11 @@ locked:
 		bctl->flags |= BTRFS_BALANCE_TYPE_MASK;
 		bctl->flags |= BTRFS_BALANCE_TYPE_MASK;
 	}
 	}
 
 
+	if (bctl->flags & ~(BTRFS_BALANCE_ARGS_MASK | BTRFS_BALANCE_TYPE_MASK)) {
+		ret = -EINVAL;
+		goto out_bargs;
+	}
+
 do_balance:
 do_balance:
 	/*
 	/*
 	 * Ownership of bctl and mutually_exclusive_operation_running
 	 * Ownership of bctl and mutually_exclusive_operation_running

+ 8 - 0
fs/btrfs/volumes.h

@@ -376,6 +376,14 @@ struct map_lookup {
 #define BTRFS_BALANCE_ARGS_VRANGE	(1ULL << 4)
 #define BTRFS_BALANCE_ARGS_VRANGE	(1ULL << 4)
 #define BTRFS_BALANCE_ARGS_LIMIT	(1ULL << 5)
 #define BTRFS_BALANCE_ARGS_LIMIT	(1ULL << 5)
 
 
+#define BTRFS_BALANCE_ARGS_MASK			\
+	(BTRFS_BALANCE_ARGS_PROFILES |		\
+	 BTRFS_BALANCE_ARGS_USAGE |		\
+	 BTRFS_BALANCE_ARGS_DEVID | 		\
+	 BTRFS_BALANCE_ARGS_DRANGE |		\
+	 BTRFS_BALANCE_ARGS_VRANGE |		\
+	 BTRFS_BALANCE_ARGS_LIMIT)
+
 /*
 /*
  * Profile changing flags.  When SOFT is set we won't relocate chunk if
  * Profile changing flags.  When SOFT is set we won't relocate chunk if
  * it already has the target profile (even though it may be
  * it already has the target profile (even though it may be