fs/namespace.c: introduce helper function path_unmounted()
Subsystems (2)
PATCH 1/8 fs/namespace.c: introduce helper function path_unmounted()
In fs/namespace.c, we verify whether a path is a mountpoint by comparing path->dentry and path->mnt->mnt_root. Introduce path_unmounted() to make code more readable.
--- fs/namespace.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
fs/namespace.c +12 -7
@@ -1234,6 +1234,11 @@ static int do_umount(struct mount *mnt, int flags)return retval; } +static inline bool path_unmounted (struct path *path) +{ +return path->dentry != path->mnt->mnt_root; +} +/* * Now umount can handle mount points as well as block devices. * This is important for filesystems which use unnamed block devices.
@@ -1260,7 +1265,7 @@ SYSCALL_DEFINE2(umount, char __user *, name, int, flags) goto out; mnt =real_mount (path.mnt); retval = -EINVAL ; -if (path.dentry != path.mnt->mnt_root) +if (path_unmounted (&path)) goto dput_and_out;if (!check_mnt (mnt)) goto dput_and_out;
@@ -1613,7 +1618,7 @@ static int do_change_type(struct path *path, int flag)if (!capable (CAP_SYS_ADMIN ))return -EPERM ; -if (path->dentry != path->mnt->mnt_root) +if (path_unmounted (path))return -EINVAL ; type =flags_to_propagation_type (flag);
@@ -1727,7 +1732,7 @@ static int do_remount(struct path *path, int flags, int mnt_flags,if (!check_mnt (mnt))return -EINVAL ; -if (path->dentry != path->mnt->mnt_root) +if (path_unmounted (path))return -EINVAL ; err =security_sb_remount (sb, data);
@@ -1793,7 +1798,7 @@ static int do_move_mount(struct path *path, char *old_name) goto out1; err = -EINVAL ; -if (old_path.dentry != old_path.mnt->mnt_root) +if (path_unmounted (&old_path)) goto out1;if (!mnt_has_parent (old))
@@ -1892,7 +1897,7 @@ static int do_add_mount(struct mount *newmnt, struct path *path, int mnt_flags)/* Refuse the same filesystem on the same mount point */ err = -EBUSY ;if (path->mnt->mnt_sb == newmnt->mnt.mnt_sb && - path->mnt->mnt_root == path->dentry) + !path_unmounted (path)) goto unlock; err = -EINVAL ;
@@ -2534,11 +2539,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root, old.mnt == root.mnt) goto out4;/* loop, on the same file system */ error = -EINVAL ; -if (root.mnt->mnt_root != root.dentry) +if (path_unmounted (&root)) goto out4;/* not a mountpoint */ if (!mnt_has_parent (root_mnt)) goto out4;/* not attached */ -if (new.mnt->mnt_root != new.dentry) +if (path_unmounted (&new)) goto out4;/* not a mountpoint */ if (!mnt_has_parent (new_mnt)) goto out4;/* not attached */
Signature · 1 line
1.7.9.5
PATCH 2/8 fs/namespace.c: remove unused macro MNT_WRITER_UNDERFLOW_LIMIT
Its users have gone.
--- fs/namespace.c | 1 - 1 file changed, 1 deletion(-)
fs/namespace.c +0 -1
@@ -59,7 +59,6 @@ static inline unsigned long hash(struct vfsmount *mnt, struct dentry *dentry)return tmp & (HASH_SIZE -1 ); } -#define MNT_WRITER_UNDERFLOW_LIMIT -(1<<16)/* * allocation is serialized by namespace_sem, but we need the spinlock to
Signature · 1 line
1.7.9.5
PATCH 3/8 fs/namespace.c: trivial code clean
In reply to Yan Hong--- fs/namespace.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/namespace.c +2 -2
@@ -763,7 +763,7 @@ vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void mnt->mnt.mnt_root = root; mnt->mnt.mnt_sb = root->d_sb; - mnt->mnt_mountpoint = mnt->mnt.mnt_root; + mnt->mnt_mountpoint = root; mnt->mnt_parent = mnt;br_write_lock (&vfsmount_lock);list_add_tail (&mnt->mnt_instance, &root->d_sb->s_mounts);
@@ -798,7 +798,7 @@ static struct mount *clone_mnt(struct mount *old, struct dentry *root,atomic_inc (&sb->s_active); mnt->mnt.mnt_sb = sb; mnt->mnt.mnt_root =dget (root); - mnt->mnt_mountpoint = mnt->mnt.mnt_root; + mnt->mnt_mountpoint = root; mnt->mnt_parent = mnt;br_write_lock (&vfsmount_lock);list_add_tail (&mnt->mnt_instance, &sb->s_mounts);
Signature · 1 line
1.7.9.5
PATCH 4/8 fs/namespace.c: check permission early in sys_[u]mount
In reply to Yan HongWe have several branches in sys_mount, each of them will check CAP_SYS_ADMIN capability seperately. Do this check at the beginning of sys_mount.
Also check permission as early as possible in sys_umount.
--- fs/namespace.c | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-)
fs/namespace.c +7 -19
@@ -1256,6 +1256,9 @@ SYSCALL_DEFINE2(umount, char __user *, name, int, flags)if (flags & ~(MNT_FORCE |MNT_DETACH |MNT_EXPIRE |UMOUNT_NOFOLLOW ))return -EINVAL ; +if (!capable (CAP_SYS_ADMIN )) +return -EPERM ; +if (!(flags &UMOUNT_NOFOLLOW )) lookup_flags |=LOOKUP_FOLLOW ;
@@ -1269,10 +1272,6 @@ SYSCALL_DEFINE2(umount, char __user *, name, int, flags)if (!check_mnt (mnt)) goto dput_and_out; - retval = -EPERM ; -if (!capable (CAP_SYS_ADMIN )) - goto dput_and_out; - retval =do_umount (mnt, flags); dput_and_out:/* we mustn't call path_put() as that would clear mnt_expiry_mark */
@@ -1296,9 +1295,7 @@ SYSCALL_DEFINE1(oldumount, char __user *, name)static int mount_is_safe (struct path *path) { -if (capable (CAP_SYS_ADMIN )) -return 0 ; -return -EPERM ; +return 0 ;#ifdef notyetif (S_ISLNK (path->dentry->d_inode->i_mode))return -EPERM ;
@@ -1614,9 +1611,6 @@ static int do_change_type(struct path *path, int flag)int type;int err =0 ; -if (!capable (CAP_SYS_ADMIN )) -return -EPERM ; -if (path_unmounted (path))return -EINVAL ;
@@ -1725,9 +1719,6 @@ static int do_remount(struct path *path, int flags, int mnt_flags,struct super_block *sb = path->mnt->mnt_sb;struct mount *mnt =real_mount (path->mnt); -if (!capable (CAP_SYS_ADMIN )) -return -EPERM ; -if (!check_mnt (mnt))return -EINVAL ;
@@ -1774,8 +1765,6 @@ static int do_move_mount(struct path *path, char *old_name)struct mount *p;struct mount *old;int err =0 ; -if (!capable (CAP_SYS_ADMIN )) -return -EPERM ;if (!old_name || !*old_name)return -EINVAL ; err =kern_path (old_name,LOOKUP_FOLLOW , &old_path);
@@ -1924,10 +1913,6 @@ static int do_new_mount(struct path *path, char *type, int flags,if (!type)return -EINVAL ; -/* we need capabilities... */ -if (!capable (CAP_SYS_ADMIN )) -return -EPERM ; - mnt =do_kern_mount (type, flags, name, data);if (IS_ERR (mnt))return PTR_ERR (mnt);
@@ -2410,6 +2395,9 @@ SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,char *kernel_dev;unsigned long data_page; +if (!capable (CAP_SYS_ADMIN )) +return -EPERM ; + ret =copy_mount_string (type, &kernel_type);if (ret <0 ) goto out_type;
Signature · 1 line
1.7.9.5
PATCH 5/8 fs/namei.c: introduce macro AT_FDINV
In reply to Yan HongFile descriptor is irrelevent when LOOKUP_ROOT is set. Introduce AT_FDINV to avoid using hard coded value or reusing existing macro.
--- fs/namei.c | 11 ++++++----- include/linux/fcntl.h | 2 ++ 2 files changed, 8 insertions(+), 5 deletions(-)
fs/namei.c +6 -5
@@ -2034,8 +2034,8 @@ int vfs_path_lookup(struct dentry *dentry, struct vfsmount *mnt, nd.root.dentry = dentry; nd.root.mnt = mnt;BUG_ON (flags &LOOKUP_PARENT ); -/* the first argument of do_path_lookup() is ignored with LOOKUP_ROOT */ - err =do_path_lookup (AT_FDCWD , name, flags |LOOKUP_ROOT , &nd); + + err =do_path_lookup (AT_FDINV , name, flags |LOOKUP_ROOT , &nd);if (!err) *path = nd.path;return err;
@@ -2969,11 +2969,12 @@ struct file *do_file_open_root(struct dentry *dentry, struct vfsmount *mnt,if (dentry->d_inode->i_op->follow_link && op->intent &LOOKUP_OPEN )return ERR_PTR (-ELOOP ); - file =path_openat (-1 , name, &nd, op, flags |LOOKUP_RCU ); + file =path_openat (AT_FDINV , name, &nd, op, flags |LOOKUP_RCU );if (unlikely (file ==ERR_PTR (-ECHILD ))) - file =path_openat (-1 , name, &nd, op, flags); + file =path_openat (AT_FDINV , name, &nd, op, flags);if (unlikely (file ==ERR_PTR (-ESTALE ))) - file =path_openat (-1 , name, &nd, op, flags |LOOKUP_REVAL ); + file =path_openat (AT_FDINV , name, &nd, op, + flags |LOOKUP_REVAL );return file; }
include/linux/fcntl.h +2 -0
@@ -41,6 +41,8 @@#define AT_FDCWD -100/* Special value used to indicate openat should use the current working directory. */ +#define AT_FDINV -200/* Special value used when LOOKUP_ROOT +is set. */ #define AT_SYMLINK_NOFOLLOW 0x100/* Do not follow symbolic links. */ #define AT_REMOVEDIR 0x200/* Remove directory instead of unlinking file. */
Signature · 1 line
1.7.9.5
PATCH 6/8 fs/inode.c: call alloc_inode() in new_inode() directly
In reply to Yan HongThis saves us a list head initialization.
--- fs/inode.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
fs/inode.c +4 -2
@@ -921,9 +921,11 @@ struct inode *new_inode(struct super_block *sb)spin_lock_prefetch (&inode_sb_list_lock); - inode =new_inode_pseudo (sb); -if (inode) + inode =alloc_inode (sb); +if (inode) { + inode->i_state =0 ;inode_sb_list_add (inode); + }return inode; }EXPORT_SYMBOL (new_inode);
Signature · 1 line
1.7.9.5
PATCH 7/8 fs/inode.c: remove outstanding spin lock prefetch
In reply to Yan HongDo we have particular reason to do this here?
--- fs/inode.c | 3 --- 1 file changed, 3 deletions(-)
fs/inode.c +0 -3
@@ -14,7 +14,6 @@#include <linux/fsnotify.h> #include <linux/mount.h> #include <linux/posix_acl.h> -#include <linux/prefetch.h> #include <linux/buffer_head.h> /* for inode_has_buffers */ #include <linux/ratelimit.h> #include "internal.h"
@@ -919,8 +918,6 @@ struct inode *new_inode(struct super_block *sb) {struct inode *inode; -spin_lock_prefetch (&inode_sb_list_lock); - inode =alloc_inode (sb);if (inode) { inode->i_state =0 ;
Signature · 1 line
1.7.9.5
PATCH 8/8 vfs: misc comment clean
In reply to Yan HongMostly fix comments which reference inexist locks or parameters.
--- fs/dcache.c | 12 ++++-------- fs/inode.c | 4 ++-- fs/namei.c | 2 +- fs/namespace.c | 9 +++------ 4 files changed, 10 insertions(+), 17 deletions(-)
fs/dcache.c +4 -8
@@ -44,8 +44,6 @@* Usage: * dcache->d_inode->i_lock protects: * - i_dentry, d_alias, d_inode of aliases -* dcache_hash_bucket lock protects: -* - the dcache hash table * s_anon bl list spinlock protects: * - the s_anon list (see __d_drop) * dcache_lru_lock protects:
@@ -64,7 +62,6 @@* dentry->d_inode->i_lock * dentry->d_lock * dcache_lru_lock -* dcache_hash_bucket lock * s_anon lock * * If there is an ancestor relationship:
@@ -145,10 +142,9 @@ int proc_nr_dentry(ctl_table *table, int write, void __user *buffer,#include <asm/word-at-a-time.h> /* -* NOTE! 'cs' and 'scount' come from a dentry, so it has a -* aligned allocation for this particular component. We don't -* strictly need the load_unaligned_zeropad() safety, but it -* doesn't hurt either. +* NOTE! 'cs' comes from a dentry, so it has an aligned allocation +* for this particular component. We don't strictly need the +* load_unaligned_zeropad() safety, but it doesn't hurt either. * * In contrast, 'ct' and 'tcount' can be from a pathname, and do * need the careful unaligned handling.
@@ -304,7 +300,7 @@ static void dentry_unlink_inode(struct dentry * dentry) }/* -* dentry_lru_(add|del|prune|move_tail) must be called with d_lock held. +* dentry_lru_(add|del|prune|move_list) must be called with d_lock held. */ static void dentry_lru_add (struct dentry *dentry) {
fs/inode.c +2 -2
@@ -676,7 +676,7 @@ static int can_unuse(struct inode *inode)* Walk the superblock inode LRU for freeable inodes and attempt to free them. * This is called from the superblock shrinker function with a number of inodes * to trim from the LRU. Inodes to be freed are moved to a temporary list and -* then are freed outside inode_lock by dispose_list(). +* then are freed outside s_inode_lru_lock by dispose_list(). * * Any inodes which are pinned purely because of attached pagecache have their * pagecache removed. If the inode has metadata buffers attached to
@@ -777,7 +777,7 @@ void prune_icache_sb(struct super_block *sb, int nr_to_scan)static void __wait_on_freeing_inode (struct inode *inode);/* -* Called with the inode lock held. +* Called with the inode_hash_lock held. */ static struct inode *find_inode(struct super_block *sb, struct hlist_head *head,
fs/namei.c +1 -1
@@ -421,7 +421,7 @@ EXPORT_SYMBOL(path_put);* Path walking has 2 modes, rcu-walk and ref-walk (see * Documentation/filesystems/path-lookup.txt). In situations when we can't * continue in RCU mode, we attempt to drop out of rcu-walk mode and grab -* normal reference counts on dentries and vfsmounts to transition to rcu-walk +* normal reference counts on dentries and vfsmounts to transition to ref-walk * mode. Refcounts are grabbed at the last known good point before rcu-walk * got stuck, so ref-walk may continue from there. If this is not successful * (eg. a seqcount has changed), then failure is returned and it's up to caller
fs/namespace.c +3 -6
@@ -1239,9 +1239,6 @@ static inline bool path_unmounted(struct path *path) }/* -* Now umount can handle mount points as well as block devices. -* This is important for filesystems which use unnamed block devices. -* * We now support a flag for forced unmount like the other 'big iron' * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD */
@@ -1431,9 +1428,9 @@ static int invent_group_ids(struct mount *mnt, bool recurse) }/* -* @source_mnt : mount tree to be attached -* @nd : place the mount tree @source_mnt is attached -* @parent_nd : if non-null, detach the source_mnt from its parent and +* @source_mnt : mount tree to be attached +* @path : place the mount tree @source_mnt is attached +* @parent_path : if non-null, detach the @source_mnt from its parent and * store the parent mount and mountpoint dentry. * (done when source_mnt is moved) *
Signature · 1 line
1.7.9.5