From: "yu kuai" <yukuai@fygo.io>
To: "By" <xiaobai050@gmail.com>, <song@kernel.org>,
"yu kuai" <yukuai@fygo.io>
Cc: <magiclinan@didiglobal.com>, <xiao@kernel.org>,
<linux-raid@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<syzbot+95eeb4ada2349a2170ea@syzkaller.appspotmail.com>
Subject: Re: [PATCH] md: prevent opening an array before its sysfs kobject is ready
Date: Wed, 23 Sep 2026 19:53:52 +0800 [thread overview]
Message-ID: <a19e3020-272b-4f93-8535-00fa07002d91@fygo.io> (raw)
In-Reply-To: <20260923071017.23563-1-xiaobai050@gmail.com>
Hi,
在 2026/9/23 15:10, By 写道:
> md_alloc() publishes the gendisk with add_disk() before it initializes
> and registers mddev->kobj. A concurrent open can issue ADD_NEW_DISK in
> this window, causing bind_rdev_to_array() to pass the uninitialized
> mddev kobject as a parent to kobject_add(). This triggers a kobject
> warning.
>
> Set MD_CLOSING before publishing the disk so md_open() rejects opens
> until the kobject and sysfs attributes are ready. Clear the bit under
> open_mutex, which md_open() holds while checking it.
>
> Compile-tested with ARCH=arm64 defconfig and drivers/md/md.o. The
> upstream syzbot report has no reproducer, so this race was not tested
> at runtime.
>
> Fixes: 7df835a32a8b ("md: fix a lock order reversal in md_alloc")
> Reported-by: syzbot+95eeb4ada2349a2170ea@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=95eeb4ada2349a2170ea
> Assisted-by: LLM
> Signed-off-by: By <xiaobai050@gmail.com>
> ---
> drivers/md/md.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index 680b34a63..11b0b6b13 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -6385,6 +6385,8 @@ struct mddev *md_alloc(dev_t dev, char *name)
>
> disk->events |= DISK_EVENT_MEDIA_CHANGE;
> mddev->gendisk = disk;
> + /* add_disk() exposes the device before its md kobject is registered. */
> + set_bit(MD_CLOSING, &mddev->flags);
> error = add_disk(disk);
> if (error)
> goto out_put_disk;
> @@ -6406,6 +6408,9 @@ struct mddev *md_alloc(dev_t dev, char *name)
> kobject_uevent(&mddev->kobj, KOBJ_ADD);
> mddev->sysfs_state = sysfs_get_dirent_safe(mddev->kobj.sd, "array_state");
> mddev->sysfs_level = sysfs_get_dirent_safe(mddev->kobj.sd, "level");
> + mutex_lock(&mddev->open_mutex);
> + clear_bit(MD_CLOSING, &mddev->flags);
> + mutex_unlock(&mddev->open_mutex);
I don't like this fix, it introduces a race window that open md device will fail. Instead,
since all bind_rdev_to_array() is already protected by reconfig_mutex, can this problem be
fixed by holding reconfig_mutex for both add_disk and kobject_add?
> mutex_unlock(&disks_mutex);
> return mddev;
>
--
Thanks,
Kuai
prev parent reply other threads:[~2026-09-23 11:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-23 7:10 By
2026-09-23 11:53 ` yu kuai [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a19e3020-272b-4f93-8535-00fa07002d91@fygo.io \
--to=yukuai@fygo.io \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-raid@vger.kernel.org \
--cc=magiclinan@didiglobal.com \
--cc=song@kernel.org \
--cc=syzbot+95eeb4ada2349a2170ea@syzkaller.appspotmail.com \
--cc=xiao@kernel.org \
--cc=xiaobai050@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®