From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A0BCB1CD5C0; Tue, 9 Jul 2024 16:23:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720542200; cv=none; b=LigkIhePVmskUSQOCXK5fAVT7KxDT7xpAnj5+UnbljONIHP7I9hXss0CXx68wwM4iY+uZN9WnBbJc53oklNvDzJCfGCCbY+TLHTbJ/XjpyOMQi4X53qRz4qyYxTRwOR/wdbmKP50x1/dhTtvCt/4RmDmuZipkDVhzHueBwMTKdc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720542200; c=relaxed/simple; bh=wUr2ViHXx5P9+0tGV7ntLO2JBTHbENx0R7dWuYdTdXk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X5SfJiiSbYCHXIj9Qwe1PG3KTDop2vI796MrvLoArTmubUFBAhfsN+5Nm+1e43VcLjnqeLDwQDUGy56p2ToksPVr1t5sAwWjlXKtAsi9FH1XUs30Kq65Hcrk3V5O/GrRRjoVbLFNBm6egvzY/FXvRAecS0yrqQ0hpipM6drPP7o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UgHwfIDx; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UgHwfIDx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 662C6C3277B; Tue, 9 Jul 2024 16:23:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720542200; bh=wUr2ViHXx5P9+0tGV7ntLO2JBTHbENx0R7dWuYdTdXk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UgHwfIDxuJdStNppo2zI8peePbBRF747fEN8aIKIUVeYQUwCjdBg4OSBlI+9olAR/ vMBzCSYpbFNfBXd73K6pdiY2v2SrKMbzTo0olb9Q60EZd/LfHCGs+m/0NiXgvea8Om tKxLoO9MuTZvzHXOBNHt5UQs3+LE/TiozNDABp4DInYcmvcFnvxJ77gvJb8Qf72FHr TRzNB0sRXNdnhGfT0h7pBi7njWSkY3H54HNJ2WMo1XkKaB8zFLvo7ceMxPsaYD58Ig pDyABXgEV4Xe4hI24uGOQVI+H10BFx8oMyvVxU3UvKqDjgGIYFSQ1aoRCtvnscpXdq p8FxO8eHEVPsA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Filipe Manana , Boris Burkov , Qu Wenruo , David Sterba , Sasha Levin , clm@fb.com, josef@toxicpanda.com, linux-btrfs@vger.kernel.org Subject: [PATCH AUTOSEL 6.6 26/33] btrfs: qgroup: fix quota root leak after quota disable failure Date: Tue, 9 Jul 2024 12:21:52 -0400 Message-ID: <20240709162224.31148-26-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240709162224.31148-1-sashal@kernel.org> References: <20240709162224.31148-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.6.38 Content-Transfer-Encoding: 8bit From: Filipe Manana [ Upstream commit a7e4c6a3031c74078dba7fa36239d0f4fe476c53 ] If during the quota disable we fail when cleaning the quota tree or when deleting the root from the root tree, we jump to the 'out' label without ever dropping the reference on the quota root, resulting in a leak of the root since fs_info->quota_root is no longer pointing to the root (we have set it to NULL just before those steps). Fix this by always doing a btrfs_put_root() call under the 'out' label. This is a problem that exists since qgroups were first added in 2012 by commit bed92eae26cc ("Btrfs: qgroup implementation and prototypes"), but back then we missed a kfree on the quota root and free_extent_buffer() calls on its root and commit root nodes, since back then roots were not yet reference counted. Reviewed-by: Boris Burkov Reviewed-by: Qu Wenruo Signed-off-by: Filipe Manana Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/qgroup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index 99ea2c6d31944..223dfbf009938 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -1228,7 +1228,7 @@ int btrfs_quota_enable(struct btrfs_fs_info *fs_info) int btrfs_quota_disable(struct btrfs_fs_info *fs_info) { - struct btrfs_root *quota_root; + struct btrfs_root *quota_root = NULL; struct btrfs_trans_handle *trans = NULL; int ret = 0; @@ -1323,9 +1323,9 @@ int btrfs_quota_disable(struct btrfs_fs_info *fs_info) btrfs_free_tree_block(trans, btrfs_root_id(quota_root), quota_root->node, 0, 1); - btrfs_put_root(quota_root); out: + btrfs_put_root(quota_root); mutex_unlock(&fs_info->qgroup_ioctl_lock); if (ret && trans) btrfs_end_transaction(trans); -- 2.43.0