From patchwork Mon Oct 24 11:27:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9679 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp535522wru; Mon, 24 Oct 2022 09:13:05 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5//JOP28jom6BfqUkzslxnncnI4FXjmKy1Vkbb13Zve7pECGmPU33It+E1UgZdjvjkXDtt X-Received: by 2002:a63:b5d:0:b0:45f:d7d0:5808 with SMTP id a29-20020a630b5d000000b0045fd7d05808mr28422639pgl.330.1666627985462; Mon, 24 Oct 2022 09:13:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666627985; cv=none; d=google.com; s=arc-20160816; b=YZFpjC3DN4tH42PPUYNlyQN8woTylASmJmYsIZWpHNNmZzpuo+4znIoEE5XYNd1bVl KkwhbLjDHZVEvy62S4uoOjLSN5movoI/CFQNdVL2OSAbfBsq8XqOF6r1worjCx8TXCYN jLdI9AGdiWbfyjHBYexSeJBo9USFH27rZjLKwbT6UC0hzYTt8IYqw1+PfyuoMIZy+w8w mlCD/Hu43B4aWcyvTA6VQdFY2z55I5Ue7Gy3xxDeePB7VzdOiiD4w0RXQXjdWrWLtS3T sVXzVwt4iN8+AIQVrooPpz0uuLzXzRv4yCPFzXXIPBu9cz8zcg3rUy0cZ+zuNYwL972W l44g== 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=h847raATzme5uJXVNwT5pENdfBtw44WO7ne0H0gAFCs=; b=WY3OLn42/jUKc9qV+Ujg8KNgscVLLAMRefDr/v8AuwizSPOxJfzVQCASapL+Q3mVoE Xbw6nQxd3/OYbuM8ataG8jdSEplzJb/ZuDbEHk6YQaVi38w51Fnzz46ICAycNHY3V3v9 o27mRmZny3j92CBCem2I3YgYzgbfZHafRYpABf3llxHwxPPW8DUONF2+CInz0+QJ+FPB pier+azZJy1RvZsTRgoyGK//ekpqmrSkD2PUov7cWdoEpDz73ezfU0Cpoc6ub/fxTHVN ALLBSkK1GOhg0u/DkizxylMjf/dqPgEbd4Rb/xQ8I2YvOX3klrcdcEk39Ybe9EXyQC56 iyRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=reliQMNp; 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 y40-20020a056a001ca800b0056baa6cfd49si7789pfw.332.2022.10.24.09.12.51; Mon, 24 Oct 2022 09:13:05 -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=reliQMNp; 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 S233887AbiJXQMM (ORCPT + 99 others); Mon, 24 Oct 2022 12:12:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232783AbiJXQFa (ORCPT ); Mon, 24 Oct 2022 12:05:30 -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 7236065A2; Mon, 24 Oct 2022 07:58:30 -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 1B540B8163C; Mon, 24 Oct 2022 12:18:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 77FF8C433D7; Mon, 24 Oct 2022 12:18:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613931; bh=LPRtJd9WOtczlaBhoc6jlt3gikaryNM1+Qp05AfSWsY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=reliQMNpPYzp8SXr7Kb/sSxPBapoYMMs8wbuPqjcpVmGY9reFjW5o6nhsp68fmOMp MnJ001Kvtl+OpE6bBj6WkKklRG5YXyAP8J3GPFmy8BYTTj7CoSNguR6pbnrT5rEipx 9H/AEvSQv0DQN7/Qf91E+NiltoYTePoxLbu1BX68= 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.10 068/390] ext4: fix potential memory leak in ext4_fc_record_modified_inode() Date: Mon, 24 Oct 2022 13:27:45 +0200 Message-Id: <20221024113025.497311766@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113022.510008560@linuxfoundation.org> References: <20221024113022.510008560@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?1747586106918840655?= X-GMAIL-MSGID: =?utf-8?q?1747586106918840655?= 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 @@ -1391,13 +1391,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; }