btrfs: Require CAP_SYS_ADMIN for filesystem rebalance

Filesystem rebalancing (BTRFS_IOC_BALANCE) affects the entire
filesystem and may run uninterruptibly for a long time. This does not
seem to be something that an unprivileged user should be able to do.

Reported-by: Aron Xu <happyaron.xu@gmail.com>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Signed-off-by: Chris Mason <chris.mason@oracle.com>

authored by Ben Hutchings and committed by Chris Mason 6f88a440 f690efb1

+4
+4
fs/btrfs/volumes.c
··· 22 22 #include <linux/blkdev.h> 23 23 #include <linux/random.h> 24 24 #include <linux/iocontext.h> 25 + #include <linux/capability.h> 25 26 #include <asm/div64.h> 26 27 #include "compat.h" 27 28 #include "ctree.h" ··· 2024 2023 2025 2024 if (dev_root->fs_info->sb->s_flags & MS_RDONLY) 2026 2025 return -EROFS; 2026 + 2027 + if (!capable(CAP_SYS_ADMIN)) 2028 + return -EPERM; 2027 2029 2028 2030 mutex_lock(&dev_root->fs_info->volume_mutex); 2029 2031 dev_root = dev_root->fs_info->dev_root;