diff mbox series

btrfs: qgroup: fix double unlock in btrfs_quota_disable

Message ID 1ed61ba7891b9f86a20a46ee5bb42cb4649311af.1695833099.git.boris@bur.io (mailing list archive)
State New, archived
Headers show
Series btrfs: qgroup: fix double unlock in btrfs_quota_disable | expand

Commit Message

Boris Burkov Sept. 27, 2023, 4:45 p.m. UTC
Flushing reservations in quota disable is done while we do not hold the
qgroup ioctl lock, therefore jumping to releasing that lock on failure
is wrong. We don't have the transaction handle yet, either, so just jump
to unlocking the cleaner mutex. This was found by smatch.

Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/linux-btrfs/dfadfecc-e50b-425a-80f7-3ae1290db2d3@moroto.mountain/T/#u
Fixes: 5e99a45f1f0f ("btrfs: qgroup: flush reservations during quota disable")
Signed-off-by: Boris Burkov <boris@bur.io>
---
 fs/btrfs/qgroup.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

David Sterba Sept. 27, 2023, 5:49 p.m. UTC | #1
On Wed, Sep 27, 2023 at 09:45:14AM -0700, Boris Burkov wrote:
> Flushing reservations in quota disable is done while we do not hold the
> qgroup ioctl lock, therefore jumping to releasing that lock on failure
> is wrong. We don't have the transaction handle yet, either, so just jump
> to unlocking the cleaner mutex. This was found by smatch.
> 
> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> Closes: https://lore.kernel.org/linux-btrfs/dfadfecc-e50b-425a-80f7-3ae1290db2d3@moroto.mountain/T/#u
> Fixes: 5e99a45f1f0f ("btrfs: qgroup: flush reservations during quota disable")
> Signed-off-by: Boris Burkov <boris@bur.io>

Folded to the commit, thanks.
diff mbox series

Patch

diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index 1a486d8a7b5a..7d9cb7064811 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -1375,7 +1375,7 @@  int btrfs_quota_disable(struct btrfs_fs_info *fs_info)
 
 	ret = flush_reservations(fs_info);
 	if (ret)
-		goto out;
+		goto unlock_cleaner;
 
 	/*
 	 * 1 For the root item
@@ -1439,6 +1439,7 @@  int btrfs_quota_disable(struct btrfs_fs_info *fs_info)
 		btrfs_end_transaction(trans);
 	else if (trans)
 		ret = btrfs_commit_transaction(trans);
+unlock_cleaner:
 	mutex_unlock(&fs_info->cleaner_mutex);
 
 	return ret;