]> git.baikalelectronics.ru Git - kernel.git/commitdiff
btrfs: scrub: reject unsupported scrub flags
authorQu Wenruo <wqu@suse.com>
Thu, 6 Apr 2023 05:00:34 +0000 (13:00 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 17 May 2023 09:35:55 +0000 (11:35 +0200)
commit 604e6681e114d05a2e384c4d1e8ef81918037ef5 upstream.

Since the introduction of scrub interface, the only flag that we support
is BTRFS_SCRUB_READONLY.  Thus there is no sanity checks, if there are
some undefined flags passed in, we just ignore them.

This is problematic if we want to introduce new scrub flags, as we have
no way to determine if such flags are supported.

Address the problem by introducing a check for the flags, and if
unsupported flags are set, return -EOPNOTSUPP to inform the user space.

This check should be backported for all supported kernels before any new
scrub flags are introduced.

CC: stable@vger.kernel.org # 4.14+
Reviewed-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/btrfs/ioctl.c
include/uapi/linux/btrfs.h

index 64b443aa61cae3ae47f176f8d4a792019c93b9db..22f95a5a58fe15eca063f9c5a98bfba1634a56be 100644 (file)
@@ -4339,6 +4339,11 @@ static long btrfs_ioctl_scrub(struct file *file, void __user *arg)
        if (IS_ERR(sa))
                return PTR_ERR(sa);
 
+       if (sa->flags & ~BTRFS_SCRUB_SUPPORTED_FLAGS) {
+               ret = -EOPNOTSUPP;
+               goto out;
+       }
+
        if (!(sa->flags & BTRFS_SCRUB_READONLY)) {
                ret = mnt_want_write_file(file);
                if (ret)
index 3ee0678c0a8355ca8aa8495733e231a013042695..72cd9f61f05483994285ea4cf0d0dca80bf1da00 100644 (file)
@@ -162,6 +162,7 @@ struct btrfs_scrub_progress {
 };
 
 #define BTRFS_SCRUB_READONLY   1
+#define BTRFS_SCRUB_SUPPORTED_FLAGS    (BTRFS_SCRUB_READONLY)
 struct btrfs_ioctl_scrub_args {
        __u64 devid;                            /* in */
        __u64 start;                            /* in */