From: "Yu Kuai" <yukuai@fnnas.com>
To: "Guangshuo Li" <lgs201920130244@gmail.com>,
"Song Liu" <song@kernel.org>,
"Greg Kroah-Hartman" <gregkh@suse.de>,
<linux-raid@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<yukuai@fnnas.com>
Cc: <stable@vger.kernel.org>
Subject: Re: [PATCH v2] md: fix kobject reference leak in md_import_device()
Date: Sun, 19 Apr 2026 12:42:29 +0800 [thread overview]
Message-ID: <cdc869dc-ba1a-4cc2-a44c-3d147ca6bbbc@fnnas.com> (raw)
In-Reply-To: <20260413141759.2970973-1-lgs201920130244@gmail.com>
Hi,
在 2026/4/13 22:17, Guangshuo Li 写道:
> md_import_device() initializes rdev->kobj with kobject_init() before
> checking the device size and loading the superblock.
>
> When one of the later checks fails, the error path still frees rdev
> directly with kfree(). This bypasses the kobject release path and leaves
> the kobject reference unbalanced.
>
> The issue was identified by a static analysis tool I developed and
> confirmed by manual review.
>
> After kobject_init(), release rdev through kobject_put() instead of
> kfree().
>
> Fixes: f9cb074bff8e ("Kobject: rename kobject_init_ng() to kobject_init()")
> Cc: stable@vger.kernel.org
> Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
> ---
> v2:
> - note that the issue was identified by my static analysis tool
> - and confirmed by manual review
>
> drivers/md/md.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index 6d73f6e196a9..4ce7512dc834 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -3871,6 +3871,9 @@ static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supe
>
> out_blkdev_put:
> fput(rdev->bdev_file);
> + md_rdev_clear(rdev);
> + kobject_put(&rdev->kobj);
> + return ERR_PTR(err);
I think it's cleaner to move kobject_init() after everything in rdev
is ready.
> out_clear_rdev:
> md_rdev_clear(rdev);
> out_free_rdev:
--
Thansk,
Kuai
prev parent reply other threads:[~2026-04-19 4:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-13 14:17 [PATCH v2] md: fix kobject reference leak in md_import_device() Guangshuo Li
2026-04-14 1:28 ` Su Yue
2026-04-14 11:32 ` Guangshuo Li
2026-04-14 14:05 ` Su Yue
2026-04-19 4:42 ` 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=cdc869dc-ba1a-4cc2-a44c-3d147ca6bbbc@fnnas.com \
--to=yukuai@fnnas.com \
--cc=gregkh@suse.de \
--cc=lgs201920130244@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-raid@vger.kernel.org \
--cc=song@kernel.org \
--cc=stable@vger.kernel.org \
/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