From: Greg KH <gregkh@linuxfoundation.org>
To: Yufen Yu <yuyufen@huawei.com>
Cc: linux-kernel@vger.kernel.org, rafael@kernel.org, axboe@kernel.dk,
hch@lst.de, linux-block@vger.kernel.org
Subject: Re: [PATCH] drivers core: don't do anything in device_del() when device_add() fail
Date: Fri, 2 Apr 2021 17:06:25 +0200 [thread overview]
Message-ID: <YGcy8amoQiYX48xL@kroah.com> (raw)
In-Reply-To: <20210401130138.2164928-1-yuyufen@huawei.com>
On Thu, Apr 01, 2021 at 09:01:38AM -0400, Yufen Yu wrote:
> Recently, our syzbot test reported NULL pointer dereference in
> device_del() by injecting memory allocation fail in device_add().
Don't do that :)
> For now, callers of device_add(), such as add_disk(), may ignore
> device_add()'s fail and go on working.
Please fix up those users, if device_add() fails there is no need to
call device_del().
> In unregister path, it will
> call device_del() from del_gendisk(). That can cause various NULL
> pointer dereference, including dev->p is NULL in kill_device(),
> 'name' is NULL in sysfs_remove_link(), kobj->sd is 'NULL' when call
> dpm_sysfs_remove(), and so on.
>
> To avoid these kernel panic, we call device_del() only when device_add()
> is success.
As Rafael said, that's not what you are doing here, so even if I wanted
to take this patch, I can't.
>
> Signed-off-by: Yufen Yu <yuyufen@huawei.com>
> ---
> drivers/base/core.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index f29839382f81..a10ec5dbc577 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -3380,6 +3380,9 @@ void device_del(struct device *dev)
> struct class_interface *class_intf;
> unsigned int noio_flag;
>
> + if (!dev->p)
> + return;
Also, this isn't a good test as it's not obvious what you are trying to
check for here.
thanks,
greg k-h
prev parent reply other threads:[~2021-04-02 15:06 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-01 13:01 Yufen Yu
2021-04-01 13:31 ` Rafael J. Wysocki
2021-04-02 15:06 ` Greg KH [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=YGcy8amoQiYX48xL@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=axboe@kernel.dk \
--cc=hch@lst.de \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=yuyufen@huawei.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®