]> git.baikalelectronics.ru Git - kernel.git/commit
btrfs: revert fs_devices state on error of btrfs_init_new_device
authorNaohiro Aota <naota@elisp.net>
Fri, 27 Jul 2018 00:04:55 +0000 (09:04 +0900)
committerDavid Sterba <dsterba@suse.com>
Mon, 6 Aug 2018 11:13:04 +0000 (13:13 +0200)
commit1a605b0e9c8b264f8bd1857e70b6079b0b76f40c
tree6b7f07df694ff8e502a024f71a2dd0020f23e5c3
parent3b8720d2ff59eab5b0f1c933f66578947a39205b
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: 99175604eacb ("btrfs: replace many BUG_ONs with proper error handling")
Signed-off-by: Naohiro Aota <naota@elisp.net>
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/volumes.c