From patchwork Wed Oct 19 08:23:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 5539 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp348466wrs; Wed, 19 Oct 2022 07:10:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6VlB2Go8dBBcnLO+XHh4iujFXpGUyMfdZP0t7+uIs0JG4x0LMhB06tQy0Fyb0eH2bX+aQN X-Received: by 2002:a05:6402:148a:b0:459:2eab:9b0a with SMTP id e10-20020a056402148a00b004592eab9b0amr7593059edv.139.1666188609839; Wed, 19 Oct 2022 07:10:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666188609; cv=none; d=google.com; s=arc-20160816; b=jrDXDoTtrx3ljNtTci4xSxWClLV4JPdUqxOaHTXHxpiw8/WgYRY2nzS6DOnhHAVsik 1d2zUi4+KSG4SXAlU+A1ZudDn/8YyBZ1QLcP38eNUmbkv7NupHBBONsQDQGeVs1by9xZ tu0IFY/fRlgOOS3n/kgZBPTOGTBVtOSH4qAPiPM8VIZl/6dXYHmV5045GUhVU2EFG4IC m/f67VtahJqlb1MgelGnnyf3xnVmUzLZtgtbkRs3Woa95Q1ZTJhA/t3mKCm6rtZkG7BR HlI8MeB05Loyh5T9Lf/XLfID6zPkg60jLnjxI447z6aDQk/TCGTUeUUuE+iOPrwzVeYy hAwA== 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=MtZArkGlv5buEWRZ/YUpKagsJinPtiWhFfZbrZL4mb8=; b=i5WY00VTrn0mOqyMTWPRiJeLP4A70r16216p2xLHaNtbKtHL3Ah4RuQ5HFuOEknFOA XG0eq096Qy4h2yoxpvSOTji9EYLzY0iWbt9V0HwBmgar4N6hwLEcVpzFML7Z1tVjIJqQ AA7EW4UsY729CQgWCefWTrLjbys7j6XnE1EM1SaqAwv7g1a+JutRTJuhVvJ1WFwBRi1Q 5SyJ3kUFKS7JX2w4hSasYKNkM4JP5c6G6WhuSaFDg3pW0qIOxU8/NKPy8xQsxBiBV5Oi TneyGnbj1cB0qR70/RA0R9M5xq2hvaPHgpKKUDs4Y7WQ7yfaADtiwB4u2oDTa+rE7uA+ r7Rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lmFJOuNb; 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 g14-20020a1709065d0e00b0078219af8361si13662319ejt.883.2022.10.19.07.09.38; Wed, 19 Oct 2022 07:10:09 -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=lmFJOuNb; 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 S233752AbiJSNwh (ORCPT + 99 others); Wed, 19 Oct 2022 09:52:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233723AbiJSNwD (ORCPT ); Wed, 19 Oct 2022 09:52:03 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73526189C34; Wed, 19 Oct 2022 06:35:43 -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 sin.source.kernel.org (Postfix) with ESMTPS id 5E322CE20F4; Wed, 19 Oct 2022 08:44:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 616C5C433C1; Wed, 19 Oct 2022 08:44:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666169066; bh=A/EfSodavLN3vkOq7yofx8nSRK5ew/SrXZ7YRPbEBvs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lmFJOuNbjmgXpeVt8U9PFNh2MBqNlpjqhi1twmiCrsgYmDg5WucjA4KM4tFzIx3HU JA4TjmklN0usltLI5enZ3s5FNQe5LSIwBKmaAmUSJW1UozjsOqRGHq7Ud20W4Vxc4I embrhulrCr6FYBPvOusUdNqw9XqfwpzMSr3ft82M= 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 6.0 146/862] ext4: fix potential memory leak in ext4_fc_record_modified_inode() Date: Wed, 19 Oct 2022 10:23:53 +0200 Message-Id: <20221019083256.438343884@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 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?1747125387915087205?= X-GMAIL-MSGID: =?utf-8?q?1747125387915087205?= From: Ye Bin commit 9305721a309fa1bd7c194e0d4a2335bf3b29dca4 upstream. 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. Cc: stable@kernel.org Signed-off-by: Ye Bin Reviewed-by: Jan Kara Link: https://lore.kernel.org/r/20220921064040.3693255-2-yebin10@huawei.com Signed-off-by: Theodore Ts'o Signed-off-by: Greg Kroah-Hartman --- fs/ext4/fast_commit.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -1494,13 +1494,15 @@ static int ext4_fc_record_modified_inode 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; }