linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] autofs: drop dentry reference only when it is never used
@ 2018-11-26  1:58 Pan Bian
  2018-11-26 10:36 ` Ian Kent
  0 siblings, 1 reply; 2+ messages in thread
From: Pan Bian @ 2018-11-26  1:58 UTC (permalink / raw)
  To: Ian Kent; +Cc: autofs, linux-kernel, Pan Bian

The function autofs_expire_run calls dput(dentry) to drop the reference
count of dentry. However, dentry is read via autofs_dentry_ino(dentry)
after that. This may result in a use-free-bug. The patch drops the
reference count of dentry only when it is never used.

Signed-off-by: Pan Bian <bianpan2016@163.com>
---
 fs/autofs/expire.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/autofs/expire.c b/fs/autofs/expire.c
index d441244..28d9c2b 100644
--- a/fs/autofs/expire.c
+++ b/fs/autofs/expire.c
@@ -596,7 +596,6 @@ int autofs_expire_run(struct super_block *sb,
 	pkt.len = dentry->d_name.len;
 	memcpy(pkt.name, dentry->d_name.name, pkt.len);
 	pkt.name[pkt.len] = '\0';
-	dput(dentry);
 
 	if (copy_to_user(pkt_p, &pkt, sizeof(struct autofs_packet_expire)))
 		ret = -EFAULT;
@@ -609,6 +608,8 @@ int autofs_expire_run(struct super_block *sb,
 	complete_all(&ino->expire_complete);
 	spin_unlock(&sbi->fs_lock);
 
+	dput(dentry);
+
 	return ret;
 }
 
-- 
2.7.4



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

* Re: [PATCH] autofs: drop dentry reference only when it is never used
  2018-11-26  1:58 [PATCH] autofs: drop dentry reference only when it is never used Pan Bian
@ 2018-11-26 10:36 ` Ian Kent
  0 siblings, 0 replies; 2+ messages in thread
From: Ian Kent @ 2018-11-26 10:36 UTC (permalink / raw)
  To: Pan Bian; +Cc: autofs, linux-kernel

On Mon, 2018-11-26 at 09:58 +0800, Pan Bian wrote:
> The function autofs_expire_run calls dput(dentry) to drop the reference
> count of dentry. However, dentry is read via autofs_dentry_ino(dentry)
> after that. This may result in a use-free-bug. The patch drops the
> reference count of dentry only when it is never used.

Yes, I agree this is a bug and it should be fixed.

The autofs_expire_run() function is used for autofs v3 which is
very old now so it's not likely to be called.

But I think you are correct, if it is called the copy to user
space should trigger a umount and (likley) remove the mount
point directory, maybe I broke this at some point without
realising it ...

So thanks, I'll have a closer look but even if the ref counting
isn't quite what either of us expect this is probably still worth
while.

If I don't see any reason to not do this I'll forward the patch
to Andrew.

Ian
> 
> Signed-off-by: Pan Bian <bianpan2016@163.com>
> ---
>  fs/autofs/expire.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/autofs/expire.c b/fs/autofs/expire.c
> index d441244..28d9c2b 100644
> --- a/fs/autofs/expire.c
> +++ b/fs/autofs/expire.c
> @@ -596,7 +596,6 @@ int autofs_expire_run(struct super_block *sb,
>  	pkt.len = dentry->d_name.len;
>  	memcpy(pkt.name, dentry->d_name.name, pkt.len);
>  	pkt.name[pkt.len] = '\0';
> -	dput(dentry);
>  
>  	if (copy_to_user(pkt_p, &pkt, sizeof(struct autofs_packet_expire)))
>  		ret = -EFAULT;
> @@ -609,6 +608,8 @@ int autofs_expire_run(struct super_block *sb,
>  	complete_all(&ino->expire_complete);
>  	spin_unlock(&sbi->fs_lock);
>  
> +	dput(dentry);
> +
>  	return ret;
>  }
>  


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

end of thread, other threads:[~2018-11-26 10:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-26  1:58 [PATCH] autofs: drop dentry reference only when it is never used Pan Bian
2018-11-26 10:36 ` Ian Kent

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