ceph-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ceph: fix inode leak on getattr error in __fh_to_dentry
@ 2021-03-26 15:40 Jeff Layton
  2021-03-29  3:10 ` Xiubo Li
  2021-03-30 13:46 ` Luis Henriques
  0 siblings, 2 replies; 5+ messages in thread
From: Jeff Layton @ 2021-03-26 15:40 UTC (permalink / raw)
  To: ceph-devel; +Cc: idryomov, Luis Henriques

Cc: Luis Henriques <lhenriques@suse.de>
Fixes: 878dabb64117 (ceph: don't return -ESTALE if there's still an open file)
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
 fs/ceph/export.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/ceph/export.c b/fs/ceph/export.c
index f22156ee7306..17d8c8f4ec89 100644
--- a/fs/ceph/export.c
+++ b/fs/ceph/export.c
@@ -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);
-- 
2.30.2


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ceph: fix inode leak on getattr error in __fh_to_dentry
  2021-03-26 15:40 [PATCH] ceph: fix inode leak on getattr error in __fh_to_dentry Jeff Layton
@ 2021-03-29  3:10 ` Xiubo Li
  2021-03-30 13:46 ` Luis Henriques
  1 sibling, 0 replies; 5+ messages in thread
From: Xiubo Li @ 2021-03-29  3:10 UTC (permalink / raw)
  To: Jeff Layton, ceph-devel; +Cc: idryomov, Luis Henriques

On 2021/3/26 23:40, Jeff Layton wrote:
> Cc: Luis Henriques <lhenriques@suse.de>
> Fixes: 878dabb64117 (ceph: don't return -ESTALE if there's still an open file)
> Signed-off-by: Jeff Layton <jlayton@kernel.org>
> ---
>   fs/ceph/export.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/fs/ceph/export.c b/fs/ceph/export.c
> index f22156ee7306..17d8c8f4ec89 100644
> --- a/fs/ceph/export.c
> +++ b/fs/ceph/export.c
> @@ -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);

Reviewed-by: Xiubo Li <xiubli@redhat.com>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ceph: fix inode leak on getattr error in __fh_to_dentry
  2021-03-26 15:40 [PATCH] ceph: fix inode leak on getattr error in __fh_to_dentry Jeff Layton
  2021-03-29  3:10 ` Xiubo Li
@ 2021-03-30 13:46 ` Luis Henriques
  2021-03-30 16:53   ` Jeff Layton
  1 sibling, 1 reply; 5+ messages in thread
From: Luis Henriques @ 2021-03-30 13:46 UTC (permalink / raw)
  To: Jeff Layton; +Cc: ceph-devel, idryomov

On Fri, Mar 26, 2021 at 11:40:32AM -0400, Jeff Layton wrote:
> Cc: Luis Henriques <lhenriques@suse.de>
> Fixes: 878dabb64117 (ceph: don't return -ESTALE if there's still an open file)
> Signed-off-by: Jeff Layton <jlayton@kernel.org>
> ---
>  fs/ceph/export.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/ceph/export.c b/fs/ceph/export.c
> index f22156ee7306..17d8c8f4ec89 100644
> --- a/fs/ceph/export.c
> +++ b/fs/ceph/export.c
> @@ -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


>  		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.30.2
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ceph: fix inode leak on getattr error in __fh_to_dentry
  2021-03-30 13:46 ` Luis Henriques
@ 2021-03-30 16:53   ` Jeff Layton
  2021-03-31  9:53     ` Luis Henriques
  0 siblings, 1 reply; 5+ messages in thread
From: Jeff Layton @ 2021-03-30 16:53 UTC (permalink / raw)
  To: Luis Henriques; +Cc: ceph-devel, idryomov

On Tue, 2021-03-30 at 14:46 +0100, Luis Henriques wrote:
> On Fri, Mar 26, 2021 at 11:40:32AM -0400, Jeff Layton wrote:
> > Cc: Luis Henriques <lhenriques@suse.de>
> > Fixes: 878dabb64117 (ceph: don't return -ESTALE if there's still an open file)
> > Signed-off-by: Jeff Layton <jlayton@kernel.org>
> > ---
> >  fs/ceph/export.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/fs/ceph/export.c b/fs/ceph/export.c
> > index f22156ee7306..17d8c8f4ec89 100644
> > --- a/fs/ceph/export.c
> > +++ b/fs/ceph/export.c
> > @@ -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?
> 

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.

-- 
Jeff Layton <jlayton@kernel.org>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ceph: fix inode leak on getattr error in __fh_to_dentry
  2021-03-30 16:53   ` Jeff Layton
@ 2021-03-31  9:53     ` Luis Henriques
  0 siblings, 0 replies; 5+ messages in thread
From: Luis Henriques @ 2021-03-31  9:53 UTC (permalink / raw)
  To: Jeff Layton; +Cc: ceph-devel, idryomov

On Tue, Mar 30, 2021 at 12:53:51PM -0400, Jeff Layton wrote:
> On Tue, 2021-03-30 at 14:46 +0100, Luis Henriques wrote:
> > On Fri, Mar 26, 2021 at 11:40:32AM -0400, Jeff Layton wrote:
> > > Cc: Luis Henriques <lhenriques@suse.de>
> > > Fixes: 878dabb64117 (ceph: don't return -ESTALE if there's still an open file)
> > > Signed-off-by: Jeff Layton <jlayton@kernel.org>
> > > ---
> > >  fs/ceph/export.c | 4 +++-
> > >  1 file changed, 3 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/fs/ceph/export.c b/fs/ceph/export.c
> > > index f22156ee7306..17d8c8f4ec89 100644
> > > --- a/fs/ceph/export.c
> > > +++ b/fs/ceph/export.c
> > > @@ -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?
> > 
> 
> 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-03-31  9:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-26 15:40 [PATCH] ceph: fix inode leak on getattr error in __fh_to_dentry Jeff Layton
2021-03-29  3:10 ` Xiubo Li
2021-03-30 13:46 ` Luis Henriques
2021-03-30 16:53   ` Jeff Layton
2021-03-31  9:53     ` Luis Henriques

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).