Skip to content

Commit 1742e1c

Browse files
void0redkdave
authored andcommitted
btrfs: fix extent map use-after-free when handling missing device in read_one_chunk
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 <1527030098@qq.com> Fixes: adfb69a ("btrfs: add_missing_dev() should return the actual error") CC: stable@vger.kernel.org # 4.9+ Signed-off-by: void0red <void0red@gmail.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 3eb4234 commit 1742e1c

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

fs/btrfs/volumes.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6976,8 +6976,9 @@ static int read_one_chunk(struct btrfs_key *key, struct extent_buffer *leaf,
69766976
map->stripes[i].dev = handle_missing_device(fs_info,
69776977
devid, uuid);
69786978
if (IS_ERR(map->stripes[i].dev)) {
6979+
ret = PTR_ERR(map->stripes[i].dev);
69796980
free_extent_map(em);
6980-
return PTR_ERR(map->stripes[i].dev);
6981+
return ret;
69816982
}
69826983
}
69836984

0 commit comments

Comments
 (0)