From patchwork Sat Oct 22 07:20:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7214 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1090297wrr; Sat, 22 Oct 2022 00:46:29 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4x1Neu6ptmy70vUGwJ/3QRVFvJUBRzZzY6m94anuRkt+v560ibxrYwN5aGIJrT9bpLZ/e5 X-Received: by 2002:a17:90b:1d03:b0:212:cd82:aa0c with SMTP id on3-20020a17090b1d0300b00212cd82aa0cmr8070849pjb.214.1666424789633; Sat, 22 Oct 2022 00:46:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666424789; cv=none; d=google.com; s=arc-20160816; b=Fd2MUYXwXgHQ2UhnAH9i8ip7DnhJl4cOC6njRPW+YXWbhZ4Gd1DmuFAuJuFHPiSAy/ ajJa7P9Zgk4QddSpa5NzsSai34TNFD5NKQuDs09Dv5isoEr/JRB0dacWJYSxJFpIQ4qM k0qQiVA2wd0X+STdSjo4wU7BjR9w4R37Isubs+503UziuwLc4lc1ggdSY3v5P2nhUPc/ 4sa1bCnh5/ITZQKwt4M2noJ3SfokiVSBZrhk2q6KyTnHDbFzvPPBUFL0/uglJoEEwkPW p/6O5xNNrJ/jES185rL+iRCdmfsX6eRtpc7QnoJyplRXnMOCXDFYc5X8T9TwoUSBI3N9 8Cjw== 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=PUcsWTrkG6qWKJ7pq0f4FyyK8ZcqQ/5e8GalNCt8xrw3d3yNCniP/uSOiieaxAGbUz 7C1PveRXDNnOM+2i6HLrOFY8qF38hU4vvsXxXkaCpfiv14BLClpuCkxtr3ssKLlsfcUG 8bZeHnITehwy5FPzF32PEpsTkpO4wyHrTjKzvug3oNEsiPsyc8ubfJdp+LtcK98daLMu Sk9zNdsPrPSAE99HuThvOEIxwKqM8alEy1Sya4ykLZIuJd7EP28ihAutm7nqGrpbIRFy BHOY/u+VQ8v0plVJodHBRbfKKIdVwBuGbbB/WDpx3scbe3T4bOSNPkQ6Xau7/eL3Zv26 /sCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dSUy7VI6; 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 gk8-20020a17090b118800b00211780dcde8si7665609pjb.124.2022.10.22.00.46.17; Sat, 22 Oct 2022 00:46:29 -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=dSUy7VI6; 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 S231266AbiJVHqB (ORCPT + 99 others); Sat, 22 Oct 2022 03:46:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231394AbiJVHoF (ORCPT ); Sat, 22 Oct 2022 03:44:05 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47D41DD886; Sat, 22 Oct 2022 00:42:36 -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 ams.source.kernel.org (Postfix) with ESMTPS id 22CEEB82E07; Sat, 22 Oct 2022 07:41:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F789C433D7; Sat, 22 Oct 2022 07:41:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424487; bh=A/EfSodavLN3vkOq7yofx8nSRK5ew/SrXZ7YRPbEBvs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dSUy7VI6H0yeaa9ULhvNIvWPP6gman5pvBaKiOZwXVor+hQ6LCiO4f/65M6BT9Sk8 EE48Ds1Y5yp+9kw2KiNvhHFpOw+W6WlvSwm2619mCJt2cOA1Rw3bY7W+1tjIqyPw3e 5XEeyQl8/RP1sOFwFmx0lM6cArJ4SB0YJ7lmWGws= 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 134/717] ext4: fix potential memory leak in ext4_fc_record_modified_inode() Date: Sat, 22 Oct 2022 09:20:13 +0200 Message-Id: <20221022072439.237269256@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?1747373040436336991?= X-GMAIL-MSGID: =?utf-8?q?1747373040436336991?= 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; }