Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2205414iof; Tue, 7 Jun 2022 23:09:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyRbVx6cwdr3VdwfgftznubCgWJ/vSPN6fbjiqYJk3Nu5pZbMtlCs7GrmfdHz0JB26/HPtO X-Received: by 2002:a17:902:ab8c:b0:167:4d5c:3542 with SMTP id f12-20020a170902ab8c00b001674d5c3542mr24374611plr.6.1654668592889; Tue, 07 Jun 2022 23:09:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654668592; cv=none; d=google.com; s=arc-20160816; b=ple00DuFAjMDGH7rvJ98qSMOU4yPXPkDcC7Ov4KWytpaupNaMv1XFrxk4TW+OHJ+P8 OxTjM0yEoS/FOewukmOgblL1JuhcaoL54ucfSrFTKLTYqq7fkjHtj5FkWflrh1IfKe8C z8Vnmt1zlCDUHfdc6VTyhnCWM1zb36HMPYvPdTQE5kaSMhNtNsctzKBIJqnDuyJ8nLEB sogpBkJEp6F+RaGoC8mg0O91bNta9OVfJO+KjFdlv5/PkHK1dHcXAznsuEEy5LZPda6T f8cQf80PYvqFbdSjOzy5qLa3Tih5pNdEe9LpAxSLRxvQIagIxeUlgfPBm28JXkKQ9NxY z9AQ== 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=MVvy6Yz7icmcpud5fy8a5t+1R7DhrQ14jEO0e+n3jC8=; b=AFxHl/MkBBD6BUvDX/NmlNIajeS/aJt8swB9BEmHpiov9OuigpeRB6/1ahl2dKBe4Z W3YCQqc9jcOswdByZOYhxUYGqCgmzEmySovCIZ9HXiO0m+1qYFvcZ6e4NhOvjuluKO9T 90RorGVrEhxKekucQnBJPeNZjPNRd8qFbxk08PjphUufFxaoNDb3apA5l8TFN0Pv19M3 HPTpMn/LKYkhXMzTduRoy3RVYFKrRUMjT27ZorGtJdstXBETtPKVpAKuBHP3nWXeDG3e CiqDbiIP+hg27eOOzVDE4B5tUDbG1JMw8NLb6c/bLOdutEA3mWeEu2KiHJ7+j89Inpyz iiPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wbqViWYb; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id n7-20020a17090ac68700b001df53d6dbc7si29384948pjt.117.2022.06.07.23.09.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 23:09:52 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wbqViWYb; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 72B9928CE8E; Tue, 7 Jun 2022 22:32:16 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377167AbiFHBfF (ORCPT + 99 others); Tue, 7 Jun 2022 21:35:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353209AbiFGWM4 (ORCPT ); Tue, 7 Jun 2022 18:12:56 -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 C465F25D5E3; Tue, 7 Jun 2022 12:19:37 -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 7E7B661929; Tue, 7 Jun 2022 19:19:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E182C385A2; Tue, 7 Jun 2022 19:19:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654629576; bh=I/AxesGm+UuH/LfTjxhIW+yj0CyrQKwGuT/W633gWPQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wbqViWYb9tLy7QAPvZbPu1Z175C0NLltnVvD89gvduqiLLoWBuUMWhPfb/in3MQnL OGp/MdXOk3Ecm6x7gqZcxXVvkzWDrpnjHTgPklNTVmkZ8UP2AHqA+wZ32RvQgwO/Fd hfXXjwHUo9u3f8smBwZTAb7brqY2ckHMAnGITAJU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Biggers , Ritesh Harjani , Theodore Tso Subject: [PATCH 5.18 741/879] ext4: fix memory leak in parse_apply_sb_mount_options() Date: Tue, 7 Jun 2022 19:04:19 +0200 Message-Id: <20220607165024.366221861@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: Eric Biggers commit c069db76ed7b681c69159f44be96d2137e9ca989 upstream. If processing the on-disk mount options fails after any memory was allocated in the ext4_fs_context, e.g. s_qf_names, then this memory is leaked. Fix this by calling ext4_fc_free() instead of kfree() directly. Reproducer: mkfs.ext4 -F /dev/vdc tune2fs /dev/vdc -E mount_opts=usrjquota=file echo clear > /sys/kernel/debug/kmemleak mount /dev/vdc /vdc echo scan > /sys/kernel/debug/kmemleak sleep 5 echo scan > /sys/kernel/debug/kmemleak cat /sys/kernel/debug/kmemleak Fixes: 7edfd85b1ffd ("ext4: Completely separate options parsing and sb setup") Cc: stable@vger.kernel.org Signed-off-by: Eric Biggers Tested-by: Ritesh Harjani Link: https://lore.kernel.org/r/20220513231605.175121-2-ebiggers@kernel.org Signed-off-by: Theodore Ts'o Signed-off-by: Greg Kroah-Hartman --- fs/ext4/super.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -2626,8 +2626,10 @@ parse_failed: ret = ext4_apply_options(fc, sb); out_free: - kfree(s_ctx); - kfree(fc); + if (fc) { + ext4_fc_free(fc); + kfree(fc); + } kfree(s_mount_opts); return ret; }