Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1015147iob; Fri, 13 May 2022 19:42:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwGgMj3Q9FOZGNgfuYGt0Phs/A+5OPN3KATADy2v/i1vWFDGm69uOXTfQAZHTMcnleTR8JW X-Received: by 2002:a5d:598c:0:b0:20c:6912:6870 with SMTP id n12-20020a5d598c000000b0020c69126870mr5971375wri.465.1652496150590; Fri, 13 May 2022 19:42:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652496150; cv=none; d=google.com; s=arc-20160816; b=PHfcAtJ4MRy30z6fPZJ6SC7W5ocf0k2UGCXzMTRnih79Qwzdn454HDg/c2M3d5YM+V tVjrSpJzB+w1BixagYjh+pPq7kbHlC5gwPWbQd6fm6tHTc4yYg+Ih2YAQ/AXlwl/3KwO 7XH9QhhG9JWnoovXsca1x+ZbVzgtP9zB8gkgawyczUPKbGYmB/uH3fawxShjcG/MqeJX HeijGnVyEG+2WaeDIzsmCEipCUSccXnVXiJM8woZUU8RXU/x8ZdQjPjoDAEsFPpbmhvL 1YST/Y+C2u+Ilau9rm4wJQ9Zq0BUBj05Tj/QSvF4VREdgIE3jfi3QcYtbxC8/rHtdBR2 dIRg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mzjFt3Uep6ZHt+0RJxUADGXLsQOpJNCPf4KdRrjArVE=; b=yJNjA7MiIgtVAYumrklmpiNIuGjCyb7+A1VEd0R4w7FdnebIO5FzGpTu+dq3+F4eCl hG9dlEjtq2FyRuKEGqrSY8Xr/NgX7ZVVdfhPmfzOZA1ZWo4LLmvKHePzUZJk7UGTP3TZ noVgxGpqBe67xOFxTv6yfrwmBxqJKF21ExZj70SgHlmSTJvoulZa5g/f/IjzMftVO4sF xOEn7FBPLIHth5RQCUCzGTYYzvMSMTNPOsR/3AizaeqyzGsb9uHNYkTsP75rIxMlF38j rVj4j6kCcBWyp3EA2W5sEsFpzqOUVwMFS4ZAbyer6sdwZZB0DC0S67mOyyS3dd3yhQY5 lvfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FXmYdsz0; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id m3-20020a5d6a03000000b00207a5bc6476si3378643wru.807.2022.05.13.19.42.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 19:42:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FXmYdsz0; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CE30E506EC8; Fri, 13 May 2022 17:52:23 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229704AbiEMXXj (ORCPT + 99 others); Fri, 13 May 2022 19:23:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230391AbiEMXX3 (ORCPT ); Fri, 13 May 2022 19:23:29 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C63C2FDA18; Fri, 13 May 2022 16:20:58 -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 9FB80B83220; Fri, 13 May 2022 23:20:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 102ABC34113; Fri, 13 May 2022 23:20:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1652484055; bh=b92LkAqhO5PUVsDiRTBhHHeNaJDTEdm3bJ8lN4kNIfg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FXmYdsz0VOS5bnNgZiePUFvY4PBeM7didV6ZMHJAFIjZZs4OxD+YKw2GWUImfihKT I8p8PLNSwblLJPzYS1xBLQqBf3UyVdPRXQs5c6Q3ZcvtDXZ1T0ZYBdfkaCNlPlX/nx huOW+ydQXjo9tTd/MnOeIjMJeZqu+6rIbUWJyArYj9QWq/CTnSgQYXYC6w45Y6WtpG XzXGz36/vK8xYXOKx28jqW5Oy/gvZW1zVTH9FOXNZuyC3HmOK640v0tJapmDRcKgdU p6ktSn+1jBvoJ4nOagefuu1EsctNc3giLo6APE847uxu1aYEDfdlJljZI3kyaHHC5i +E/A/Nb3JLh7w== From: Eric Biggers To: linux-fscrypt@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Cc: Jeff Layton , Lukas Czerner , Theodore Ts'o , Jaegeuk Kim , stable@vger.kernel.org Subject: [PATCH v3 1/5] ext4: fix memory leak in parse_apply_sb_mount_options() Date: Fri, 13 May 2022 16:16:01 -0700 Message-Id: <20220513231605.175121-2-ebiggers@kernel.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220513231605.175121-1-ebiggers@kernel.org> References: <20220513231605.175121-1-ebiggers@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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-ext4@vger.kernel.org From: Eric Biggers 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 --- fs/ext4/super.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 1466fbdbc8e34..60fa2f2623e07 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -2625,8 +2625,10 @@ static int parse_apply_sb_mount_options(struct super_block *sb, 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; } -- 2.36.1