From: Damien Guibouret <damien.guibouret@partition-saving.com>
To: yebin <yebin10@huawei.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 20:25:59 +0200 [thread overview]
Message-ID: <d49a38ed-5523-8339-e1e8-d52b0ab41fdf@partition-saving.com> (raw)
In-Reply-To: <6329126D.8060704@huawei.com>
Hello,
Le 20/09/2022 à 03:07, yebin a écrit :
>
>
> 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.
There are at least two calls in ext4_ext_clear_bb (ext4/extents.c) that
do not check for return code of ext4_fc_record_regions. But perhaps
these are these calls that should be fixed.
>>> 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 18:26 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
2022-09-20 18:25 ` Damien Guibouret [this message]
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=d49a38ed-5523-8339-e1e8-d52b0ab41fdf@partition-saving.com \
--to=damien.guibouret@partition-saving.com \
--cc=adilger.kernel@dilger.ca \
--cc=jack@suse.cz \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tytso@mit.edu \
--cc=yebin10@huawei.com \
/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®