assorted fixes and cleanups
Subsystems (4)
[email protected]
maintainercover assorted fixes and cleanups
This is not really a patch series, just random pending stuff. None of it is 2.6.23 material I think.
Thanks,
Miklos
--
[email protected]
maintainerPATCH 1/9 unprivileged mounts: fix subtype handling
From: Miklos Szeredi <[email protected]>
Subtype handling was done in do_kern_mount(), but "unprivileged
mounts: allow unprivileged mounts" patch made do_new_mount() use vfs_kern_mount(). This broke the filesystem subtype handling.
Fix this by moving the subtype handling from do_kern_mount() into do_new_mount(). All other callers are kernel-internal and do not need subtype support.
---
fs/namespace.c +26 -0
@@ -1198,6 +1198,29 @@ out:return err; } +static struct vfsmount *fs_set_subtype (struct vfsmount *mnt,const char *fstype) +{ +int err; +const char *subtype =strchr (fstype,'.' ); +if (subtype) { + subtype++; + err = -EINVAL ; +if (!subtype[0 ]) + goto err; + }else + subtype ="" ; + + mnt->mnt_sb->s_subtype =kstrdup (subtype,GFP_KERNEL ); + err = -ENOMEM ; +if (!mnt->mnt_sb->s_subtype) + goto err; +return mnt; + + err: +mntput (mnt); +return ERR_PTR (err); +} +/* * create a new mount for userspace and request it to be added into the * namespace's tree
@@ -1227,6 +1250,9 @@ static int do_new_mount(struct nameidata } mnt =vfs_kern_mount (type, flags & ~MS_SETUSER , name, data); +if (!IS_ERR (mnt) && (type->fs_flags &FS_HAS_SUBTYPE ) && + !mnt->mnt_sb->s_subtype) + mnt =fs_set_subtype (mnt, fstype);put_filesystem (type);if (IS_ERR (mnt)) {if (flags &MS_SETUSER )
fs/super.c +0 -26
@@ -906,29 +906,6 @@ out:EXPORT_SYMBOL_GPL (vfs_kern_mount); -static struct vfsmount *fs_set_subtype (struct vfsmount *mnt,const char *fstype) -{ -int err; -const char *subtype =strchr (fstype,'.' ); -if (subtype) { - subtype++; - err = -EINVAL ; -if (!subtype[0 ]) - goto err; - }else - subtype ="" ; - - mnt->mnt_sb->s_subtype =kstrdup (subtype,GFP_KERNEL ); - err = -ENOMEM ; -if (!mnt->mnt_sb->s_subtype) - goto err; -return mnt; - - err: -mntput (mnt); -return ERR_PTR (err); -} -struct vfsmount *do_kern_mount (const char *fstype,int flags,const char *name,void *data) {
@@ -937,9 +914,6 @@ do_kern_mount(const char *fstype, int flif (!type)return ERR_PTR (-ENODEV ); mnt =vfs_kern_mount (type, flags, name, data); -if (!IS_ERR (mnt) && (type->fs_flags &FS_HAS_SUBTYPE ) && - !mnt->mnt_sb->s_subtype) - mnt =fs_set_subtype (mnt, fstype);put_filesystem (type);return mnt; }
--
[email protected]
maintainerPATCH 2/9 VFS: check nanoseconds in utimensat
In reply to [email protected]From: Miklos Szeredi <[email protected]>
utimensat() (and possibly other callers of do_utimes()) didn't check if the nanosecond value was within the allowed range.
---
fs/utimes.c +13 -0
@@ -38,6 +38,14 @@ asmlinkage long sys_utime(char __user *f#endif +static bool nsec_valid (long nsec) +{ +if (nsec ==UTIME_OMIT || nsec ==UTIME_NOW ) +return true; + +return nsec >=0 && nsec <=999999999 ; +} +/* If times==NULL, set access and modification to current time, * must be owner or have write permission. * Else, update from *times, must be owner or super user.
@@ -52,6 +60,11 @@ long do_utimes(int dfd, char __user *filstruct file *f =NULL ; error = -EINVAL ; +if (times && (!nsec_valid (times[0 ].tv_nsec) || + !nsec_valid (times[1 ].tv_nsec))) { + goto out; + } +if (flags & ~AT_SYMLINK_NOFOLLOW ) goto out;
--
[email protected]
maintainerPATCH 3/9 fix execute checking in permission()
In reply to [email protected]From: Miklos Szeredi <[email protected]>
permission() checks that MAY_EXEC is only allowed on regular files if at least one execute bit is set in the file mode.
generic_permission() already ensures this, so the extra check in permission() is superfluous.
If the filesystem defines it's own ->permission() the check may still be needed. In this case move it after ->permission(). This is needed because filesystems such as FUSE may need to refresh the inode attributes before checking permissions.
This check should be moved inside ->permission(), but that's another story.
---
fs/namei.c +24 -12
@@ -227,10 +227,10 @@ int generic_permission(struct inode *inoint permission (struct inode *inode,int mask,struct nameidata *nd) { -umode_t mode = inode->i_mode;int retval, submask;if (mask &MAY_WRITE ) { +umode_t mode = inode->i_mode;/* * Nobody gets write access to a read-only fs.
@@ -246,22 +246,34 @@ int permission(struct inode *inode, intreturn -EACCES ; } - -/* -* MAY_EXEC on regular files requires special handling: We override -* filesystem execute permissions if the mode bits aren't set or -* the fs is mounted with the "noexec" flag. -*/ -if ((mask &MAY_EXEC ) &&S_ISREG (mode) && (!(mode &S_IXUGO ) || - (nd && nd->mnt && (nd->mnt->mnt_flags &MNT_NOEXEC )))) -return -EACCES ; +if ((mask &MAY_EXEC ) &&S_ISREG (inode->i_mode)) { +/* +* MAY_EXEC on regular files is denied if the fs is mounted +* with the "noexec" flag. +*/ +if (nd && nd->mnt && (nd->mnt->mnt_flags &MNT_NOEXEC )) +return -EACCES ; + }/* Ordinary permission routines do not understand MAY_APPEND. */ submask = mask & ~MAY_APPEND ; -if (inode->i_op && inode->i_op->permission) +if (inode->i_op && inode->i_op->permission) { retval = inode->i_op->permission (inode, submask, nd); -else +if (!retval) { +/* +* Exec permission on a regular file is denied if none +* of the execute bits are set. +* +* This check should be done by the ->permission() +* method. +*/ +if ((mask &MAY_EXEC ) &&S_ISREG (inode->i_mode) && + !(inode->i_mode &S_IXUGO )) +return -EACCES ; + } + }else { retval =generic_permission (inode, submask,NULL ); + }if (retval)return retval;
--
[email protected]
maintainerPATCH 4/9 exec: remove unnecessary check for MNT_NOEXEC
In reply to [email protected]From: Miklos Szeredi <[email protected]>
vfs_permission(MAY_EXEC) checks if the filesystem is mounted with "noexec", so there's no need to repeat this check in sys_uselib() and open_exec().
---
fs/exec.c +1 -5
@@ -113,9 +113,6 @@ asmlinkage long sys_uselib(const char __if (error) goto out; - error = -EACCES ; -if (nd.mnt->mnt_flags &MNT_NOEXEC ) - goto exit; error = -EINVAL ;if (!S_ISREG (nd.dentry->d_inode->i_mode)) goto exit;
@@ -659,8 +656,7 @@ struct file *open_exec(const char *name)if (!err) {struct inode *inode = nd.dentry->d_inode; file =ERR_PTR (-EACCES ); -if (!(nd.mnt->mnt_flags &MNT_NOEXEC ) && -S_ISREG (inode->i_mode)) { +if (S_ISREG (inode->i_mode)) {int err =vfs_permission (&nd,MAY_EXEC ); file =ERR_PTR (err);if (!err) {
--
[email protected]
maintainerPATCH 5/9 fuse: fix setting i_mode bits
In reply to [email protected]From: Miklos Szeredi <[email protected]>
The patch titled "fuse: fix permission checking on sticky directories" removed all but the S_IFMT bits from i_mode.
However some of these are unfortunately used by the VFS, such as the execute, suid and sgid bits.
So only remove the sticky bit, which is used for checking deletion from a directory.
---
fs/fuse/inode.c +10 -8
@@ -124,14 +124,7 @@ void fuse_change_attributes(struct inodeloff_t oldsize; inode->i_ino = attr->ino; - fi->orig_i_mode = (inode->i_mode &S_IFMT ) | (attr->mode &07777 ); -/* -* Don't set the mode bits in i_mode, unless we want the VFS -* to check permissions. This prevents failures due to the -* sticky bit check in may_delete(). -*/ -if (fc->flags &FUSE_DEFAULT_PERMISSIONS ) - inode->i_mode = fi->orig_i_mode; + inode->i_mode = (inode->i_mode &S_IFMT ) | (attr->mode &07777 ); inode->i_nlink = attr->nlink; inode->i_uid = attr->uid; inode->i_gid = attr->gid;
@@ -143,6 +136,15 @@ void fuse_change_attributes(struct inode inode->i_ctime.tv_sec = attr->ctime; inode->i_ctime.tv_nsec = attr->ctimensec; +/* +* Don't set the sticky bit in i_mode, unless we want the VFS +* to check permissions. This prevents failures due to the +* check in may_delete(). +*/ + fi->orig_i_mode = inode->i_mode; +if (!(fc->flags &FUSE_DEFAULT_PERMISSIONS )) + inode->i_mode &= ~S_ISVTX ; +spin_lock (&fc->lock); oldsize = inode->i_size;i_size_write (inode, attr->size);
--
[email protected]
maintainerPATCH 6/9 fuse: clean up execute permission checking
In reply to [email protected]From: Miklos Szeredi <[email protected]>
Define a new function fuse_refresh_attributes() that conditionally refreshes the attributes based on the validity timeout.
In fuse_permission() only refresh the attributes for checking the execute bits if necessary.
---
fs/fuse/dir.c +31 -18
@@ -695,6 +695,20 @@ static int fuse_do_getattr(struct inode }/* +* Check if attributes are still valid, and if not send a GETATTR +* request to refresh them. +*/ +static int fuse_refresh_attributes (struct inode *inode) +{ +struct fuse_inode *fi =get_fuse_inode (inode); + +if (fi->i_time <get_jiffies_64 ()) +return fuse_do_getattr (inode); +else +return 0 ; +} + +/* * Calling into a user-controlled filesystem gives the filesystem * daemon ptrace-like capabilities over the requester process. This * means, that the filesystem daemon is able to record the exact
@@ -770,7 +784,6 @@ static int fuse_access(struct inode *inostatic int fuse_permission (struct inode *inode,int mask,struct nameidata *nd) {struct fuse_conn *fc =get_fuse_conn (inode); -struct fuse_inode *fi =get_fuse_inode (inode);bool refreshed = false;int err =0 ;
@@ -778,12 +791,11 @@ static int fuse_permission(struct inodereturn -EACCES ;/* -* If attributes are needed, but are stale, refresh them -* before proceeding +* If attributes are needed, refresh them before proceeding */ -if (((fc->flags &FUSE_DEFAULT_PERMISSIONS ) || (mask &MAY_EXEC )) && - fi->i_time <get_jiffies_64 ()) { - err =fuse_do_getattr (inode); +if ((fc->flags &FUSE_DEFAULT_PERMISSIONS ) || + ((mask &MAY_EXEC ) &&S_ISREG (inode->i_mode))) { + err =fuse_refresh_attributes (inode);if (err)return err;
@@ -806,14 +818,17 @@ static int fuse_permission(struct inodeexist. So if permissions are revoked this won't be noticed immediately, only after the attribute timeout has expired */ - - }else { -int mode = inode->i_mode; -if ((mask &MAY_EXEC ) && !S_ISDIR (mode) && !(mode &S_IXUGO )) -return -EACCES ; - -if (nd && (nd->flags & (LOOKUP_ACCESS |LOOKUP_CHDIR ))) -return fuse_access (inode, mask); + }else if (nd && (nd->flags & (LOOKUP_ACCESS |LOOKUP_CHDIR ))) { + err =fuse_access (inode, mask); + }else if ((mask &MAY_EXEC ) &&S_ISREG (inode->i_mode)) { +if (!(inode->i_mode &S_IXUGO )) { +if (refreshed) +return -EACCES ; + + err =fuse_do_getattr (inode); +if (!err && !(inode->i_mode &S_IXUGO )) +return -EACCES ; + } }return err; }
@@ -1046,14 +1061,12 @@ static int fuse_getattr(struct vfsmountstruct inode *inode = entry->d_inode;struct fuse_inode *fi =get_fuse_inode (inode);struct fuse_conn *fc =get_fuse_conn (inode); -int err =0 ; +int err;if (!fuse_allow_task (fc, current))return -EACCES ; -if (fi->i_time <get_jiffies_64 ()) - err =fuse_do_getattr (inode); - + err =fuse_refresh_attributes (inode);if (!err) {generic_fillattr (inode, stat); stat->mode = fi->orig_i_mode;
--
[email protected]
maintainerPATCH 7/9 clean out unused code in dentry pruning
In reply to [email protected]From: Miklos Szeredi <[email protected]>
It looks like in the end all pruners want parents removed.
So remove unused code and function arguments.
---
fs/dcache.c +10 -14
@@ -381,20 +381,17 @@ restart:* Throw away a dentry - free the inode, dput the parent. This requires that * the LRU list has already been removed. * -* If prune_parents is true, try to prune ancestors as well. +* Try to prune ancestors as well. This is necessary to prevent +* quadratic behavior of shrink_dcache_parent(), but is also expected +* to be beneficial in reducing dentry cache fragmentation. * * Called with dcache_lock, drops it and then regains. * Called with dentry->d_lock held, drops it. */ -static void prune_one_dentry (struct dentry * dentry,int prune_parents) +static void prune_one_dentry (struct dentry * dentry) {__d_drop (dentry); dentry =d_kill (dentry); -if (!prune_parents) { -dput (dentry); -spin_lock (&dcache_lock); -return ; - }/* * Prune ancestors. Locking is simpler than in dput(),
@@ -422,7 +419,6 @@ static void prune_one_dentry(struct dent* @count: number of entries to try and free * @sb: if given, ignore dentries for other superblocks * which are being unmounted. -* @prune_parents: if true, try to prune ancestors as well in one go * * Shrink the dcache. This is done when we need * more memory, or simply when we need to unmount
@@ -433,7 +429,7 @@ static void prune_one_dentry(struct dent* all the dentries are in use. */ -static void prune_dcache (int count,struct super_block *sb,int prune_parents) +static void prune_dcache (int count,struct super_block *sb) {spin_lock (&dcache_lock);for (; count ; count--) {
@@ -493,7 +489,7 @@ static void prune_dcache(int count, stru* without taking the s_umount lock (I already hold it). */ if (sb && dentry->d_sb == sb) { -prune_one_dentry (dentry, prune_parents); +prune_one_dentry (dentry);continue ; }/*
@@ -508,7 +504,7 @@ static void prune_dcache(int count, stru s_umount = &dentry->d_sb->s_umount;if (down_read_trylock (s_umount)) {if (dentry->d_sb->s_root !=NULL ) { -prune_one_dentry (dentry, prune_parents); +prune_one_dentry (dentry);up_read (s_umount);continue ; }
@@ -579,7 +575,7 @@ repeat:spin_unlock (&dentry->d_lock);continue ; } -prune_one_dentry (dentry,1 ); +prune_one_dentry (dentry);cond_resched_lock (&dcache_lock); goto repeat; }
@@ -858,7 +854,7 @@ void shrink_dcache_parent(struct dentryint found;while ((found =select_parent (parent)) !=0 ) -prune_dcache (found, parent->d_sb,1 ); +prune_dcache (found, parent->d_sb); }/*
@@ -878,7 +874,7 @@ static int shrink_dcache_memory(int nr,if (nr) {if (!(gfp_mask & __GFP_FS))return -1 ; -prune_dcache (nr,NULL ,1 ); +prune_dcache (nr,NULL ); }return (dentry_stat.nr_unused /100 ) * sysctl_vfs_cache_pressure; }
--
[email protected]
maintainerPATCH 8/9 UML: remove unnecessary hostfs_getattr()
In reply to [email protected]From: Miklos Szeredi <[email protected]>
Currently hostfs_getattr() just defines the default behavior.
---
fs/hostfs/hostfs_kern.c +0 -9
@@ -874,13 +874,6 @@ int hostfs_setattr(struct dentry *dentryreturn inode_setattr (dentry->d_inode, attr); } -int hostfs_getattr (struct vfsmount *mnt,struct dentry *dentry, -struct kstat *stat) -{ -generic_fillattr (dentry->d_inode, stat); -return 0 ; -} -static const struct inode_operations hostfs_iops = { .create = hostfs_create, .link = hostfs_link,
@@ -892,7 +885,6 @@ static const struct inode_operations hos .rename = hostfs_rename, .permission = hostfs_permission, .setattr = hostfs_setattr, - .getattr = hostfs_getattr, };static const struct inode_operations hostfs_dir_iops = {
@@ -907,7 +899,6 @@ static const struct inode_operations hos .rename = hostfs_rename, .permission = hostfs_permission, .setattr = hostfs_setattr, - .getattr = hostfs_getattr, };int hostfs_link_readpage (struct file *file,struct page *page)
--
[email protected]
maintainerPATCH 9/9 fix warnings is revoked_inode.c
In reply to [email protected]From: Miklos Szeredi <[email protected]>
Fix following warnings introduced by fs-introduce-write_begin-write_end-and-perform_write-aops-revoke.patch
fs/revoked_inode.c:381: warning: ‘revoked_write_begin’ defined but not used fs/revoked_inode.c:388: warning: ‘revoked_write_end’ defined but not used
---
fs/revoked_inode.c +2 -14
@@ -363,18 +363,6 @@ static int revoked_writepage(struct pagereturn -EIO ; } -static int revoked_prepare_write (struct file *file,struct page *page, -unsigned from,unsigned to) -{ -return -EIO ; -} - -static int revoked_commit_write (struct file *file,struct page *page, -unsigned from,unsigned to) -{ -return -EIO ; -} -static int revoked_write_begin (struct file *file,struct address_space *mapping,loff_t pos,unsigned len,unsigned flags,struct page **pagep,void **fsdata)
@@ -399,8 +387,8 @@ static ssize_t revoked_direct_IO(int rw,static const struct address_space_operations revoked_aops = { .readpage = revoked_readpage, .writepage = revoked_writepage, - .prepare_write = revoked_prepare_write, - .commit_write = revoked_commit_write, + .write_begin = revoked_write_begin, + .write_end = revoked_write_end, .direct_IO = revoked_direct_IO, };
--