From: Miklos Szeredi Subject: [patch 02/10] unprivileged mounts: allow unprivileged umount Date: Fri, 27 Apr 2007 14:04:19 +0200 Message-ID: <20070427120528.701271037@szeredi.hu> References: <20070427120417.110164241@szeredi.hu> Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, containers@lists.osdl.org To: akpm@linux-foundation.org, serue@us.ibm.com, viro@ftp.linux.org.uk, linuxram@us.ibm.com, ebiederm@xmission.com, kzak@redhat.com Return-path: Received: from mail-gw3.sa.ew.hu ([212.108.200.82]:54999 "EHLO mail-gw3.sa.ew.hu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755725AbXD0MMC (ORCPT ); Fri, 27 Apr 2007 08:12:02 -0400 Content-Disposition: inline; filename=unprivileged-mounts-allow-unprivileged-umount.patch Sender: linux-fsdevel-owner@vger.kernel.org List-Id: linux-fsdevel.vger.kernel.org From: Miklos Szeredi The owner doesn't need sysadmin capabilities to call umount(). Similar behavior as umount(8) on mounts having "user=UID" option in /etc/mtab. The difference is that umount also checks /etc/fstab, presumably to exclude another mount on the same mountpoint. Signed-off-by: Miklos Szeredi --- Index: linux/fs/namespace.c =================================================================== --- linux.orig/fs/namespace.c 2007-04-26 13:10:48.000000000 +0200 +++ linux/fs/namespace.c 2007-04-26 13:16:21.000000000 +0200 @@ -658,6 +658,27 @@ static int do_umount(struct vfsmount *mn return retval; } +static bool is_mount_owner(struct vfsmount *mnt, uid_t uid) +{ + return (mnt->mnt_flags & MNT_USER) && mnt->mnt_uid == uid; +} + +/* + * umount is permitted for + * - sysadmin + * - mount owner, if not forced umount + */ +static bool permit_umount(struct vfsmount *mnt, int flags) +{ + if (capable(CAP_SYS_ADMIN)) + return true; + + if (flags & MNT_FORCE) + return false; + + return is_mount_owner(mnt, current->fsuid); +} + /* * Now umount can handle mount points as well as block devices. * This is important for filesystems which use unnamed block devices. @@ -681,7 +702,7 @@ asmlinkage long sys_umount(char __user * goto dput_and_out; retval = -EPERM; - if (!capable(CAP_SYS_ADMIN)) + if (!permit_umount(nd.mnt, flags)) goto dput_and_out; retval = do_umount(nd.mnt, flags); --