Skip to content

Commit 169a4cf

Browse files
void0redgregkh
authored andcommitted
btrfs: fix extent map use-after-free when handling missing device in read_one_chunk
commit 1742e1c upstream. Store the error code before freeing the extent_map. Though it's reference counted structure, in that function it's the first and last allocation so this would lead to a potential use-after-free. The error can happen eg. when chunk is stored on a missing device and the degraded mount option is missing. Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=216721 Reported-by: eriri <[email protected]> Fixes: adfb69a ("btrfs: add_missing_dev() should return the actual error") CC: [email protected] # 4.9+ Signed-off-by: void0red <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 712b093 commit 169a4cf

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

fs/btrfs/volumes.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7241,8 +7241,9 @@ static int read_one_chunk(struct btrfs_key *key, struct extent_buffer *leaf,
72417241
map->stripes[i].dev = handle_missing_device(fs_info,
72427242
devid, uuid);
72437243
if (IS_ERR(map->stripes[i].dev)) {
7244+
ret = PTR_ERR(map->stripes[i].dev);
72447245
free_extent_map(em);
7245-
return PTR_ERR(map->stripes[i].dev);
7246+
return ret;
72467247
}
72477248
}
72487249

0 commit comments

Comments
 (0)