From: Corey Minyard <cminyard@mvista.com>
To: Yang Yingliang <yangyingliang@huawei.com>
Cc: arnd@arndb.de, gregkh@linuxfoundation.org,
openipmi-developer@lists.sourceforge.net,
linux-kernel@vger.kernel.org, stable@vger.kernel.org,
qiaonuohan@huawei.com
Subject: Re: [PATCH] ipmi_si: fix use-after-free of resource->name
Date: Fri, 25 Jan 2019 14:35:24 -0600 [thread overview]
Message-ID: <20190125203524.GA20851@minyard.net> (raw)
In-Reply-To: <1548383459-38420-1-git-send-email-yangyingliang@huawei.com>
On Fri, Jan 25, 2019 at 10:30:59AM +0800, Yang Yingliang wrote:
> When we excute the following commands, we got oops
> rmmod ipmi_si
> cat /proc/ioports
>
snip...
>
> If io_setup is called successful in try_smi_init() but try_smi_init()
> goes out_err before calling ipmi_register_smi(), so ipmi_unregister_smi()
> will not be called while removing module. It leads to the resource that
> allocated in io_setup() can not be freed, but the name(DEVICE_NAME) of
> resource is freed while removing the module. It causes use-after-free
> when cat /proc/ioports.
>
> Fix this by calling shutdown_smi() while removing the module and don't
> call release_region() if request_region() is not called to avoid error
> prints.
>
> Fixes: 93c303d2045b ("ipmi_si: Clean up shutdown a bit")
> Cc: stable@vger.kernel.org
> Reported-by: NuoHan Qiao <qiaonuohan@huawei.com>
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---
> drivers/char/ipmi/ipmi_si_intf.c | 2 ++
> drivers/char/ipmi/ipmi_si_port_io.c | 3 +++
> 2 files changed, 5 insertions(+)
>
> diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
> index dc8603d..635e98a 100644
> --- a/drivers/char/ipmi/ipmi_si_intf.c
> +++ b/drivers/char/ipmi/ipmi_si_intf.c
> @@ -2235,6 +2235,8 @@ static void cleanup_one_si(struct smi_info *smi_info)
>
> if (smi_info->intf)
> ipmi_unregister_smi(smi_info->intf);
> + else
> + shutdown_smi(smi_info);
This is completely the wrong way to fix this. The general principle is
that a function cleans up for itself if it returns an error. If you
add hacks other places for a function failing you end up with a mess.
I think the right way to fix this is to add something like:
if (rv && new_smi->io.io_size && smi_info->io.io_cleanup) {
smi_info->io.io_cleanup(&smi_info->io);
smi_info->io.io_cleanup = NULL;
}
at the end of try_smi_init().
-corey
>
> if (smi_info->pdev) {
> if (smi_info->pdev_registered)
> diff --git a/drivers/char/ipmi/ipmi_si_port_io.c b/drivers/char/ipmi/ipmi_si_port_io.c
> index ef6dffc..0c46a3f 100644
> --- a/drivers/char/ipmi/ipmi_si_port_io.c
> +++ b/drivers/char/ipmi/ipmi_si_port_io.c
> @@ -53,6 +53,9 @@ static void port_cleanup(struct si_sm_io *io)
> unsigned int addr = io->addr_data;
> int idx;
>
> + if (io->regsize != 1 && io->regsize != 2 && io->regsize != 4)
> + return;
> +
> if (addr) {
> for (idx = 0; idx < io->io_size; idx++)
> release_region(addr + idx * io->regspacing,
> --
> 1.8.3
>
>
next prev parent reply other threads:[~2019-01-25 20:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-25 2:30 [PATCH] ipmi_si: fix use-after-free of resource->name Yang Yingliang
2019-01-25 20:35 ` Corey Minyard [this message]
2019-01-26 1:41 ` Yang Yingliang
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=20190125203524.GA20851@minyard.net \
--to=cminyard@mvista.com \
--cc=arnd@arndb.de \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=openipmi-developer@lists.sourceforge.net \
--cc=qiaonuohan@huawei.com \
--cc=stable@vger.kernel.org \
--cc=yangyingliang@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;
as well as URLs for NNTP newsgroup(s).