Skip to contentSkip to conversation

ceph: fix inode leak on getattr error in __fh_to_dentry

PATCH In review Jeff Layton 3 participants 5 messages Mar 26, 2021 – Mar 31, 2021 Ceph client

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ceph: fix inode leak on getattr error in __fh_to_dentry

Cc Luis Henriques <[email protected]>
Fixes 878dabb64117 (ceph: don't return -ESTALE if there's still an open file)
---
 fs/ceph/export.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/ceph/export.c +3 -1
index f22156ee7306..17d8c8f4ec89 100644
@@ -178,8 +178,10 @@ static struct dentry *__fh_to_dentry(struct super_block *sb, u64 ino)
 		return ERR_CAST(inode);
 	/* We need LINK caps to reliably check i_nlink */
 	err = ceph_do_getattr(inode, CEPH_CAP_LINK_SHARED, false);
-	if (err)
+	if (err) {
+		iput(inode);
 		return ERR_PTR(err);
+	}
 	/* -ESTALE if inode as been unlinked and no file is open */
 	if ((inode->i_nlink == 0) && (atomic_read(&inode->i_count) == 1)) {
 		iput(inode);
Signature · 1 line
2.30.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · Jeff Layton
Cc Luis Henriques <[email protected]>
Fixes 878dabb64117 (ceph: don't return -ESTALE if there's still an open file)
---
  fs/ceph/export.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
fs/ceph/export.c +0 -0
index f22156ee7306..17d8c8f4ec89 100644
@@ -178,8 +178,10 @@ static struct dentry *__fh_to_dentry(struct super_block *sb, u64 ino)
  		return ERR_CAST(inode);

fs/ceph/export.c static struct dentry *__fh_to_dentry(struct super_block *sb, u64 ino) · line 187

Quoted 10 lines
fs/ceph/export.c +3 -1
  	/* We need LINK caps to reliably check i_nlink */
  	err = ceph_do_getattr(inode, CEPH_CAP_LINK_SHARED, false);
-	if (err)
+	if (err) {
+		iput(inode);
  		return ERR_PTR(err);
+	}
  	/* -ESTALE if inode as been unlinked and no file is open */
  	if ((inode->i_nlink == 0) && (atomic_read(&inode->i_count) == 1)) {
  		iput(inode);
#2 lore raw
In reply to Jeff Layton
Quoted 12 lines · Jeff Layton
Cc Luis Henriques <[email protected]>
Fixes 878dabb64117 (ceph: don't return -ESTALE if there's still an open file)
---
 fs/ceph/export.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/ceph/export.c +0 -0
index f22156ee7306..17d8c8f4ec89 100644

fs/ceph/export.c static struct dentry *__fh_to_dentry(struct super_block *sb, u64 ino) · line 182

Quoted 6 lines
fs/ceph/export.c +2 -1
@@ -178,8 +178,10 @@ static struct dentry *__fh_to_dentry(struct super_block *sb, u64 ino)
 		return ERR_CAST(inode);
 	/* We need LINK caps to reliably check i_nlink */
 	err = ceph_do_getattr(inode, CEPH_CAP_LINK_SHARED, false);
-	if (err)
+	if (err) {
+		iput(inode);

To be honest, I'm failing to see where we could be leaking the inode here. We're trying to get LINK caps to do the check bellow; if ceph_do_getattr() fails, the inode reference it (may) grabs will be released by calling ceph_mdsc_put_request().

Do you see any other possibility?

Cheers,
--
Luís

Quoted 8 lines
fs/ceph/export.c +1 -0
 		return ERR_PTR(err);
+	}
 	/* -ESTALE if inode as been unlinked and no file is open */
 	if ((inode->i_nlink == 0) && (atomic_read(&inode->i_count) == 1)) {
 		iput(inode);
Signature · 1 line
2.30.2
#3 lore raw
Quoted 25 lines · Luis Henriques
Quoted 12 lines · Jeff Layton
Cc Luis Henriques <[email protected]>
Fixes 878dabb64117 (ceph: don't return -ESTALE if there's still an open file)
---
 fs/ceph/export.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/ceph/export.c +0 -0
index f22156ee7306..17d8c8f4ec89 100644

fs/ceph/export.c static struct dentry *__fh_to_dentry(struct super_block *sb, u64 ino) · line 182

Quoted 6 lines
fs/ceph/export.c +2 -1
@@ -178,8 +178,10 @@ static struct dentry *__fh_to_dentry(struct super_block *sb, u64 ino)
 		return ERR_CAST(inode);
 	/* We need LINK caps to reliably check i_nlink */
 	err = ceph_do_getattr(inode, CEPH_CAP_LINK_SHARED, false);
-	if (err)
+	if (err) {
+		iput(inode);

To be honest, I'm failing to see where we could be leaking the inode here. We're trying to get LINK caps to do the check bellow; if ceph_do_getattr() fails, the inode reference it (may) grabs will be released by calling ceph_mdsc_put_request().

Quoted 2 lines

Do you see any other possibility?

We already hold a reference to the inode at this point by virtue of the successful return from __lookup_inode. ceph_do_getattr does not consume that reference on success or failure, AFAICT.

Signature · 1 line
Jeff Layton <[email protected]>
#4 lore raw
Quoted 26 lines · Jeff Layton
Quoted 25 lines · Luis Henriques
Quoted 12 lines · Jeff Layton
Cc Luis Henriques <[email protected]>
Fixes 878dabb64117 (ceph: don't return -ESTALE if there's still an open file)
---
 fs/ceph/export.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/ceph/export.c +0 -0
index f22156ee7306..17d8c8f4ec89 100644

fs/ceph/export.c static struct dentry *__fh_to_dentry(struct super_block *sb, u64 ino) · line 182

Quoted 6 lines
fs/ceph/export.c +2 -1
@@ -178,8 +178,10 @@ static struct dentry *__fh_to_dentry(struct super_block *sb, u64 ino)
 		return ERR_CAST(inode);
 	/* We need LINK caps to reliably check i_nlink */
 	err = ceph_do_getattr(inode, CEPH_CAP_LINK_SHARED, false);
-	if (err)
+	if (err) {
+		iput(inode);

To be honest, I'm failing to see where we could be leaking the inode here. We're trying to get LINK caps to do the check bellow; if ceph_do_getattr() fails, the inode reference it (may) grabs will be released by calling ceph_mdsc_put_request().

Quoted 6 lines
Quoted 2 lines

Do you see any other possibility?

We already hold a reference to the inode at this point by virtue of the successful return from __lookup_inode. ceph_do_getattr does not consume that reference on success or failure, AFAICT.

Doh! Of course. I was looking at it the wrong way.

Cheers,
--
Luís