From patchwork Wed Oct 19 08:23:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 4599 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp206406wrs; Wed, 19 Oct 2022 01:52:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5f0HHqL8lTMFXq/mtJYzYuKlyDYoH096VyYWunH0tOQU0vI5KsOfEB+xYAcq0k5EcEOU+N X-Received: by 2002:a05:6a00:124d:b0:566:8645:dad2 with SMTP id u13-20020a056a00124d00b005668645dad2mr7703436pfi.5.1666169542337; Wed, 19 Oct 2022 01:52:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666169542; cv=none; d=google.com; s=arc-20160816; b=q6hd9+Xn5/F2si0lLKEUsNPxRHhkn/PzmorfYXQOoCn9S63ruxVhh1zo6Xka/gx92p AG1ZvYhzpBisjJwlTkeTaxvC6gUZn1ATOenibwfYqObfk6ACOHq3eMS9kBaLSa1lRPhG P6XteHE9t9ebOwN6Ev8n0K8YuCRi8rzfXND8keq26kwu5DXcPzxLk5tc4EoWNeHkVSFR yHmsISZIAn4SgOy+eXKjNKsCoCEVFXoR1kgab7IbHC6QNz6FcIqHoMKAYPRZlSsgC1j8 1kjhyd+RPmII5XJMB8SN9TOh+b0+HMpIw/XSAR2MJUZvZJCDVmc0d2Zf6O2ilR59/8BA rJdQ== 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=xViorNA1In9h73vMDM+KXt4j/dEgjo6SzadjNeBlAAz4fq37pFWsEIjP9C47fKIDvz ALThfHttUdXjDh3DzAmk4QmRJTATcg5fnvCtz629z8sY+WTQI/ZXl8XzBnCOUmQb+zpd 5IGryL71q4NRH31xuw0DWRQluJa1fzLSnM+QnXookD72NXcPFDMwBWl3w9664deeKx0d 1wY5wxVbLdr3yhyiLdL8REUldfdp5k689myq3ai1V3wv8bfJX9zmufwJI7PKr2/Tnd8t TvXJ1zjUk3LWfctgfryY22KB81OQUz9cffEP5pzD+/ebxXqivgIBnU0cBMnyHGkWP764 hzpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="kc/ZFTGT"; 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 j7-20020a056a00174700b005660f2c4b27si18633043pfc.274.2022.10.19.01.52.10; Wed, 19 Oct 2022 01:52:22 -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="kc/ZFTGT"; 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 S231715AbiJSIvn (ORCPT + 99 others); Wed, 19 Oct 2022 04:51:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231888AbiJSItt (ORCPT ); Wed, 19 Oct 2022 04:49:49 -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 D1CBC89CFB; Wed, 19 Oct 2022 01:48:01 -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 73C2C61805; Wed, 19 Oct 2022 08:44:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 73C99C433D6; Wed, 19 Oct 2022 08:44:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666169069; bh=H2f0utUE260eE+Vd88zICS6WI0lF7gGGbPGRjwWNoew=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kc/ZFTGTfghIZgblZew14UZ6RyuxX/LvsPhRg2U7V0BbV8qcVSIVYc2VvkG2GjMhk +5D9DmGsgwNLxpeneZaTW1pxMLgWiZbHFK1E6br2eQk1TnN9brgkUVts4lbFlM9YD3 ykqfldsQUAD6Y99yYFekQDPEhHpO8kKTM4dCpJZ4= 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 147/862] ext4: fix potential memory leak in ext4_fc_record_regions() Date: Wed, 19 Oct 2022 10:23:54 +0200 Message-Id: <20221019083256.486598993@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?1747105394328005829?= X-GMAIL-MSGID: =?utf-8?q?1747105394328005829?= 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;