Commit 9dd1cd3
Mike Snitzer
dm: fix dm-raid crash if md_handle_request() splits bio
Commit ca52248 ("dm: pass NULL bdev to bio_alloc_clone")
introduced the optimization to _not_ perform bio_associate_blkg()'s
relatively costly work when DM core clones its bio. But in doing so it
exposed the possibility for DM's cloned bio to alter DM target
behavior (e.g. crash) if a target were to issue IO without first
calling bio_set_dev().
The DM raid target can trigger an MD crash due to its need to split
the DM bio that is passed to md_handle_request(). The split will
recurse to submit_bio_noacct() using a bio with an uninitialized
->bi_blkg. This NULL bio->bi_blkg causes blk_throtl_bio() to
dereference a NULL blkg_to_tg(bio->bi_blkg).
Fix this in DM core by adding a new 'needs_bio_set_dev' target flag that
will make alloc_tio() call bio_set_dev() on behalf of the target.
dm-raid is the only target that requires this flag. bio_set_dev()
initializes the DM cloned bio's ->bi_blkg, using bio_associate_blkg,
before passing the bio to md_handle_request().
Long-term fix would be to audit and refactor MD code to rely on DM to
split its bio, using dm_accept_partial_bio(), but there are MD raid
personalities (e.g. raid1 and raid10) whose implementation are tightly
coupled to handling the bio splitting inline.
Fixes: ca52248 ("dm: pass NULL bdev to bio_alloc_clone")
Cc: [email protected]
Signed-off-by: Mike Snitzer <[email protected]>1 parent 7dad24d commit 9dd1cd3
File tree
4 files changed
+15
-9
lines changed- drivers/md
- include
- linux
- uapi/linux
4 files changed
+15
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3095 | 3095 | | |
3096 | 3096 | | |
3097 | 3097 | | |
| 3098 | + | |
3098 | 3099 | | |
3099 | 3100 | | |
3100 | 3101 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
574 | 574 | | |
575 | 575 | | |
576 | 576 | | |
577 | | - | |
578 | | - | |
579 | | - | |
580 | 577 | | |
581 | 578 | | |
582 | 579 | | |
| |||
609 | 606 | | |
610 | 607 | | |
611 | 608 | | |
| 609 | + | |
612 | 610 | | |
613 | 611 | | |
614 | 612 | | |
| |||
618 | 616 | | |
619 | 617 | | |
620 | 618 | | |
621 | | - | |
622 | | - | |
623 | 619 | | |
624 | 620 | | |
625 | 621 | | |
626 | 622 | | |
627 | | - | |
628 | | - | |
629 | 623 | | |
630 | 624 | | |
631 | 625 | | |
| |||
641 | 635 | | |
642 | 636 | | |
643 | 637 | | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
644 | 643 | | |
645 | 644 | | |
646 | 645 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
373 | 373 | | |
374 | 374 | | |
375 | 375 | | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
376 | 382 | | |
377 | 383 | | |
378 | 384 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
286 | 286 | | |
287 | 287 | | |
288 | 288 | | |
289 | | - | |
| 289 | + | |
290 | 290 | | |
291 | | - | |
| 291 | + | |
292 | 292 | | |
293 | 293 | | |
294 | 294 | | |
| |||
0 commit comments