Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754019AbYAPMfZ (ORCPT ); Wed, 16 Jan 2008 07:35:25 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751925AbYAPMe5 (ORCPT ); Wed, 16 Jan 2008 07:34:57 -0500 Received: from fxip-0047f.externet.hu ([88.209.222.127]:34431 "EHLO pomaz-ex.szeredi.hu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751595AbYAPMe4 (ORCPT ); Wed, 16 Jan 2008 07:34:56 -0500 Message-Id: <20080116123424.938213321@szeredi.hu> References: <20080116123147.466284860@szeredi.hu> User-Agent: quilt/0.45-1 Date: Wed, 16 Jan 2008 13:31:49 +0100 From: Miklos Szeredi To: akpm@linux-foundation.org, hch@infradead.org, serue@us.ibm.com, viro@ftp.linux.org.uk, kzak@redhat.com Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, containers@lists.osdl.org, util-linux-ng@vger.kernel.org Subject: [patch 02/10] unprivileged mounts: allow unprivileged umount Content-Disposition: inline; filename=unprivileged-mounts-allow-unprivileged-umount.patch Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1764 Lines: 60 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 Acked-by: Serge Hallyn --- Index: linux/fs/namespace.c =================================================================== --- linux.orig/fs/namespace.c 2008-01-16 13:25:05.000000000 +0100 +++ linux/fs/namespace.c 2008-01-16 13:25:06.000000000 +0100 @@ -894,6 +894,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. @@ -917,7 +938,7 @@ asmlinkage long sys_umount(char __user * goto dput_and_out; retval = -EPERM; - if (!capable(CAP_SYS_ADMIN)) + if (!permit_umount(nd.path.mnt, flags)) goto dput_and_out; retval = do_umount(nd.path.mnt, flags); -- -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/