Skip to contentSkip to conversation

btrfs: fix double unlock bugs in btrfs_compare_trees()

PATCH In review Dan Carpenter 2 participants 3 messages Jan 7, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: fix double unlock bugs in btrfs_compare_trees()

These error paths unlock before the goto, but the goto also unlocks so it's a double unlock.

Fixes 5646ffa863d0 ("btrfs: make send work with concurrent block group relocation")
---
 fs/btrfs/send.c | 2 --
 1 file changed, 2 deletions(-)
fs/btrfs/send.c +0 -2
index 3fc144b8c0d8..1aa8a0998673 100644
@@ -7152,7 +7152,6 @@ static int btrfs_compare_trees(struct btrfs_root *left_root,
 	left_path->nodes[left_level] =
 			btrfs_clone_extent_buffer(left_root->commit_root);
 	if (!left_path->nodes[left_level]) {
-		up_read(&fs_info->commit_root_sem);
 		ret = -ENOMEM;
 		goto out;
 	}
@@ -7162,7 +7161,6 @@ static int btrfs_compare_trees(struct btrfs_root *left_root,
 	right_path->nodes[right_level] =
 			btrfs_clone_extent_buffer(right_root->commit_root);
 	if (!right_path->nodes[right_level]) {
-		up_read(&fs_info->commit_root_sem);
 		ret = -ENOMEM;
 		goto out;
 	}
Signature · 1 line
2.20.1
#1 lore raw
Quoted 2 lines · Dan Carpenter

These error paths unlock before the goto, but the goto also unlocks so it's a double unlock.

There's also the case where there's an unlock without a previous lock. I've just sent out a different version of the patch that fixes that as well:

https://lore.kernel.org/linux-btrfs/a7b1b2094bb0697dda72bdd9bf1ed789cb0b9b08.1641550850.git.fdmanana@suse.com/

Thanks.

Quoted 30 lines
Fixes 5646ffa863d0 ("btrfs: make send work with concurrent block group relocation")
---
 fs/btrfs/send.c | 2 --
 1 file changed, 2 deletions(-)
fs/btrfs/send.c +0 -2
index 3fc144b8c0d8..1aa8a0998673 100644
@@ -7152,7 +7152,6 @@ static int btrfs_compare_trees(struct btrfs_root *left_root,
 	left_path->nodes[left_level] =
 			btrfs_clone_extent_buffer(left_root->commit_root);
 	if (!left_path->nodes[left_level]) {
-		up_read(&fs_info->commit_root_sem);
 		ret = -ENOMEM;
 		goto out;
 	}
@@ -7162,7 +7161,6 @@ static int btrfs_compare_trees(struct btrfs_root *left_root,
 	right_path->nodes[right_level] =
 			btrfs_clone_extent_buffer(right_root->commit_root);
 	if (!right_path->nodes[right_level]) {
-		up_read(&fs_info->commit_root_sem);
 		ret = -ENOMEM;
 		goto out;
 	}
Signature · 1 line
2.20.1
#2 lore raw
Quoted 8 lines · Filipe Manana
Quoted 2 lines · Dan Carpenter

These error paths unlock before the goto, but the goto also unlocks so it's a double unlock.

There's also the case where there's an unlock without a previous lock. I've just sent out a different version of the patch that fixes that as well:

https://lore.kernel.org/linux-btrfs/a7b1b2094bb0697dda72bdd9bf1ed789cb0b9b08.1641550850.git.fdmanana@suse.com/

Ah! Thanks.

regards,
dan carpenter