fs/9p: Add fid before dentry instantiation
Subsystems (2)
RFC PATCH 1/2 fs/9p: Add fid before dentry instantiation
d_instantiate marks the dentry positive. So a parallel lookup and mkdir of the directory can find dentry that doesn't have fid attached. This can result in both the code path doing v9fs_fid_add which results in v9fs_dentry leak.
Signed-off-by Aneesh Kumar K.V <[email protected]>
--- fs/9p/vfs_inode.c | 4 +--- fs/9p/vfs_inode_dotl.c | 8 ++++---- 2 files changed, 5 insertions(+), 7 deletions(-)
fs/9p/vfs_inode.c +1 -3
@@ -645,13 +645,11 @@ v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir,P9_DPRINTK (P9_DEBUG_VFS ,"inode creation failed %d\n" , err); goto error; } -d_instantiate (dentry, inode); err =v9fs_fid_add (dentry, fid);if (err <0 ) goto error; - +d_instantiate (dentry, inode);return ofid; - error:if (ofid)p9_client_clunk (ofid);
fs/9p/vfs_inode_dotl.c +4 -4
@@ -281,10 +281,10 @@ v9fs_vfs_create_dotl(struct inode *dir, struct dentry *dentry, int omode,P9_DPRINTK (P9_DEBUG_VFS ,"inode creation failed %d\n" , err); goto error; } -d_instantiate (dentry, inode); err =v9fs_fid_add (dentry, fid);if (err <0 ) goto error; +d_instantiate (dentry, inode);/* Now set the ACL based on the default value */ v9fs_set_create_acl (dentry, &dacl, &pacl);
@@ -403,10 +403,10 @@ static int v9fs_vfs_mkdir_dotl(struct inode *dir, err); goto error; } -d_instantiate (dentry, inode); err =v9fs_fid_add (dentry, fid);if (err <0 ) goto error; +d_instantiate (dentry, inode); fid =NULL ; }else {/*
@@ -657,10 +657,10 @@ v9fs_vfs_symlink_dotl(struct inode *dir, struct dentry *dentry, err); goto error; } -d_instantiate (dentry, inode); err =v9fs_fid_add (dentry, fid);if (err <0 ) goto error; +d_instantiate (dentry, inode); fid =NULL ; }else {/* Not in cached mode. No need to populate inode with stat */
@@ -810,10 +810,10 @@ v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, int omode, err); goto error; } -d_instantiate (dentry, inode); err =v9fs_fid_add (dentry, fid);if (err <0 ) goto error; +d_instantiate (dentry, inode); fid =NULL ; }else {/*
Signature · 1 line
1.7.4.1
RFC PATCH 2/2 fs/9p: Don't update file type when updating file attributes
We should only update attributes that we can change on stat2inode. Also do file type initialization in v9fs_init_inode.
Signed-off-by Aneesh Kumar K.V <[email protected]>
--- fs/9p/v9fs_vfs.h | 4 +- fs/9p/vfs_inode.c | 91 ++++++++++++++++++++++++++--------------------- fs/9p/vfs_inode_dotl.c | 23 ++++++++---- fs/9p/vfs_super.c | 2 +- 4 files changed, 68 insertions(+), 52 deletions(-)
fs/9p/v9fs_vfs.h +2 -2
@@ -54,9 +54,9 @@ extern struct kmem_cache *v9fs_inode_cache;struct inode *v9fs_alloc_inode (struct super_block *sb);void v9fs_destroy_inode (struct inode *inode); -struct inode *v9fs_get_inode (struct super_block *sb,int mode); +struct inode *v9fs_get_inode (struct super_block *sb,int mode,dev_t );int v9fs_init_inode (struct v9fs_session_info *v9ses, -struct inode *inode,int mode); +struct inode *inode,int mode,dev_t );void v9fs_evict_inode (struct inode *inode);ino_t v9fs_qid2ino (struct p9_qid *qid);void v9fs_stat2inode (struct p9_wstat *,struct inode *,struct super_block *);
fs/9p/vfs_inode.c +50 -41
195 lines not on this page · raw message
fs/9p/vfs_inode_dotl.c +15 -8
@@ -153,7 +153,8 @@ static struct inode *v9fs_qid_iget_dotl(struct super_block *sb,* later. */ inode->i_ino = i_ino; - retval =v9fs_init_inode (v9ses, inode, st->st_mode); + retval =v9fs_init_inode (v9ses, inode, + st->st_mode,new_decode_dev (st->st_rdev));if (retval) goto error;
@@ -414,7 +415,7 @@ static int v9fs_vfs_mkdir_dotl(struct inode *dir,* inode with stat. We need to get an inode * so that we can set the acl with dentry */ - inode =v9fs_get_inode (dir->i_sb, mode); + inode =v9fs_get_inode (dir->i_sb, mode,0 );if (IS_ERR (inode)) { err =PTR_ERR (inode); goto error;
@@ -540,6 +541,7 @@ int v9fs_vfs_setattr_dotl(struct dentry *dentry, struct iattr *iattr)void v9fs_stat2inode_dotl (struct p9_stat_dotl *stat,struct inode *inode) { +mode_t mode;struct v9fs_inode *v9inode =V9FS_I (inode);if ((stat->st_result_mask &P9_STATS_BASIC ) ==P9_STATS_BASIC ) {
@@ -552,11 +554,10 @@ v9fs_stat2inode_dotl(struct p9_stat_dotl *stat, struct inode *inode) inode->i_uid = stat->st_uid; inode->i_gid = stat->st_gid; inode->i_nlink = stat->st_nlink; - inode->i_mode = stat->st_mode; - inode->i_rdev =new_decode_dev (stat->st_rdev); -if ((S_ISBLK (inode->i_mode)) || (S_ISCHR (inode->i_mode))) -init_special_inode (inode, inode->i_mode, inode->i_rdev); + mode = stat->st_mode &S_IALLUGO ; + mode |= inode->i_mode & ~S_IALLUGO ; + inode->i_mode = mode;i_size_write (inode, stat->st_size); inode->i_blocks = stat->st_blocks;
@@ -664,7 +665,7 @@ v9fs_vfs_symlink_dotl(struct inode *dir, struct dentry *dentry, fid =NULL ; }else {/* Not in cached mode. No need to populate inode with stat */ - inode =v9fs_get_inode (dir->i_sb,S_IFLNK ); + inode =v9fs_get_inode (dir->i_sb,S_IFLNK ,0 );if (IS_ERR (inode)) { err =PTR_ERR (inode); goto error;
@@ -820,7 +821,7 @@ v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, int omode,* Not in cached mode. No need to populate inode with stat. * socket syscall returns a fd, so we need instantiate */ - inode =v9fs_get_inode (dir->i_sb, mode); + inode =v9fs_get_inode (dir->i_sb, mode, rdev);if (IS_ERR (inode)) { err =PTR_ERR (inode); goto error;
@@ -886,6 +887,11 @@ int v9fs_refresh_inode_dotl(struct p9_fid *fid, struct inode *inode) st =p9_client_getattr_dotl (fid,P9_STATS_ALL );if (IS_ERR (st))return PTR_ERR (st); +/* +* Don't update inode if the file type is different +*/ +if ((inode->i_mode &S_IFMT ) != (st->st_mode &S_IFMT )) + goto out;spin_lock (&inode->i_lock);/*
@@ -897,6 +903,7 @@ int v9fs_refresh_inode_dotl(struct p9_fid *fid, struct inode *inode)if (v9ses->cache) inode->i_size = i_size;spin_unlock (&inode->i_lock); +out:kfree (st);return 0 ; }
fs/9p/vfs_super.c +1 -1
@@ -149,7 +149,7 @@ static struct dentry *v9fs_mount(struct file_system_type *fs_type, int flags,else sb->s_d_op = &v9fs_dentry_operations; - inode =v9fs_get_inode (sb,S_IFDIR | mode); + inode =v9fs_get_inode (sb,S_IFDIR | mode,0 );if (IS_ERR (inode)) { retval =PTR_ERR (inode); goto release_sb;
Signature · 1 line
1.7.4.1