From patchwork Mon Oct 24 11:27:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9023 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp441419wru; Mon, 24 Oct 2022 06:05:53 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7TRcz7OO3c2wMeIorNsJNPSusj+RSEOE52q7FkB9kNGrInB+jDa6ZsK3UksaF5mf8odLwf X-Received: by 2002:a17:90b:1bc9:b0:20d:b990:5028 with SMTP id oa9-20020a17090b1bc900b0020db9905028mr63050353pjb.111.1666616753477; Mon, 24 Oct 2022 06:05:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666616753; cv=none; d=google.com; s=arc-20160816; b=w07d0TBhWUN4cSqILBwRjJuZW8Bor1F9R8SGZpW95Sq0EP4i7fteiDme9lSsjy9DRg oMwHvyTWMjZjFFfnxH3nWm2DLaMwfa3JUkms9576oTu1c8iWsLXPW3fC+IgsqV1mroFQ TgMOwm3iPOgBP4MLiJwf/FzeTtKbCYOAbF1ZUD02asQXDC3FX99Y5btekb1BHE0G2PX1 eDNNho9izlzCIdfwnD9BJs4XqOdaXFOo5DCOCys9HANyBA5sAlEoIX4p6J5QTnF/lAxg ufDRF5hxMjIrcVfB5X1QIG8Ge7kfl5Kgq7JAT1dC1J7+WeinuWRPNpgmxFk0DrIk8SDm IGVQ== 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=KbWh7xYV5wvMCDK/R9glIU9iwkurd9EL1YCngka/RDs=; b=IcybSnCP0JF5/rc1gK3cwLfsYqr6Oiia35wV0WHHHa826Li5Cy76UZYwjEwFZeNc/p suuCk34tO8HNTfTV+TvOVmMKcBO05Aoc3Y1Qzubwy0Fr4qMTt5T5mEGLmBhxlVfbFvzJ mJBEdpV33QADwOPACU2Z9rJ5miwu72alxmoo99qciTD7/N2HuKdf3V7AWty7G8ijGrmH Kienx6JPwuMy4tkHla7cgwAQvkDISinrMV7i7AQfnDKnuTis25uZKEbHsgG4A3AW2RZ/ 1ARs0+FUDwDODC7qSXz2CxUtfy9dw8mw4EiZfYh7ULTVRYQbQC9quw+riJfIt3kAZqOM h/6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CwnfWVmV; 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 p16-20020a170902e75000b00161739962ffsi37392829plf.163.2022.10.24.06.05.30; Mon, 24 Oct 2022 06:05:53 -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=CwnfWVmV; 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 S235468AbiJXNEx (ORCPT + 99 others); Mon, 24 Oct 2022 09:04:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235114AbiJXNBZ (ORCPT ); Mon, 24 Oct 2022 09:01:25 -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 173AC2CDDB; Mon, 24 Oct 2022 05:19:57 -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 025EA61014; Mon, 24 Oct 2022 12:18:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 151DEC433C1; Mon, 24 Oct 2022 12:18:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613934; bh=vRZRcG52HvItJnHU8ZwO+iF8jCky5QMMnaeL1wxRTTc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CwnfWVmV3EUJXUqlXg5zrjhLrj5q2yZJOEAgUo1IlbqqeGBej5QNE0uIh5jQKGtjH L5gMt6w3qDq7Shv++iJtiwSXsKIKD9ZzHAP6r3PJqzyxQ7fVmj4416qFJ3uyJhNMNT ZkeTsfKBs7z+kcCKaOF7pjqMIvTkXovz8YNyMcSc= 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 069/390] ext4: fix potential memory leak in ext4_fc_record_regions() Date: Mon, 24 Oct 2022 13:27:46 +0200 Message-Id: <20221024113025.529118096@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?1747574328626684955?= X-GMAIL-MSGID: =?utf-8?q?1747574328626684955?= 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 @@ -1584,15 +1584,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;