public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fuse: add missing iput() in fuse_lookup() error path
@ 2025-12-19 17:43 Luis Henriques
  2025-12-19 22:10 ` Al Viro
  0 siblings, 1 reply; 4+ messages in thread
From: Luis Henriques @ 2025-12-19 17:43 UTC (permalink / raw)
  To: Miklos Szeredi, Al Viro
  Cc: mszeredi, linux-fsdevel, linux-kernel, kernel-dev, Luis Henriques

The inode use count needs to be dropped in the fuse_lookup() error path,
when there's an error returned by d_splice_alias().

(While there, remove extra white spaces before labels.)

Fixes: 5835f3390e35 ("fuse: use d_materialise_unique()")
Signed-off-by: Luis Henriques <luis@igalia.com>
---
 fs/fuse/dir.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index 4b6b3d2758ff..75032b947a13 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -636,7 +636,7 @@ static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry,
 	newent = d_splice_alias(inode, entry);
 	err = PTR_ERR(newent);
 	if (IS_ERR(newent))
-		goto out_err;
+		goto out_iput;
 
 	entry = newent ? newent : entry;
 	entry->d_time = epoch;
@@ -649,9 +649,9 @@ static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry,
 		fuse_advise_use_readdirplus(dir);
 	return newent;
 
- out_iput:
+out_iput:
 	iput(inode);
- out_err:
+out_err:
 	return ERR_PTR(err);
 }
 

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

* Re: [PATCH] fuse: add missing iput() in fuse_lookup() error path
  2025-12-19 17:43 [PATCH] fuse: add missing iput() in fuse_lookup() error path Luis Henriques
@ 2025-12-19 22:10 ` Al Viro
  2025-12-19 22:14   ` Al Viro
  2025-12-23 14:31   ` Luis Henriques
  0 siblings, 2 replies; 4+ messages in thread
From: Al Viro @ 2025-12-19 22:10 UTC (permalink / raw)
  To: Luis Henriques
  Cc: Miklos Szeredi, mszeredi, linux-fsdevel, linux-kernel, kernel-dev

On Fri, Dec 19, 2025 at 05:43:09PM +0000, Luis Henriques wrote:
> The inode use count needs to be dropped in the fuse_lookup() error path,
> when there's an error returned by d_splice_alias().
> 
> (While there, remove extra white spaces before labels.)
> 
> Fixes: 5835f3390e35 ("fuse: use d_materialise_unique()")
> Signed-off-by: Luis Henriques <luis@igalia.com>

Have you actually looked at d_splice_alias()?

It does consume inode reference in all cases, success or error.  On success
it gets transferred to dentry; on failure it is dropped.  That's quite
deliberate, since it makes life much simplier for failure handling in the
callers.

If you can reproduce a leak there, I would like to see a reproducer.
If not, I would say that your patch introduces a double-iput.

NAK.

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

* Re: [PATCH] fuse: add missing iput() in fuse_lookup() error path
  2025-12-19 22:10 ` Al Viro
@ 2025-12-19 22:14   ` Al Viro
  2025-12-23 14:31   ` Luis Henriques
  1 sibling, 0 replies; 4+ messages in thread
From: Al Viro @ 2025-12-19 22:14 UTC (permalink / raw)
  To: Luis Henriques
  Cc: Miklos Szeredi, mszeredi, linux-fsdevel, linux-kernel, kernel-dev

On Fri, Dec 19, 2025 at 10:10:31PM +0000, Al Viro wrote:
> On Fri, Dec 19, 2025 at 05:43:09PM +0000, Luis Henriques wrote:
> > The inode use count needs to be dropped in the fuse_lookup() error path,
> > when there's an error returned by d_splice_alias().
> > 
> > (While there, remove extra white spaces before labels.)
> > 
> > Fixes: 5835f3390e35 ("fuse: use d_materialise_unique()")
> > Signed-off-by: Luis Henriques <luis@igalia.com>
> 
> Have you actually looked at d_splice_alias()?
> 
> It does consume inode reference in all cases, success or error.  On success
> it gets transferred to dentry; on failure it is dropped.  That's quite
> deliberate, since it makes life much simplier for failure handling in the
> callers.
> 
> If you can reproduce a leak there, I would like to see a reproducer.
> If not, I would say that your patch introduces a double-iput.
> 
> NAK.

PS: out_iput in there is needed only on one failure exit - after we'd
found an inode and before we'd passed it to d_splice_alias().

FWIW, I would rather replace that with
	if (inode && get_node_id(inode) == FUSE_ROOT_ID) {
		iput(inode);
		return ERR_PTR(-EIO);
	}
and turned all goto out_err; into direct returns.


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

* Re: [PATCH] fuse: add missing iput() in fuse_lookup() error path
  2025-12-19 22:10 ` Al Viro
  2025-12-19 22:14   ` Al Viro
@ 2025-12-23 14:31   ` Luis Henriques
  1 sibling, 0 replies; 4+ messages in thread
From: Luis Henriques @ 2025-12-23 14:31 UTC (permalink / raw)
  To: Al Viro; +Cc: Miklos Szeredi, linux-fsdevel, linux-kernel, kernel-dev

On Fri, Dec 19 2025, Al Viro wrote:

> On Fri, Dec 19, 2025 at 05:43:09PM +0000, Luis Henriques wrote:
>> The inode use count needs to be dropped in the fuse_lookup() error path,
>> when there's an error returned by d_splice_alias().
>> 
>> (While there, remove extra white spaces before labels.)
>> 
>> Fixes: 5835f3390e35 ("fuse: use d_materialise_unique()")
>> Signed-off-by: Luis Henriques <luis@igalia.com>
>
> Have you actually looked at d_splice_alias()?
>
> It does consume inode reference in all cases, success or error.  On success
> it gets transferred to dentry; on failure it is dropped.  That's quite
> deliberate, since it makes life much simplier for failure handling in the
> callers.
>
> If you can reproduce a leak there, I would like to see a reproducer.
> If not, I would say that your patch introduces a double-iput.
>
> NAK.

Totally deserved :-(

To be honest, while investigating this I remember finding the following in
d_obtain_alias() documentation:

  On successful return, the reference to the inode has been transferred
  to the dentry.  In case of an error the reference on the inode is released.

Since d_splice_alias() didn't included that note explicitly, I (wrongly)
assumed it would *not* consume the reference.  Sure, I did had a look at
the function, but clearly not close enough.

Sorry for wasting your time, and thank you for the explanation.

Cheers,
-- 
Luís

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

end of thread, other threads:[~2025-12-23 14:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-19 17:43 [PATCH] fuse: add missing iput() in fuse_lookup() error path Luis Henriques
2025-12-19 22:10 ` Al Viro
2025-12-19 22:14   ` Al Viro
2025-12-23 14:31   ` Luis Henriques

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox