From patchwork Tue Aug 3 19:48:20 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sage Weil X-Patchwork-Id: 116851 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o73Jmi13031313 for ; Tue, 3 Aug 2010 19:48:44 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757391Ab0HCTsm (ORCPT ); Tue, 3 Aug 2010 15:48:42 -0400 Received: from cobra.newdream.net ([66.33.216.30]:48442 "EHLO cobra.newdream.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756515Ab0HCTsl (ORCPT ); Tue, 3 Aug 2010 15:48:41 -0400 Received: from localhost.localdomain (ip-66-33-206-8.dreamhost.com [66.33.206.8]) by cobra.newdream.net (Postfix) with ESMTPA id 9BD17BC7A1; Tue, 3 Aug 2010 12:51:26 -0700 (PDT) From: Sage Weil To: linux-btrfs@vger.kernel.org Cc: Sage Weil Subject: [PATCH] Btrfs: allow subvol deletion by owner Date: Tue, 3 Aug 2010 12:48:20 -0700 Message-Id: <1280864900-21067-1-git-send-email-sage@newdream.net> X-Mailer: git-send-email 1.7.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Tue, 03 Aug 2010 19:48:44 +0000 (UTC) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 9254b3d..b31283a 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -1227,9 +1227,6 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file, int ret; int err = 0; - if (!capable(CAP_SYS_ADMIN)) - return -EPERM; - vol_args = memdup_user(arg, sizeof(*vol_args)); if (IS_ERR(vol_args)) return PTR_ERR(vol_args); @@ -1264,6 +1261,28 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file, goto out_dput; } + /* + * Allow subvol deletion if we own the subvol and we would + * (approximately) be allowed to rmdir it. Strictly speaking, + * we could possibly delete everything with fewer permissions, + * or might require more permissions to remove all files + * contained by the subvol, but we aren't trying to mimic + * directory semantics perfectly. + */ + err = inode_permission(dir, MAY_WRITE | MAY_EXEC); + if (err) + goto out_dput; + err = security_inode_rmdir(dir, dentry); + if (err) + goto out_dput; + err = inode_permission(inode, MAY_WRITE | MAY_EXEC); + if (err) + goto out_dput; + err = -EPERM; + if (inode->i_uid != current_fsuid() || IS_APPEND(dir) || + IS_APPEND(inode)) + goto out_dput; + dest = BTRFS_I(inode)->root; mutex_lock(&inode->i_mutex);