Skip to content
Commit 39379faa authored by Naohiro Aota's avatar Naohiro Aota Committed by David Sterba
Browse files

btrfs: revert fs_devices state on error of btrfs_init_new_device



When btrfs hits error after modifying fs_devices in
btrfs_init_new_device() (such as btrfs_add_dev_item() returns error), it
leaves everything as is, but frees allocated btrfs_device. As a result,
fs_devices->devices and fs_devices->alloc_list contain already freed
btrfs_device, leading to later use-after-free bug.

Error path also messes the things like ->num_devices. While they go back
to the original value by unscanning btrfs devices, it is safe to revert
them here.

Fixes: 79787eaa ("btrfs: replace many BUG_ONs with proper error handling")
Signed-off-by: default avatarNaohiro Aota <naota@elisp.net>
Reviewed-by: default avatarFilipe Manana <fdmanana@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 64f64f43
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment