Commit 9e59d60
md: call del_gendisk in control path
Now del_gendisk and put_disk are called asynchronously in workqueue work.
The asynchronous way has a problem that the device node can still exist
after mdadm --stop command returns in a short window. So udev rule can
open this device node and create the struct mddev in kernel again. So put
del_gendisk in control path and still leave put_disk in md_kobj_release
to avoid uaf of gendisk.
Function del_gendisk can't be called with reconfig_mutex. If it's called
with reconfig mutex, a deadlock can happen. del_gendisk waits all sysfs
files access to finish and sysfs file access waits reconfig mutex. So
put del_gendisk after releasing reconfig mutex.
But there is still a window that sysfs can be accessed between mddev_unlock
and del_gendisk. So some actions (add disk, change level, .e.g) can happen
which lead unexpected results. MD_DELETED is used to resolve this problem.
MD_DELETED is set before releasing reconfig mutex and it should be checked
for these sysfs access which need reconfig mutex. For sysfs access which
don't need reconfig mutex, del_gendisk will wait them to finish.
But it doesn't need to do this in function mddev_lock_nointr. There are
ten places that call it.
* Five of them are in dm raid which we don't need to care. MD_DELETED is
only used for md raid.
* stop_sync_thread, md_do_sync and md_start_sync are related sync request,
and it needs to wait sync thread to finish before stopping an array.
* md_ioctl: md_open is called before md_ioctl, so ->openers is added. It
will fail to stop the array. So it doesn't need to check MD_DELETED here
* md_set_readonly:
It needs to call mddev_set_closing_and_sync_blockdev when setting readonly
or read_auto. So it will fail to stop the array too because MD_CLOSING is
already set.
Reviewed-by: Yu Kuai <[email protected]>
Signed-off-by: Xiao Ni <[email protected]>
Link: https://lore.kernel.org/linux-raid/[email protected]
Signed-off-by: Yu Kuai <[email protected]>1 parent 7e49538 commit 9e59d60
2 files changed
Lines changed: 47 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
636 | 636 | | |
637 | 637 | | |
638 | 638 | | |
639 | | - | |
640 | | - | |
641 | | - | |
642 | 639 | | |
643 | 640 | | |
644 | 641 | | |
| |||
873 | 870 | | |
874 | 871 | | |
875 | 872 | | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
876 | 883 | | |
877 | 884 | | |
878 | 885 | | |
| |||
5774 | 5781 | | |
5775 | 5782 | | |
5776 | 5783 | | |
| 5784 | + | |
5777 | 5785 | | |
5778 | 5786 | | |
5779 | 5787 | | |
5780 | 5788 | | |
5781 | 5789 | | |
| 5790 | + | |
| 5791 | + | |
| 5792 | + | |
| 5793 | + | |
5782 | 5794 | | |
5783 | 5795 | | |
5784 | 5796 | | |
| 5797 | + | |
| 5798 | + | |
5785 | 5799 | | |
5786 | 5800 | | |
5787 | 5801 | | |
5788 | 5802 | | |
5789 | 5803 | | |
| 5804 | + | |
| 5805 | + | |
| 5806 | + | |
| 5807 | + | |
5790 | 5808 | | |
5791 | 5809 | | |
5792 | 5810 | | |
5793 | 5811 | | |
5794 | 5812 | | |
5795 | 5813 | | |
5796 | 5814 | | |
5797 | | - | |
5798 | | - | |
5799 | | - | |
5800 | | - | |
5801 | | - | |
5802 | | - | |
5803 | 5815 | | |
5804 | 5816 | | |
5805 | 5817 | | |
| |||
6646 | 6658 | | |
6647 | 6659 | | |
6648 | 6660 | | |
6649 | | - | |
6650 | 6661 | | |
| 6662 | + | |
| 6663 | + | |
6651 | 6664 | | |
6652 | 6665 | | |
6653 | 6666 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
700 | 700 | | |
701 | 701 | | |
702 | 702 | | |
703 | | - | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
704 | 716 | | |
705 | 717 | | |
706 | 718 | | |
707 | 719 | | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
708 | 723 | | |
709 | 724 | | |
710 | 725 | | |
| |||
713 | 728 | | |
714 | 729 | | |
715 | 730 | | |
716 | | - | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
717 | 739 | | |
718 | 740 | | |
719 | 741 | | |
| |||
0 commit comments