From nobody Fri Dec 19 18:53:18 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42871ECAAA1 for ; Mon, 24 Oct 2022 13:46:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236407AbiJXNqf (ORCPT ); Mon, 24 Oct 2022 09:46:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236596AbiJXNoe (ORCPT ); Mon, 24 Oct 2022 09:44:34 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1812C42D79; Mon, 24 Oct 2022 05:40:18 -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 D367E61338; Mon, 24 Oct 2022 12:38:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D999CC433D6; Mon, 24 Oct 2022 12:38:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666615125; bh=MDg1xOq8ttq5QuNwnDZLKfIf0G3CaTF5t6oOlCMNYEk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BXJuHZ43muTOthssYfuMANEaj6/XjAzCUVBo5/wmsAOwgAt11poekB46JG75F7OSG PeRHq+opMslQqutMViRdAt5/xLYaWg2VFhs75XIR17KKg6PZHke96cM9ZO+CLpQDFR +zMezDkD+TWqtUE7ZUYK1oet3ZIZ+0lStGTd5NN4= 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 101/530] ext4: fix potential memory leak in ext4_fc_record_modified_inode() Date: Mon, 24 Oct 2022 13:27:25 +0200 Message-Id: <20221024113049.586155647@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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 @@ -1414,13 +1414,15 @@ static int ext4_fc_record_modified_inode if (state->fc_modified_inodes[i] =3D=3D ino) return 0; if (state->fc_modified_inodes_used =3D=3D state->fc_modified_inodes_size)= { - state->fc_modified_inodes =3D krealloc( - state->fc_modified_inodes, + int *fc_modified_inodes; + + fc_modified_inodes =3D 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 =3D fc_modified_inodes; state->fc_modified_inodes_size +=3D EXT4_FC_REPLAY_REALLOC_INCREMENT; }