[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)
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
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);
btrfs_abort_transaction(trans, ret);
out:
- btrfs_put_root(quota_root);
+ 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)
btrfs_end_transaction(trans);