Re: [PATCH 3/3] md: call del_gendisk in sync way

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

在 2025/05/07 10:14, Xiao Ni 写道:
Now del_gendisk and put_disk are called asynchronously in workqueue work.
The asynchronous way also 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 ioctl path and still leave put_disk in
md_kobj_release to avoid uaf.

Signed-off-by: Xiao Ni <xni@xxxxxxxxxx>
---
  drivers/md/md.c | 14 ++++++++++++--
  1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index c226747be9e3..a82778f6c31f 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -5718,19 +5718,30 @@ md_attr_store(struct kobject *kobj, struct attribute *attr,
  	struct md_sysfs_entry *entry = container_of(attr, struct md_sysfs_entry, attr);
  	struct mddev *mddev = container_of(kobj, struct mddev, kobj);
  	ssize_t rv;
+	struct kernfs_node *kn = NULL;
if (!entry->store)
  		return -EIO;
  	if (!capable(CAP_SYS_ADMIN))
  		return -EACCES;
+
+	if (entry->store == array_state_store && cmd_match(page, "clear"))
+		kn = sysfs_break_active_protection(kobj, attr);
+
  	spin_lock(&all_mddevs_lock);
  	if (!mddev_get(mddev)) {
+		if (kn)
+			sysfs_unbreak_active_protection(kn);
  		spin_unlock(&all_mddevs_lock);
  		return -EBUSY;
  	}
  	spin_unlock(&all_mddevs_lock);
  	rv = entry->store(mddev, page, length);
  	mddev_put(mddev);
+
+	if (kn)
+		sysfs_unbreak_active_protection(kn);
+
  	return rv;
  }
@@ -5743,7 +5754,6 @@ static void md_kobj_release(struct kobject *ko)
  	if (mddev->sysfs_level)
  		sysfs_put(mddev->sysfs_level);
- del_gendisk(mddev->gendisk);
  	put_disk(mddev->gendisk);
  }
@@ -6585,8 +6595,8 @@ static int do_md_stop(struct mddev *mddev, int mode)
  		mddev->bitmap_info.offset = 0;
export_array(mddev);
-
  		md_clean(mddev);
+		del_gendisk(mddev->gendisk);
  	}

Refer to the comments in mddev_unlock, there are some special hacks, to
delay removing md_redundancy_group until releasing reconfig_mutex, and
looks like del_gendisk here will break that.

Thanks,
Kuai

  	md_new_event();
  	sysfs_notify_dirent_safe(mddev->sysfs_state);






[Index of Archives]     [Linux RAID Wiki]     [ATA RAID]     [Linux SCSI Target Infrastructure]     [Linux Block]     [Linux IDE]     [Linux SCSI]     [Linux Hams]     [Device Mapper]     [Device Mapper Cryptographics]     [Kernel]     [Linux Admin]     [Linux Net]     [GFS]     [RPM]     [git]     [Yosemite Forum]


  Powered by Linux