* [PATCH] s390: cmf: fix use-after-free in enable_cmf
@ 2020-11-20 7:48 Qinglang Miao
2020-11-20 8:00 ` Cornelia Huck
0 siblings, 1 reply; 2+ messages in thread
From: Qinglang Miao @ 2020-11-20 7:48 UTC (permalink / raw)
To: Vineeth Vijayan, Peter Oberparleiter, Heiko Carstens,
Vasily Gorbik, Christian Borntraeger
Cc: linux-s390, linux-kernel, Qinglang Miao
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);
+ return ret;
+ }
out_unlock:
device_unlock(&cdev->dev);
return ret;
--
2.23.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] s390: cmf: fix use-after-free in enable_cmf
2020-11-20 7:48 [PATCH] s390: cmf: fix use-after-free in enable_cmf Qinglang Miao
@ 2020-11-20 8:00 ` Cornelia Huck
0 siblings, 0 replies; 2+ messages in thread
From: Cornelia Huck @ 2020-11-20 8:00 UTC (permalink / raw)
To: Qinglang Miao
Cc: Vineeth Vijayan, Peter Oberparleiter, Heiko Carstens,
Vasily Gorbik, Christian Borntraeger, linux-s390, linux-kernel
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;
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-11-20 8:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-20 7:48 [PATCH] s390: cmf: fix use-after-free in enable_cmf Qinglang Miao
2020-11-20 8:00 ` Cornelia Huck
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).