Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp4898361rwb; Tue, 20 Sep 2022 23:33:43 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4YtRmPwwZXSkKzcRd6BNfQU1e6R92XANXnHeQ9MTJSi5SwOAG3dI2jf29hHLFDscu40mnk X-Received: by 2002:a63:8ac9:0:b0:435:783:ee5d with SMTP id y192-20020a638ac9000000b004350783ee5dmr24384369pgd.77.1663742023081; Tue, 20 Sep 2022 23:33:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663742023; cv=none; d=google.com; s=arc-20160816; b=zv6N4bxc4HqO6cTo0mjOFzWALrCQ3UoaXDj1zBFld3Q2Fid2o3S5SvPpD+lw+dA5fF myHPbiAISTzdYqg2SfuFBf2ht7rfXchSX/Wb6qZAY566nXmo7UyCoSFkUsqZ05Y1swzy 0r3Voe9rPXtxc2fAQx/HJNmx+i6Wa6Pw3mRD21h9OU7oAgutZKWxSCSQpFxoFAFl8qIi xHIF6cDRqcvE6G9s26iwLNaZHv2PsXMEHRX+TD8BuOx3dLO55+dZa6F+z0cvVDk5Bs1/ h4kumU6TkSxgRR3W6KhdDhd+Zue3Uc2um1ZMbv/XoMQAuZezTgxMYasyTtpoPFjQT5/M OiVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=bBT/TRASLCcaX7L2p/quqzsyhHKixSyFG+rFKs1YAK0=; b=JXUeow52sNNDV6wz7+RzqtZV3lPWMhyM5pGEcbIfwchuLJ0+09hIBOjBJTKt1oU9l0 G6MBF1jPLgNk5zZIcwmbuXcpd3xJKoHBy+PnczFC1f6Kte4i/jADfx1tBv9JKwRNDdsf PE9N/uHa6IqnM0AfDw3ACsPs7Aacgg0D8r7GX3pKxBXm7b78tH7RfEU9BKZ4sGrVH4X9 BaQ7SLZa8KOq2K/SAMCl0+kaeSFydHxUuP6Q0q8kNtxUkiMYrl3vYEJSWHBlRQvCNVmZ sDnEF03p9dDd7psqt7HjYHGCrLBSvjjxDpUI4EyEGaWJ9OkoICZ9hfpwfhNDuwK4I3mN F+Og== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s32-20020a634520000000b00438fa5ecea2si2135365pga.255.2022.09.20.23.33.30; Tue, 20 Sep 2022 23:33:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229635AbiIUG35 (ORCPT + 99 others); Wed, 21 Sep 2022 02:29:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229624AbiIUG3z (ORCPT ); Wed, 21 Sep 2022 02:29:55 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68C541583D; Tue, 20 Sep 2022 23:29:54 -0700 (PDT) Received: from canpemm500010.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MXT125Y7RzMnGM; Wed, 21 Sep 2022 14:25:10 +0800 (CST) Received: from huawei.com (10.175.127.227) by canpemm500010.china.huawei.com (7.192.105.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 21 Sep 2022 14:29:51 +0800 From: Ye Bin To: , , CC: , , Ye Bin Subject: [PATCH -next v2 1/3] ext4: fix potential memory leak in ext4_fc_record_modified_inode() Date: Wed, 21 Sep 2022 14:40:38 +0800 Message-ID: <20220921064040.3693255-2-yebin10@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220921064040.3693255-1-yebin10@huawei.com> References: <20220921064040.3693255-1-yebin10@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To canpemm500010.china.huawei.com (7.192.105.118) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org As krealloc may return NULL, in this case 'state->fc_modified_inodes' may not be freed by krealloc, but 'state->fc_modified_inodes' already set NULL. Then will lead to 'state->fc_modified_inodes' memory leak. Signed-off-by: Ye Bin --- fs/ext4/fast_commit.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index 88575f3d0dc5..29a22ee0adb8 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -1486,13 +1486,15 @@ static int ext4_fc_record_modified_inode(struct super_block *sb, int ino) if (state->fc_modified_inodes[i] == ino) return 0; if (state->fc_modified_inodes_used == state->fc_modified_inodes_size) { - state->fc_modified_inodes = krealloc( - state->fc_modified_inodes, + int *fc_modified_inodes; + + fc_modified_inodes = krealloc(state->fc_modified_inodes, sizeof(int) * (state->fc_modified_inodes_size + EXT4_FC_REPLAY_REALLOC_INCREMENT), GFP_KERNEL); - if (!state->fc_modified_inodes) + if (!fc_modified_inodes) return -ENOMEM; + state->fc_modified_inodes = fc_modified_inodes; state->fc_modified_inodes_size += EXT4_FC_REPLAY_REALLOC_INCREMENT; } -- 2.31.1