From patchwork Mon Oct 24 11:27:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9327 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp465917wru; Mon, 24 Oct 2022 06:53:44 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4WE+6JP8aqp800D3O8PZVXsSgmIQ4MGSiuy8yYoxEuIt6CgL7CYDLiQNWW1MOdaX0cJBjc X-Received: by 2002:a17:902:bd05:b0:179:bbad:acff with SMTP id p5-20020a170902bd0500b00179bbadacffmr32778388pls.170.1666619624652; Mon, 24 Oct 2022 06:53:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666619624; cv=none; d=google.com; s=arc-20160816; b=HC+07cRzFnzfa5qi9kgML+HfyrgeR+ou3F4MoN1uptJkKsuUsZ3UtrCQKR4peOgX/y cUclFhfAC8prvRzuxP4+ldnlpt8YAwubvBMme/kgZgmQJvVmD4u16R1DEz3/undv+I02 kABktIitY/ykcw+2n0hDLfMeuX1O3AFUFLvKCGNgaArnlsgo/LzPH2vIbuW0zWKNM+TH k+3yUygIhWfUQCReF+I/eVYpXWkANZ6sdxM19Hge9eX9uMEq1sjSfrvsXn/KeBtAsLjA H6HblFcROCedM0Mlc895QAmyoXif4p39ICKARnTQzNFGmNAEFg1N/FVMb2RSwHINyLmE bQpg== 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=b4+TV+wCNwRpacj+MYqkGWFLzMFP5DONKq4DljMQi54=; b=ZHFRnqBRdzFM1SlfbHiJxX3VbH0GNkGPU0sJPF3cMagr0uDoM1SsrKuz8ly8HY2r27 jkOAKT5MdMDKZGxwDU4q6WHSTQHIzjMEKuFEHXcktbGJxNyHnF7MEqxj8TddhST3ei+y nMQ09XMwFChwfImiyrVCieFrru0SQaIHkZexkJ/EHsKsceSC0IeTFM5AfjGUyrk3Qw8F M7YpbVz9sfYJIOmbXwJrtkUvSC3NXC+8aR1bxfIu5zRnoDV2zhdn1CGHK0GxI2dD7dvd o8wJWGrJ3NJIIUuqjJhLVFCA70GXbvXgnde09Yev4MRXQkkpB4JaaFOpjpg1w6OPq2Bk PyGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=i2XX613L; 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 bd12-20020a656e0c000000b0046b158da2d9si35703571pgb.528.2022.10.24.06.53.31; Mon, 24 Oct 2022 06:53:44 -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=i2XX613L; 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 S236682AbiJXNxM (ORCPT + 99 others); Mon, 24 Oct 2022 09:53:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236643AbiJXNwX (ORCPT ); Mon, 24 Oct 2022 09:52:23 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAA668D0E3; Mon, 24 Oct 2022 05:42:54 -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 6E66061344; Mon, 24 Oct 2022 12:38:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7D6E7C433C1; Mon, 24 Oct 2022 12:38:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666615127; bh=E2h8UncF2QUEYzm9k2NPq8+cmkeXB6sD0hO6MiWYObk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i2XX613L3r/EzkBV+pZoiVAmFYU5oiKM3GgYAwo7SDKm11Jj6+oa/eldLj8ErHOsG pG0KV95hjdRDePVsVZ8pMI1Nd1qL8oDfOX9Ehpm6Yxdx8m0xgC90wOgUO33JszC0Ez 2pR82sdhGzP9WilQ1V0j8kWjHotxoiOgppifNnEI= 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.15 102/530] ext4: fix potential memory leak in ext4_fc_record_regions() Date: Mon, 24 Oct 2022 13:27:26 +0200 Message-Id: <20221024113049.639852652@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113044.976326639@linuxfoundation.org> References: <20221024113044.976326639@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 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?1747577339763032005?= X-GMAIL-MSGID: =?utf-8?q?1747577339763032005?= 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 @@ -1607,15 +1607,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;