Commit 39379fa
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: 79787ea ("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>1 parent 64f64f4 commit 39379fa
1 file changed
+24
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2321 | 2321 | | |
2322 | 2322 | | |
2323 | 2323 | | |
2324 | | - | |
| 2324 | + | |
| 2325 | + | |
2325 | 2326 | | |
2326 | 2327 | | |
2327 | 2328 | | |
| |||
2417 | 2418 | | |
2418 | 2419 | | |
2419 | 2420 | | |
2420 | | - | |
| 2421 | + | |
2421 | 2422 | | |
2422 | | - | |
| 2423 | + | |
| 2424 | + | |
2423 | 2425 | | |
2424 | | - | |
2425 | | - | |
| 2426 | + | |
| 2427 | + | |
| 2428 | + | |
2426 | 2429 | | |
2427 | 2430 | | |
2428 | 2431 | | |
| |||
2502 | 2505 | | |
2503 | 2506 | | |
2504 | 2507 | | |
| 2508 | + | |
| 2509 | + | |
| 2510 | + | |
| 2511 | + | |
| 2512 | + | |
| 2513 | + | |
| 2514 | + | |
| 2515 | + | |
| 2516 | + | |
| 2517 | + | |
| 2518 | + | |
| 2519 | + | |
| 2520 | + | |
| 2521 | + | |
| 2522 | + | |
| 2523 | + | |
2505 | 2524 | | |
2506 | 2525 | | |
2507 | 2526 | | |
| |||
0 commit comments