From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 1/2] btrfs: always remove quota_root from dirty_cowonly_roots
Date: Tue, 13 Oct 2026 09:28:47 +1030 [thread overview]
Message-ID: <e71e6fcda482f306e8841292ea0031594de78577.1791845501.git.wqu@suse.com> (raw)
In-Reply-To: <cover.1791845501.git.wqu@suse.com>
[ERROR HANDLING QUIRK]
When btrfs_quota_disable() failed at btrfs_clean_quota_tree() or
btrfs_del_root(), the quota_root->dirty_list is not removed from
fs_info->dirty_cowonly_roots, but the quota_root itself will be freed.
This leaves a dangling pointer in the dirty_cowonly_roots.
This is not a huge problem, as the transaction is aborted thus no one
will read the dirty_cowonly_roots for now.
Furthermore, quota_root should never be logged nor have qgroup swapped
tree blocks, thus it won't cause leaks from extent io tree nor qgroup
swapped blocks.
[ENHANCEMENT]
For the incoming cleanup of dirty_cowonly_roots during
btrfs_free_fs_roots(), any root that is still linked to
dirty_cowonly_roots will be read again, and this existing dangling
pointer is going to cause problem.
To prepare for that cleanup, move the list_del() call into the out
label, so that even if the transaction is aborted, we still unlink
quota_root from dirty_cowonly_roots before freeing it.
Assisted-by: LLM (exposing the bug during review)
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
fs/btrfs/qgroup.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index a0651fbfe778..8bd3abdf4805 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -1440,10 +1440,6 @@ int btrfs_quota_disable(struct btrfs_fs_info *fs_info)
goto out;
}
- spin_lock(&fs_info->trans_lock);
- list_del("a_root->dirty_list);
- spin_unlock(&fs_info->trans_lock);
-
btrfs_tree_lock(quota_root->node);
btrfs_clear_buffer_dirty(trans, quota_root->node);
btrfs_tree_unlock(quota_root->node);
@@ -1454,6 +1450,12 @@ int btrfs_quota_disable(struct btrfs_fs_info *fs_info)
btrfs_abort_transaction(trans, ret);
out:
+ if (quota_root) {
+ spin_lock(&fs_info->trans_lock);
+ list_del("a_root->dirty_list);
+ spin_unlock(&fs_info->trans_lock);
+ }
+
btrfs_put_root(quota_root);
mutex_unlock(&fs_info->qgroup_ioctl_lock);
if (ret && trans)
--
2.56.0
next prev parent reply other threads:[~2026-10-12 22:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-12 22:58 [PATCH 0/2] btrfs: further cleanup on fs_info->dirty_cowonly_roots Qu Wenruo
2026-10-12 22:58 ` Qu Wenruo [this message]
2026-10-12 22:58 ` [PATCH 2/2] btrfs: cleanup dirty_cowonly_roots during btrfs_free_fs_roots() Qu Wenruo
2026-10-13 5:41 ` Qu Wenruo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e71e6fcda482f306e8841292ea0031594de78577.1791845501.git.wqu@suse.com \
--to=wqu@suse.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.