Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3929363rwi; Sat, 22 Oct 2022 02:23:41 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5TeRczKvtJbsSHr1FrN8iLHo48ylrRJwRWwaqo2ymThKYVK1dO6EtRIAL9jSMRbaKsZ5By X-Received: by 2002:a05:6a00:1406:b0:565:dc13:bb36 with SMTP id l6-20020a056a00140600b00565dc13bb36mr23891634pfu.46.1666430621567; Sat, 22 Oct 2022 02:23:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666430621; cv=none; d=google.com; s=arc-20160816; b=GGd55n9IazhiL/KPHzR7gxhVEfu3lV2o9VmRgfUB3X0LgPe+Z1tkDOKkH9I0jueV4c cYTeZZGqLAdWhExRLO0/wQcY49RKue3wzSvynCNNh8hDl0+JxpTPm6ByJhOgY50gSuvH MBEZ0oQI3+v56SCmEGnrHLIl5lPbkBomGFEJ4URyAdM0V56hmwIuapHgF9qd6zGLBGl7 5okgCqw3mrmnuabCVaDbS4mlr4fxyzFNRIgtDwmro/FncdHDM09Ffbb8c1+Bp69B5nsq /dRU0ViEECnfHJ9JUBavNTv1BhJEc8k3RYYkPvz9xuhnrNGB4oswHPgVBEiaz16ucZq4 A5gw== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t26-20020a63535a000000b0045ce0eba52esi30004146pgl.114.2022.10.22.02.23.29; Sat, 22 Oct 2022 02:23:41 -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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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; }