ubifs: Reject unsupported ioctl flags explicitly
authorHou Tao <houtao1@huawei.com>
Sat, 9 Feb 2019 08:54:20 +0000 (16:54 +0800)
committerRichard Weinberger <richard@nod.at>
Sun, 24 Feb 2019 10:40:46 +0000 (11:40 +0100)
Reject unsupported ioctl flags explicitly, so the following command
on a regular ubifs file will fail:
chattr +d ubifs_file

And xfstests generic/424 will pass.

Signed-off-by: Hou Tao <houtao1@huawei.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
fs/ubifs/ioctl.c

index 0164bcc..daf9f93 100644 (file)
 #include <linux/mount.h>
 #include "ubifs.h"
 
+/* Need to be kept consistent with checked flags in ioctl2ubifs() */
+#define UBIFS_SUPPORTED_IOCTL_FLAGS \
+       (FS_COMPR_FL | FS_SYNC_FL | FS_APPEND_FL | \
+        FS_IMMUTABLE_FL | FS_DIRSYNC_FL)
+
 /**
  * ubifs_set_inode_flags - set VFS inode flags.
  * @inode: VFS inode to set flags for
@@ -169,6 +174,9 @@ long ubifs_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                if (get_user(flags, (int __user *) arg))
                        return -EFAULT;
 
+               if (flags & ~UBIFS_SUPPORTED_IOCTL_FLAGS)
+                       return -EOPNOTSUPP;
+
                if (!S_ISDIR(inode->i_mode))
                        flags &= ~FS_DIRSYNC_FL;