EXPORTFS: Don't return NULL from fh_to_dentry()/fh_to_parent() [ver #2]
Subsystems (10)
PATCH 1/1 EXPORTFS: Don't return NULL from fh_to_dentry()/fh_to_parent() [ver #2]
Returning NULL from fh_to_dentry() and fh_to_parent() is not permitted, so return -ESTALE instead. exportfs_decode_fh() does not check for NULL, but will try to dereference it as IS_ERR() does not check for it.
The generic_fh_to_dentry() and generic_fh_to_parent() functions also no longer return NULL, but return -ESTALE instead.
---
fs/fat/inode.c | 2 +- fs/fuse/inode.c | 4 ++-- fs/gfs2/ops_export.c | 4 ++-- fs/isofs/export.c | 4 ++-- fs/libfs.c | 4 ++-- fs/ocfs2/export.c | 4 ++-- fs/udf/namei.c | 4 ++-- fs/xfs/linux-2.6/xfs_export.c | 2 +- mm/shmem.c | 2 +- 9 files changed, 15 insertions(+), 15 deletions(-)
fs/fat/inode.c +1 -1
@@ -657,7 +657,7 @@ static struct dentry *fat_fh_to_dentry(struct super_block *sb,u32 *fh = fid->raw;if (fh_len <5 || fh_type !=3 ) -return NULL ; +return ERR_PTR (-ESTALE ); inode =ilookup (sb, fh[0 ]);if (!inode || inode->i_generation != fh[1 ]) {
fs/fuse/inode.c +2 -2
@@ -653,7 +653,7 @@ static struct dentry *fuse_fh_to_dentry(struct super_block *sb,struct fuse_inode_handle handle;if ((fh_type !=0x81 && fh_type !=0x82 ) || fh_len <3 ) -return NULL ; +return ERR_PTR (-ESTALE ); handle.nodeid = (u64 ) fid->raw[0 ] <<32 ; handle.nodeid |= (u64 ) fid->raw[1 ];
@@ -667,7 +667,7 @@ static struct dentry *fuse_fh_to_parent(struct super_block *sb,struct fuse_inode_handle parent;if (fh_type !=0x82 || fh_len <6 ) -return NULL ; +return ERR_PTR (-ESTALE ); parent.nodeid = (u64 ) fid->raw[3 ] <<32 ; parent.nodeid |= (u64 ) fid->raw[4 ];
fs/gfs2/ops_export.c +2 -2
@@ -254,7 +254,7 @@ static struct dentry *gfs2_fh_to_dentry(struct super_block *sb, struct fid *fid, this.no_addr |=be32_to_cpu (fh[3 ]);return gfs2_get_dentry (sb, &this);default : -return NULL ; +return ERR_PTR (-ESTALE ); } }
@@ -273,7 +273,7 @@ static struct dentry *gfs2_fh_to_parent(struct super_block *sb, struct fid *fid, parent.no_addr |=be32_to_cpu (fh[7 ]);return gfs2_get_dentry (sb, &parent);default : -return NULL ; +return ERR_PTR (-ESTALE ); } }
fs/isofs/export.c +2 -2
@@ -164,7 +164,7 @@ static struct dentry *isofs_fh_to_dentry(struct super_block *sb,struct isofs_fid *ifid = (struct isofs_fid *)fid;if (fh_len <3 || fh_type >2 ) -return NULL ; +return ERR_PTR (-ESTALE );return isofs_export_iget (sb, ifid->block, ifid->offset, ifid->generation);
@@ -176,7 +176,7 @@ static struct dentry *isofs_fh_to_parent(struct super_block *sb,struct isofs_fid *ifid = (struct isofs_fid *)fid;if (fh_type !=2 ) -return NULL ; +return ERR_PTR (-ESTALE ); return isofs_export_iget(sb, fh_len > 2 ? ifid->parent_block : 0,
fs/libfs.c +2 -2
@@ -751,7 +751,7 @@ struct dentry *generic_fh_to_dentry(struct super_block *sb, struct fid *fid,struct inode *inode =NULL ;if (fh_len <2 ) -return NULL ; +return ERR_PTR (-ESTALE );switch (fh_type) {case FILEID_INO32_GEN :
@@ -784,7 +784,7 @@ struct dentry *generic_fh_to_parent(struct super_block *sb, struct fid *fid,struct inode *inode =NULL ;if (fh_len <=2 ) -return NULL ; +return ERR_PTR (-ESTALE );switch (fh_type) {case FILEID_INO32_GEN_PARENT :
fs/ocfs2/export.c +2 -2
@@ -182,7 +182,7 @@ static struct dentry *ocfs2_fh_to_dentry(struct super_block *sb,struct ocfs2_inode_handle handle;if (fh_len <3 || fh_type >2 ) -return NULL ; +return ERR_PTR (-ESTALE ); handle.ih_blkno = (u64 )le32_to_cpu (fid->raw[0 ]) <<32 ; handle.ih_blkno |= (u64 )le32_to_cpu (fid->raw[1 ]);
@@ -196,7 +196,7 @@ static struct dentry *ocfs2_fh_to_parent(struct super_block *sb,struct ocfs2_inode_handle parent;if (fh_type !=2 || fh_len <6 ) -return NULL ; +return ERR_PTR (-ESTALE ); parent.ih_blkno = (u64 )le32_to_cpu (fid->raw[3 ]) <<32 ; parent.ih_blkno |= (u64 )le32_to_cpu (fid->raw[4 ]);
fs/udf/namei.c +2 -2
@@ -1297,7 +1297,7 @@ static struct dentry *udf_fh_to_dentry(struct super_block *sb,if ((fh_len !=3 && fh_len !=5 ) || (fh_type !=FILEID_UDF_WITH_PARENT && fh_type !=FILEID_UDF_WITHOUT_PARENT )) -return NULL ; +return ERR_PTR (-ESTALE );return udf_nfs_get_inode (sb, fid->udf.block, fid->udf.partref, fid->udf.generation);
@@ -1307,7 +1307,7 @@ static struct dentry *udf_fh_to_parent(struct super_block *sb, struct fid *fid, int fh_len, int fh_type) { if (fh_len != 5 || fh_type != FILEID_UDF_WITH_PARENT) - return NULL; + return ERR_PTR(-ESTALE); return udf_nfs_get_inode(sb, fid->udf.parent_block, fid->udf.parent_partref,
fs/xfs/linux-2.6/xfs_export.c +1 -1
@@ -150,7 +150,7 @@ xfs_fs_fh_to_dentry(struct super_block *sb, struct fid *fid,struct inode *inode =NULL ;if (fh_len <xfs_fileid_length (fileid_type)) -return NULL ; +return ERR_PTR (-ESTALE );switch (fileid_type) {case FILEID_INO32_GEN_PARENT :
mm/shmem.c +1 -1
@@ -2055,7 +2055,7 @@ static struct dentry *shmem_fh_to_dentry(struct super_block *sb, inum = (inum <<32 ) | fid->raw[1 ];if (fh_len <3 ) -return NULL ; +return ERR_PTR (-ESTALE ); inode =ilookup5 (sb, (unsigned long )(inum + fid->raw[0 ]), shmem_match, fid->raw);
Quoted 9 lines · David Howells
Returning NULL from
fh_to_dentry()andfh_to_parent()is not permitted, so return-ESTALEinstead.exportfs_decode_fh()does not check for NULL, but will try to dereference it asIS_ERR()does not check for it.The
generic_fh_to_dentry()andgeneric_fh_to_parent()functions also no longer return NULL, but return-ESTALEinstead.Signed-off-by David Howells <[email protected]>Acked-by J. Bruce Fields <[email protected]>
I think it's still wrong in shmem_fh_to_dentry(): you've fixed the early return, but there'd be another return NULL if !inode?
Hugh
Quoted 12 lines
mm/shmem.c +1
-1@@ -2055,7 +2055,7 @@ static struct dentry *shmem_fh_to_dentry(struct super_block *sb, inum = (inum <<32 ) | fid->raw[1 ];if (fh_len <3 ) -return NULL ; +return ERR_PTR (-ESTALE ); inode =ilookup5 (sb, (unsigned long )(inum + fid->raw[0 ]), shmem_match, fid->raw);
Quoted 3 lines · Hugh Dickins
I think it's still wrong in
shmem_fh_to_dentry(): you've fixed the early return, but there'd be another return NULL if !inode?
You're right... Grrr.
David
Quoted 2 lines · Hugh Dickins
I think it's still wrong in
shmem_fh_to_dentry(): you've fixed the early return, but there'd be another return NULL if !inode?
Now that I've fixed that as well, what are the chances of d_find_alias() returning NULL, do you think? I suppose all that's required is for a file to be deleted locally while a remote client has a filehandle to it.
David
Quoted 8 lines · David Howells
Quoted 2 lines · Hugh Dickins
I think it's still wrong in
shmem_fh_to_dentry(): you've fixed the early return, but there'd be another return NULL if !inode?Now that I've fixed that as well, what are the chances of
d_find_alias()returning NULL, do you think? I suppose all that's required is for a file to be deleted locally while a remote client has a filehandle to it.
To be honest, I've no idea - you and hch know what goes on there much better than I do. Unless there's an obvious reason why an incore filesystem like tmpfs or ramfs can't get a NULL there, I think you have to add that protection too. Sorry, it should have crossed my mind too before I misled you by saying "!inode".
Hugh