ceph: check i_nlink while converting a file handle to dentry
PATCH 1/1 ceph: check i_nlink while converting a file handle to dentry
Converting a file handle to a dentry can be done call after the inode unlink. This means that __fh_to_dentry() requires an extra check to verify the number of links is not 0.
The issue can be easily reproduced using xfstest generic/426, which does something like:
name_to_handle_at(&fh)
echo 3 > /proc/sys/vm/drop_caches
unlink()
open_by_handle_at(&fh)
The call to open_by_handle_at() should fail, as the file doesn't exist anymore.
--- fs/ceph/export.c | 4 ++++ 1 file changed, 4 insertions(+)
fs/ceph/export.c +4 -0
@@ -91,6 +91,10 @@ static struct dentry *__fh_to_dentry(struct super_block *sb, u64 ino)ceph_mdsc_put_request (req);if (!inode)return ERR_PTR (-ESTALE ); +if (inode->i_nlink ==0 ) { +iput (inode); +return ERR_PTR (-ESTALE ); + } }return d_obtain_alias (inode);
Quoted 30 lines · Luis Henriques
Converting a file handle to a dentry can be done call after the inode unlink. This means that
__fh_to_dentry()requires an extra check to verify the number of links is not 0.The issue can be easily reproduced using xfstest generic/426, which does something like:
name_to_handle_at(&fh)
echo 3 >/proc/sys/vm/drop_caches
unlink()
open_by_handle_at(&fh)The call to
open_by_handle_at()should fail, as the file doesn't exist anymore.Signed-off-by Luis Henriques <[email protected]>---
fs/ceph/export.c| 4 ++++1 file changed, 4 insertions(+)fs/ceph/export.c +0
-0
fs/ceph/export.c static struct dentry *__fh_to_dentry(struct super_block *sb, u64 ino) · line 98
Quoted 8 lines
fs/ceph/export.c +4
-0@@ -91,6 +91,10 @@ static struct dentry *__fh_to_dentry(struct super_block *sb, u64 ino)ceph_mdsc_put_request (req);if (!inode)return ERR_PTR (-ESTALE ); +if (inode->i_nlink ==0 ) { +iput (inode); +return ERR_PTR (-ESTALE ); + } }
maybe we should do this check in MDS
Regards
Yan, Zheng
Quoted 2 lines
fs/ceph/export.c +0
-0return d_obtain_alias (inode);
Quoted 25 lines · Zheng
Quoted 25 lines · Luis Henriques
Converting a file handle to a dentry can be done call after the inode unlink. This means that
__fh_to_dentry()requires an extra check to verify the number of links is not 0.The issue can be easily reproduced using xfstest generic/426, which does something like:
name_to_handle_at(&fh)
echo 3 >/proc/sys/vm/drop_caches
unlink()
open_by_handle_at(&fh)The call to
open_by_handle_at()should fail, as the file doesn't exist anymore.Signed-off-by Luis Henriques <[email protected]>---
fs/ceph/export.c| 4 ++++1 file changed, 4 insertions(+)
Quoted 15 lines
fs/ceph/export.c static struct dentry *__fh_to_dentry(struct super_block *sb, u64 ino) · line 98
Quoted 13 lines
fs/ceph/export.c +4
-0@@ -91,6 +91,10 @@ static struct dentry *__fh_to_dentry(struct super_block *sb, u64 ino)ceph_mdsc_put_request (req);if (!inode)return ERR_PTR (-ESTALE ); +if (inode->i_nlink ==0 ) { +iput (inode); +return ERR_PTR (-ESTALE ); + } }maybe we should do this check in MDS
Thank you for your review. Are you suggesting to do this check *only* in the MDS? I guess that's probably a good thing to do too, but don't you think it's a good idea to keep it on the client side as well?
Cheers,
--
Luís
Yan, Zheng
AppliedQuoted 45 lines · Luis Henriques
Quoted 25 lines · Zheng
Quoted 25 lines · Luis Henriques
Converting a file handle to a dentry can be done call after the inode unlink. This means that
__fh_to_dentry()requires an extra check to verify the number of links is not 0.The issue can be easily reproduced using xfstest generic/426, which does something like:
name_to_handle_at(&fh)
echo 3 >/proc/sys/vm/drop_cachesunlink()open_by_handle_at(&fh)The call to
open_by_handle_at()should fail, as the file doesn't exist anymore.Signed-off-by Luis Henriques <[email protected]>---
fs/ceph/export.c| 4 ++++1 file changed, 4 insertions(+)Quoted 15 lines
fs/ceph/export.c static struct dentry *__fh_to_dentry(struct super_block *sb, u64 ino) · line 98
Quoted 13 lines
fs/ceph/export.c +4
-0@@ -91,6 +91,10 @@ static struct dentry *__fh_to_dentry(struct super_block *sb, u64 ino)ceph_mdsc_put_request (req);if (!inode)return ERR_PTR (-ESTALE ); +if (inode->i_nlink ==0 ) { +iput (inode); +return ERR_PTR (-ESTALE ); + } }maybe we should do this check in MDS
Quoted 3 lines
Thank you for your review. Are you suggesting to do this check *only* in the MDS? I guess that's probably a good thing to do too, but don't you think it's a good idea to keep it on the client side as well?
Applied. Thanks
Yan, Zheng
Quoted 4 lines
Cheers,
--
Luís