From: Cornelia Huck <cohuck@redhat.com>
To: Qinglang Miao <miaoqinglang@huawei.com>
Cc: Vineeth Vijayan <vneethv@linux.ibm.com>,
Peter Oberparleiter <oberpar@linux.ibm.com>,
Heiko Carstens <hca@linux.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>,
Christian Borntraeger <borntraeger@de.ibm.com>,
<linux-s390@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] s390: cmf: fix use-after-free in enable_cmf
Date: Fri, 20 Nov 2020 09:00:00 +0100 [thread overview]
Message-ID: <20201120090000.5ac4b5b8.cohuck@redhat.com> (raw)
In-Reply-To: <20201120074850.31609-1-miaoqinglang@huawei.com>
On Fri, 20 Nov 2020 15:48:50 +0800
Qinglang Miao <miaoqinglang@huawei.com> wrote:
> kfree(cdev) is called in put_device in the error branch. So that
> device_unlock(&cdev->dev) would raise a use-after-free bug. In fact,
> there's no need to call device_unlock after put_device.
>
> Fix it by adding simply return after put_device.
>
> Fixes: a6ef15652d26 ("s390/cio: fix use after free in cmb processing")
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Qinglang Miao <miaoqinglang@huawei.com>
> ---
> drivers/s390/cio/cmf.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/s390/cio/cmf.c b/drivers/s390/cio/cmf.c
> index 72dd2471e..e95ca476f 100644
> --- a/drivers/s390/cio/cmf.c
> +++ b/drivers/s390/cio/cmf.c
> @@ -1149,9 +1149,12 @@ int enable_cmf(struct ccw_device *cdev)
> sysfs_remove_group(&cdev->dev.kobj, cmbops->attr_group);
> cmbops->free(cdev);
> }
> +
> out:
> - if (ret)
> + if (ret) {
> put_device(&cdev->dev);
The put_device() here undoes a get_device() further up in the function.
There is at least one more reference remaining, held by the caller of
enable_cmf(). Returning here would actually introduce a bug (missing
unlock).
> + return ret;
> + }
> out_unlock:
> device_unlock(&cdev->dev);
> return ret;
prev parent reply other threads:[~2020-11-20 8:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-20 7:48 Qinglang Miao
2020-11-20 8:00 ` Cornelia Huck [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=20201120090000.5ac4b5b8.cohuck@redhat.com \
--to=cohuck@redhat.com \
--cc=borntraeger@de.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=miaoqinglang@huawei.com \
--cc=oberpar@linux.ibm.com \
--cc=vneethv@linux.ibm.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®