Skip to contentSkip to conversation

Btrfs: allow subvol deletion by unprivileged user with -o user_subvol_rm_allowed

PATCH In review Sage Weil 2 participants 2 messages Oct 26, 2010 – Oct 28, 2010 Btrfs file system

lore
Share & tools
lore

Sage Weil

author
#0 lore raw

PATCH v2 1/1 Btrfs: allow subvol deletion by unprivileged user with -o user_subvol_rm_allowed

Add a mount option user_subvol_rm_allowed that allows users to delete a (potentially non-empty!) subvol when they would otherwise we allowed to do an rmdir(2). We duplicate the may_delete() checks from the core VFS code to implement identical security checks (minus the directory size check). We additionally require that the user has write+exec permission on the subvol root inode.

---
v2:
- add write+exec check on subvol root inode

 fs/btrfs/ctree.h |    1 +
 fs/btrfs/ioctl.c |  115 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 fs/btrfs/super.c |    6 ++-
 3 files changed, 116 insertions(+), 6 deletions(-)
fs/btrfs/ctree.h +1 -0
index 4c3c20b..f1f4155 100644
@@ -1193,6 +1193,7 @@ struct btrfs_root {
 #define BTRFS_MOUNT_NOSSD		(1 << 9)
 #define BTRFS_MOUNT_DISCARD		(1 << 10)
 #define BTRFS_MOUNT_FORCE_COMPRESS      (1 << 11)
+#define BTRFS_MOUNT_USER_SUBVOL_RM_ALLOWED (1 << 12)
 
 #define btrfs_clear_opt(o, opt)		((o) &= ~BTRFS_MOUNT_##opt)
 #define btrfs_set_opt(o, opt)		((o) |= BTRFS_MOUNT_##opt)
fs/btrfs/ioctl.c +110 -5

138 lines not on this page · raw message

fs/btrfs/super.c +5 -1
index 1776dbd..253c5af 100644
@@ -68,7 +68,7 @@ enum {
 	Opt_nodatacow, Opt_max_inline, Opt_alloc_start, Opt_nobarrier, Opt_ssd,
 	Opt_nossd, Opt_ssd_spread, Opt_thread_pool, Opt_noacl, Opt_compress,
 	Opt_compress_force, Opt_notreelog, Opt_ratio, Opt_flushoncommit,
-	Opt_discard, Opt_err,
+	Opt_discard, Opt_user_subvol_rm_allowed, Opt_err,
 };
 
 static match_table_t tokens = {
@@ -92,6 +92,7 @@ static match_table_t tokens = {
 	{Opt_flushoncommit, "flushoncommit"},
 	{Opt_ratio, "metadata_ratio=%d"},
 	{Opt_discard, "discard"},
+	{Opt_user_subvol_rm_allowed, "user_subvol_rm_allowed"},
 	{Opt_err, NULL},
 };
 
@@ -235,6 +236,9 @@ int btrfs_parse_options(struct btrfs_root *root, char *options)
 		case Opt_discard:
 			btrfs_set_opt(info->mount_opt, DISCARD);
 			break;
+		case Opt_user_subvol_rm_allowed:
+			btrfs_set_opt(info->mount_opt, USER_SUBVOL_RM_ALLOWED);
+			break;
 		case Opt_err:
 			printk(KERN_INFO "btrfs: unrecognized mount option "
 			       "'%s'\n", p);
Signature · 1 line
1.6.6.1
#1 lore raw

do the resulting semantics match (or resemble) the semantics provided by other facilities that allow non-superusers to mount and unmount file systems?

If all "user mountable file systems" are provided either by the FUSE layer (but that is concerned with providing the FS, not mounting it) or by setuid tools, this question may be safe to ignore.

Quoted 1 line · Sage Weil

Add a mount option user_subvol_rm_allowed that allows users to delete=

a

Quoted 1 line

(potentially non-empty!) subvol when they would otherwise we allowed =

to do

Quoted 1 line

an rmdir(2). =C2=A0We duplicate the may_delete() checks from the core=

VFS code

Quoted 1 line

to implement identical security checks (minus the directory size chec=

k).

Quoted 1 line

We additionally require that the user has write+exec permission on th=

e

Quoted 1 line

subvol root inode.

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" = in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html