mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Dinghao Liu <dinghao.liu@zju.edu.cn>
Cc: kjlu@umn.edu, Theodore Ts'o <tytso@mit.edu>,
	Andreas Dilger <adilger.kernel@dilger.ca>,
	linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ext4: Fix memleak in add_new_gdb
Date: Fri, 28 Aug 2020 11:21:19 +0200	[thread overview]
Message-ID: <20200828092119.GE7072@quack2.suse.cz> (raw)
In-Reply-To: <20200827062843.10188-1-dinghao.liu@zju.edu.cn>

On Thu 27-08-20 14:28:43, Dinghao Liu wrote:
> When ext4_journal_get_write_access() fails, we should release
> n_group_desc, iloc.bh, dind and gdb_bh to prevent memleak.
> It's the same when ext4_handle_dirty_super() fails, but we
> don't need to release dind here because it has been released
> before.
> 
> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>

Thanks for the patch! Some comments below:

> diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
> index a50b51270ea9..efc0a022ca8e 100644
> --- a/fs/ext4/resize.c
> +++ b/fs/ext4/resize.c
> @@ -843,8 +843,10 @@ static int add_new_gdb(handle_t *handle, struct inode *inode,
>  
>  	BUFFER_TRACE(dind, "get_write_access");
>  	err = ext4_journal_get_write_access(handle, dind);
> -	if (unlikely(err))
> +	if (unlikely(err)) {
>  		ext4_std_error(sb, err);
> +		goto errout;
> +	}

This hunk looks good.

> @@ -899,13 +901,17 @@ static int add_new_gdb(handle_t *handle, struct inode *inode,
>  
>  	le16_add_cpu(&es->s_reserved_gdt_blocks, -1);
>  	err = ext4_handle_dirty_super(handle, sb);
> -	if (err)
> +	if (err) {
>  		ext4_std_error(sb, err);
> +		goto errsuper;
> +	}
> +
>  	return err;
>  errout:
> +	brelse(dind);
> +errsuper:

But this is definitely wrong. Look, n_group_desc and gdb_bh are already
referenced from the superblock so you cannot free them, iloc.bh has been
released in ext4_mark_iloc_dirty().

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

  reply	other threads:[~2020-08-28  9:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-27  6:28 Dinghao Liu
2020-08-28  9:21 ` Jan Kara [this message]
2020-08-29  2:32   ` dinghao.liu

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=20200828092119.GE7072@quack2.suse.cz \
    --to=jack@suse.cz \
    --cc=adilger.kernel@dilger.ca \
    --cc=dinghao.liu@zju.edu.cn \
    --cc=kjlu@umn.edu \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tytso@mit.edu \
    /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®