Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6f88a440 authored by Ben Hutchings's avatar Ben Hutchings Committed by Chris Mason
Browse files

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: default avatarAron Xu <happyaron.xu@gmail.com>
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parent f690efb1
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
#include <linux/blkdev.h>
#include <linux/random.h>
#include <linux/iocontext.h>
#include <linux/capability.h>
#include <asm/div64.h>
#include "compat.h"
#include "ctree.h"
@@ -2024,6 +2025,9 @@ int btrfs_balance(struct btrfs_root *dev_root)
	if (dev_root->fs_info->sb->s_flags & MS_RDONLY)
		return -EROFS;

	if (!capable(CAP_SYS_ADMIN))
		return -EPERM;

	mutex_lock(&dev_root->fs_info->volume_mutex);
	dev_root = dev_root->fs_info->dev_root;