From: Corey Minyard <minyard@acm.org>
To: Yang Yingliang <yangyingliang@huawei.com>
Cc: cminyard@mvista.com, 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 v3] ipmi_si: fix use-after-free of resource->name
Date: Mon, 28 Jan 2019 07:53:59 -0600 [thread overview]
Message-ID: <20190128135359.GB4979@minyard.net> (raw)
In-Reply-To: <1548644934-36452-1-git-send-email-yangyingliang@huawei.com>
On Mon, Jan 28, 2019 at 11:08:54AM +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 io_cleanup() while try_smi_init() goes to out_err.
> and don't call io_cleanup() until io_setup() returns successful to avoid
> warning prints.
Thanks a bunch for working on this. Fix is in my next tree now, if it
is stable in there then I will send up to Linus.
-corey
>
> Fixes: 93c303d2045b ("ipmi_si: Clean up shutdown a bit")
> Cc: stable@vger.kernel.org
> Reported-by: NuoHan Qiao <qiaonuohan@huawei.com>
> Suggested-by: Corey Minyard <cminyard@mvista.com>
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---
> drivers/char/ipmi/ipmi_si_intf.c | 5 +++++
> drivers/char/ipmi/ipmi_si_mem_io.c | 5 +++--
> drivers/char/ipmi/ipmi_si_port_io.c | 5 +++--
> 3 files changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
> index dc8603d..f1b9fda 100644
> --- a/drivers/char/ipmi/ipmi_si_intf.c
> +++ b/drivers/char/ipmi/ipmi_si_intf.c
> @@ -2085,6 +2085,11 @@ static int try_smi_init(struct smi_info *new_smi)
> WARN_ON(new_smi->io.dev->init_name != NULL);
>
> out_err:
> + if (rv && new_smi->io.io_cleanup) {
> + new_smi->io.io_cleanup(&new_smi->io);
> + new_smi->io.io_cleanup = NULL;
> + }
> +
> kfree(init_name);
> return rv;
> }
> diff --git a/drivers/char/ipmi/ipmi_si_mem_io.c b/drivers/char/ipmi/ipmi_si_mem_io.c
> index fd0ec8d..7558361 100644
> --- a/drivers/char/ipmi/ipmi_si_mem_io.c
> +++ b/drivers/char/ipmi/ipmi_si_mem_io.c
> @@ -81,8 +81,6 @@ int ipmi_si_mem_setup(struct si_sm_io *io)
> if (!addr)
> return -ENODEV;
>
> - io->io_cleanup = mem_cleanup;
> -
> /*
> * Figure out the actual readb/readw/readl/etc routine to use based
> * upon the register size.
> @@ -141,5 +139,8 @@ int ipmi_si_mem_setup(struct si_sm_io *io)
> mem_region_cleanup(io, io->io_size);
> return -EIO;
> }
> +
> + io->io_cleanup = mem_cleanup;
> +
> return 0;
> }
> diff --git a/drivers/char/ipmi/ipmi_si_port_io.c b/drivers/char/ipmi/ipmi_si_port_io.c
> index ef6dffc..03924c3 100644
> --- a/drivers/char/ipmi/ipmi_si_port_io.c
> +++ b/drivers/char/ipmi/ipmi_si_port_io.c
> @@ -68,8 +68,6 @@ int ipmi_si_port_setup(struct si_sm_io *io)
> if (!addr)
> return -ENODEV;
>
> - io->io_cleanup = port_cleanup;
> -
> /*
> * Figure out the actual inb/inw/inl/etc routine to use based
> * upon the register size.
> @@ -109,5 +107,8 @@ int ipmi_si_port_setup(struct si_sm_io *io)
> return -EIO;
> }
> }
> +
> + io->io_cleanup = port_cleanup;
> +
> return 0;
> }
> --
> 1.8.3
>
>
prev parent reply other threads:[~2019-01-28 13:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-28 3:08 [PATCH v3] ipmi_si: fix use-after-free of resource->name Yang Yingliang
2019-01-28 13:53 ` Corey Minyard [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=20190128135359.GB4979@minyard.net \
--to=minyard@acm.org \
--cc=arnd@arndb.de \
--cc=cminyard@mvista.com \
--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).