mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ian Kent <raven@themaw.net>
To: Zilin Guan <zilin@seu.edu.cn>
Cc: autofs@vger.kernel.org, linux-kernel@vger.kernel.org,
	jianhao.xu@seu.edu.cn
Subject: Re: [PATCH] autofs: Fix memory leak in autofs_fill_super()
Date: Sat, 27 Dec 2025 08:25:05 +0800	[thread overview]
Message-ID: <c8a82305-1c55-4c21-b0e0-e19a6ef9b543@themaw.net> (raw)
In-Reply-To: <20251225142754.1114352-1-zilin@seu.edu.cn>

On 25/12/25 22:27, Zilin Guan wrote:
> The autofs_new_ino() function allocates a new autofs_info structure.
> If the subsequent call to autofs_get_inode() fails, this structure is
> not freed, leading to a memory leak.
>
> Fix this by adding a new error label to free the structure and jumping
> to it upon failure.
>
> While at it, consolidate the error handling for the d_make_root()
> failure case to use the same label.
>
> Fixes: 66917f85db600 ("autofs: add: new_inode check in autofs_fill_super()")
> Signed-off-by: Zilin Guan <zilin@seu.edu.cn>

Acked-by: Ian Kent <raven@themaw.net>


So obvious, one wonders how things like this go unseen for so long, ;)


Ian

> ---
>   fs/autofs/inode.c | 13 ++++++++-----
>   1 file changed, 8 insertions(+), 5 deletions(-)
>
> diff --git a/fs/autofs/inode.c b/fs/autofs/inode.c
> index b932b1719dfc..391979f8b2bb 100644
> --- a/fs/autofs/inode.c
> +++ b/fs/autofs/inode.c
> @@ -324,7 +324,7 @@ static int autofs_fill_super(struct super_block *s, struct fs_context *fc)
>   
>   	root_inode = autofs_get_inode(s, S_IFDIR | 0755);
>   	if (!root_inode)
> -		return -ENOMEM;
> +		goto nomem;
>   
>   	root_inode->i_uid = ctx->uid;
>   	root_inode->i_gid = ctx->gid;
> @@ -332,10 +332,9 @@ static int autofs_fill_super(struct super_block *s, struct fs_context *fc)
>   	root_inode->i_op = &autofs_dir_inode_operations;
>   
>   	s->s_root = d_make_root(root_inode);
> -	if (unlikely(!s->s_root)) {
> -		autofs_free_ino(ino);
> -		return -ENOMEM;
> -	}
> +	if (unlikely(!s->s_root))
> +		goto nomem;
> +
>   	s->s_root->d_fsdata = ino;
>   
>   	if (ctx->pgrp_set) {
> @@ -358,6 +357,10 @@ static int autofs_fill_super(struct super_block *s, struct fs_context *fc)
>   
>   	sbi->flags &= ~AUTOFS_SBI_CATATONIC;
>   	return 0;
> +
> +nomem:
> +	autofs_free_ino(ino);
> +	return -ENOMEM;
>   }
>   
>   /*

      reply	other threads:[~2025-12-27  0:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-25 14:27 Zilin Guan
2025-12-27  0:25 ` Ian Kent [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c8a82305-1c55-4c21-b0e0-e19a6ef9b543@themaw.net \
    --to=raven@themaw.net \
    --cc=autofs@vger.kernel.org \
    --cc=jianhao.xu@seu.edu.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=zilin@seu.edu.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®