From patchwork Sat Oct 22 07:20:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7358 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1095586wrr; Sat, 22 Oct 2022 01:03:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5cFhyNfqEdTPRv3pT/I2QexTDNdvLAdsqFK8XFjEqoQejsasE9rgOPe+50dflvf/NJIHTJ X-Received: by 2002:a17:903:2351:b0:181:68a8:9f9c with SMTP id c17-20020a170903235100b0018168a89f9cmr23312058plh.115.1666425783493; Sat, 22 Oct 2022 01:03:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666425783; cv=none; d=google.com; s=arc-20160816; b=UsxqeZZ2ZtARVHH6EVEOhw83plS/jy7SruYxgym1oz5TNF7EiI/6kw40be93sI1r0t QUhT2znGr3zKwZ+mYveJRYVj44MiaK9MnDy37v/nxkw2Vj8Th5kRUSUMhkJ3cd811nNk /pjdlGo+RfgkDGI8a7f4GVFKbtoZPrIY05BGOAqzRxZF3zfedc3/ZnjWqM9Yfu6USzmU Azu90NV/5iPrf9GO1RqJaXfLgjTxH4OtD/vIa7u0FSXGdLkXcy8Qo0W1dmMy3rlrBCfZ xM0gh12en3Btlf4DeFS3AJFPz/alaA9sNarg4QCY0jZm7rCtjEA9+pTGeXLhWp070yqg MC4Q== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=r+Q/URr8hJeUs+c7Md1YfY+258tj0MaGOnHuf0dUwdY=; b=MTSkU0rxwjaNICrrA63cNWBiUBqUR8SPZAcSZ6WVI9I7yNpnaWQrSxkob624/R+CaL UC+0BvD8YGQ48QI3HFKTvBYfZ9SmgqXLL+EXDYtO54R51OLJbyCc4O7AMGmCvBqYQN8l zYykUv+zIG11VehmX8yeiwZUz38LbDlLJsGuvAHTThUtkaH0lvF5XMbSXkV7j9l2etJH 2WuOUb4k5FtHg1BJot81QcNMvA9FaY25K1MbHLJNe7BZxCbnD8Qfs5zrSMbZFfDhimme rMV5HDkUlV2T7KSfjH+TDA/+ISfsdi8qpRB9WhzpQdnMz9oAs6yKlm4PclUtSkq2p2tW RkxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bDDd90nn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m6-20020a056a00164600b0055fe250267dsi23857808pfc.124.2022.10.22.01.02.50; Sat, 22 Oct 2022 01:03:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bDDd90nn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232574AbiJVICc (ORCPT + 99 others); Sat, 22 Oct 2022 04:02:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232316AbiJVHyj (ORCPT ); Sat, 22 Oct 2022 03:54:39 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D500DD6B92; Sat, 22 Oct 2022 00:48:00 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0716B60B88; Sat, 22 Oct 2022 07:41:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1DB8EC433D6; Sat, 22 Oct 2022 07:41:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424490; bh=H2f0utUE260eE+Vd88zICS6WI0lF7gGGbPGRjwWNoew=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bDDd90nnDTW3/93qJyiTSm7JiLWZPdxwBW3oiSSCLyAhMmEp7SmMS5CDidBRT7EJG jrXIVSqnwZVAba4PNSpORIoKdhav0mZS4ZvY6HxMD7JMseHys1icBoUbHxF9xjwDrQ I7/PXqQF0bnqshJAX9jmXq0a78+IGhnSw40xq7z4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, stable@kernel.org, Ye Bin , Jan Kara , Theodore Tso Subject: [PATCH 5.19 135/717] ext4: fix potential memory leak in ext4_fc_record_regions() Date: Sat, 22 Oct 2022 09:20:14 +0200 Message-Id: <20221022072439.424419076@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747374082628472688?= X-GMAIL-MSGID: =?utf-8?q?1747374082628472688?= From: Ye Bin commit 7069d105c1f15c442b68af43f7fde784f3126739 upstream. 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. Cc: stable@kernel.org Signed-off-by: Ye Bin Reviewed-by: Jan Kara Link: https://lore.kernel.org/r/20220921064040.3693255-3-yebin10@huawei.com Signed-off-by: Theodore Ts'o Signed-off-by: Greg Kroah-Hartman --- fs/ext4/fast_commit.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -1687,15 +1687,17 @@ int ext4_fc_record_regions(struct super_ 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) return -ENOMEM; + state->fc_regions = fc_regions; } region = &state->fc_regions[state->fc_regions_used++]; region->ino = ino;