aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYu Kuai <[email protected]>2025-07-30 07:33:21 +0000
committerYu Kuai <[email protected]>2025-07-30 17:21:43 +0000
commit1df1fc845d221eb646539836dbf509eb96b41afd (patch)
tree54ce96d0cf081f5999669643de8577ee4640d405
parentblk-ioc: don't hold queue_lock for ioc_lookup_icq() (diff)
downloadkernel-1df1fc845d221eb646539836dbf509eb96b41afd.tar.gz
kernel-1df1fc845d221eb646539836dbf509eb96b41afd.zip
md: fix create on open mddev lifetime regression
Commit 9e59d609763f ("md: call del_gendisk in control path") moves setting MD_DELETED from __mddev_put() to do_md_stop(), however, for the case create on open, mddev can be freed without do_md_stop(): 1) open md_probe md_alloc_and_put md_alloc mddev_alloc atomic_set(&mddev->active, 1); mddev->hold_active = UNTIL_IOCTL mddev_put atomic_dec_and_test(&mddev->active) if (mddev->hold_active) -> active is 0, hold_active is set md_open mddev_get atomic_inc(&mddev->active); 2) ioctl that is not STOP_ARRAY, for example, GET_ARRAY_INFO: md_ioctl mddev->hold_active = 0 3) close md_release mddev_put(mddev); atomic_dec_and_lock(&mddev->active, &all_mddevs_lock) __mddev_put -> hold_active is cleared, mddev will be freed queue_work(md_misc_wq, &mddev->del_work) Now that MD_DELETED is not set, before mddev is freed by mddev_delayed_delete(), md_open can still succeed and break mddev lifetime, causing mddev->kobj refcount underflow or mddev uaf problem. Fix this problem by setting MD_DELETED before queuing del_work. Reported-by: [email protected] Closes: https://lore.kernel.org/all/[email protected]/ Reported-by: [email protected] Closes: https://lore.kernel.org/all/[email protected]/ Fixes: 9e59d609763f ("md: call del_gendisk in control path") Link: https://lore.kernel.org/linux-raid/[email protected] Signed-off-by: Yu Kuai <[email protected]> Reviewed-by: Paul Menzel <[email protected]> Reviewed-by: Xiao Ni <[email protected]>
-rw-r--r--drivers/md/md.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 046fe85c76fe..2716d5c59517 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -637,6 +637,12 @@ static void __mddev_put(struct mddev *mddev)
return;
/*
+ * If array is freed by stopping array, MD_DELETED is set by
+ * do_md_stop(), MD_DELETED is still set here in case mddev is freed
+ * directly by closing a mddev that is created by create_on_open.
+ */
+ set_bit(MD_DELETED, &mddev->flags);
+ /*
* Call queue_work inside the spinlock so that flush_workqueue() after
* mddev_find will succeed in waiting for the work to be done.
*/