Commit 2434b54
committed
md: call del_gendisk in control path
JIRA: https://issues.redhat.com/browse/RHEL-94433
JIRA: https://issues.redhat.com/browse/RHEL-20191
JIRA: https://issues.redhat.com/browse/RHEL-9656
commit 9e59d60
Author: Xiao Ni <xni@redhat.com>
Date: Wed Jun 11 15:31:06 2025 +0800
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 <yukuai3@huawei.com>
Signed-off-by: Xiao Ni <xni@redhat.com>
Link: https://lore.kernel.org/linux-raid/20250611073108.25463-2-xni@redhat.com
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
Signed-off-by: Nigel Croxon <ncroxon@redhat.com>1 parent 14a1b94 commit 2434b54
2 files changed
+47
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
637 | 637 | | |
638 | 638 | | |
639 | 639 | | |
640 | | - | |
641 | | - | |
642 | | - | |
643 | 640 | | |
644 | 641 | | |
645 | 642 | | |
| |||
874 | 871 | | |
875 | 872 | | |
876 | 873 | | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
877 | 884 | | |
878 | 885 | | |
879 | 886 | | |
| |||
5800 | 5807 | | |
5801 | 5808 | | |
5802 | 5809 | | |
| 5810 | + | |
5803 | 5811 | | |
5804 | 5812 | | |
5805 | 5813 | | |
5806 | 5814 | | |
5807 | 5815 | | |
| 5816 | + | |
| 5817 | + | |
| 5818 | + | |
| 5819 | + | |
5808 | 5820 | | |
5809 | 5821 | | |
5810 | 5822 | | |
| 5823 | + | |
| 5824 | + | |
5811 | 5825 | | |
5812 | 5826 | | |
5813 | 5827 | | |
5814 | 5828 | | |
5815 | 5829 | | |
| 5830 | + | |
| 5831 | + | |
| 5832 | + | |
| 5833 | + | |
5816 | 5834 | | |
5817 | 5835 | | |
5818 | 5836 | | |
5819 | 5837 | | |
5820 | 5838 | | |
5821 | 5839 | | |
5822 | 5840 | | |
5823 | | - | |
5824 | | - | |
5825 | | - | |
5826 | | - | |
5827 | | - | |
5828 | | - | |
5829 | 5841 | | |
5830 | 5842 | | |
5831 | 5843 | | |
| |||
6672 | 6684 | | |
6673 | 6685 | | |
6674 | 6686 | | |
6675 | | - | |
6676 | 6687 | | |
| 6688 | + | |
| 6689 | + | |
6677 | 6690 | | |
6678 | 6691 | | |
6679 | 6692 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
702 | 702 | | |
703 | 703 | | |
704 | 704 | | |
705 | | - | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
706 | 718 | | |
707 | 719 | | |
708 | 720 | | |
709 | 721 | | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
710 | 725 | | |
711 | 726 | | |
712 | 727 | | |
| |||
715 | 730 | | |
716 | 731 | | |
717 | 732 | | |
718 | | - | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
719 | 741 | | |
720 | 742 | | |
721 | 743 | | |
| |||
0 commit comments