Skip to contentSkip to conversation

Btrfs: fix unprotected assignment of the left cursor for device replace

PATCH In review [email protected] 2 participants 2 messages May 20, 2016 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 4/6 Btrfs: fix unprotected assignment of the left cursor for device replace

From: Filipe Manana <[email protected]>

We were assigning new values to fields of the device replace object without holding the respective lock after processing each device extent. This is important for the left cursor field which can be accessed by a concurrent task running __btrfs_map_block (which, correctly, takes the device replace lock).
So change these fields while holding the device replace lock.

---
 fs/btrfs/scrub.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/btrfs/scrub.c +4 -0
index a181b52..a58e0ae 100644
@@ -3640,9 +3640,11 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
 			break;
 		}
 
+		btrfs_dev_replace_lock(&fs_info->dev_replace, 1);
 		dev_replace->cursor_right = found_key.offset + length;
 		dev_replace->cursor_left = found_key.offset;
 		dev_replace->item_needs_writeback = 1;
+		btrfs_dev_replace_unlock(&fs_info->dev_replace, 1);
 		ret = scrub_chunk(sctx, scrub_dev, chunk_offset, length,
 				  found_key.offset, cache, is_dev_replace);
 
@@ -3716,8 +3718,10 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
 			break;
 		}
 
+		btrfs_dev_replace_lock(&fs_info->dev_replace, 1);
 		dev_replace->cursor_left = dev_replace->cursor_right;
 		dev_replace->item_needs_writeback = 1;
+		btrfs_dev_replace_unlock(&fs_info->dev_replace, 1);
 skip:
 		key.offset = found_key.offset + length;
 		btrfs_release_path(path);
Signature · 1 line
2.7.0.rc3
Reviewed-by on v1 4/6
#1 lore raw
Quoted 10 lines · On Fri, May 20, 2016 at 12:44 AM, <[email protected]> wrote:

From: Filipe Manana <[email protected]>

We were assigning new values to fields of the device replace object without holding the respective lock after processing each device extent. This is important for the left cursor field which can be accessed by a concurrent task running __btrfs_map_block (which, correctly, takes the device replace lock).
So change these fields while holding the device replace lock.

Eesh, thanks,