From: yebin <yebin10@huawei.com>
To: Damien Guibouret <damien.guibouret@partition-saving.com>,
<tytso@mit.edu>, <adilger.kernel@dilger.ca>,
<linux-ext4@vger.kernel.org>
Cc: <linux-kernel@vger.kernel.org>, <jack@suse.cz>
Subject: Re: [PATCH -next 1/2] ext4: fix potential memory leak in ext4_fc_record_regions()
Date: Tue, 20 Sep 2022 09:07:57 +0800 [thread overview]
Message-ID: <6329126D.8060704@huawei.com> (raw)
In-Reply-To: <02fc228b-7cc5-b470-9b5c-8ad726b18158@partition-saving.com>
On 2022/9/20 2:40, Damien Guibouret wrote:
> Hello,
>
> Le 19/09/2022 à 16:40, Ye Bin a écrit :
>> As krealloc may return NULL, in this case 'state->fc_regions' may not be
>> freed by krealloc, but 'state->fc_regions' already set NULL. Then will
>> lead to 'state->fc_regions' memory leak.
>>
>> Signed-off-by: Ye Bin <yebin10@huawei.com>
>> ---
>> fs/ext4/fast_commit.c | 14 ++++++++------
>> 1 file changed, 8 insertions(+), 6 deletions(-)
>>
>> diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c
>> index 9217a588afd1..cc8c8db075ba 100644
>> --- a/fs/ext4/fast_commit.c
>> +++ b/fs/ext4/fast_commit.c
>> @@ -1677,15 +1677,17 @@ int ext4_fc_record_regions(struct super_block
>> *sb, int ino,
>> if (replay && state->fc_regions_used != state->fc_regions_valid)
>> state->fc_regions_used = state->fc_regions_valid;
>> if (state->fc_regions_used == state->fc_regions_size) {
>> + struct ext4_fc_alloc_region *fc_regions;
>> +
>> state->fc_regions_size +=
>> EXT4_FC_REPLAY_REALLOC_INCREMENT;
>> - state->fc_regions = krealloc(
>> - state->fc_regions,
>> - state->fc_regions_size *
>> - sizeof(struct ext4_fc_alloc_region),
>> - GFP_KERNEL);
>> - if (!state->fc_regions)
>> + fc_regions = krealloc(state->fc_regions,
>> + state->fc_regions_size *
>> + sizeof(struct ext4_fc_alloc_region),
>> + GFP_KERNEL);
>> + if (!fc_regions)
>
> Would it not be safer to restore state->fc_regions_size to its
> previous value in that case to keep consistency between size value and
> allocated size (or to update state->fc_regions_size only after
> allocation as it is done in second part of this patch) ?
>
Actually, If 'ext4_fc_record_regions()' return -ENOMEM, then will stop
replay journal.
'state->fc_regions_size' will not be used any more, so it's safe.
>> return -ENOMEM;
>> + state->fc_regions = fc_regions;
>> }
>> region = &state->fc_regions[state->fc_regions_used++];
>> region->ino = ino;
>
> Regards,
>
> Damien
>
> .
>
next prev parent reply other threads:[~2022-09-20 1:08 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-19 14:40 [PATCH -next 0/2] Fix two potential memory leak Ye Bin
2022-09-19 14:40 ` [PATCH -next 1/2] ext4: fix potential memory leak in ext4_fc_record_regions() Ye Bin
2022-09-19 15:26 ` Jan Kara
2022-09-19 18:40 ` Damien Guibouret
2022-09-20 1:07 ` yebin [this message]
2022-09-20 18:25 ` Damien Guibouret
2022-09-21 1:26 ` yebin
2022-09-19 14:40 ` [PATCH -next 2/2] ext4: fix potential memory leak in ext4_fc_record_modified_inode() Ye Bin
2022-09-19 15:26 ` Jan Kara
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=6329126D.8060704@huawei.com \
--to=yebin10@huawei.com \
--cc=adilger.kernel@dilger.ca \
--cc=damien.guibouret@partition-saving.com \
--cc=jack@suse.cz \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.