mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] s390: cio: fix use-after-free in ccw_device_destroy_console
@ 2020-12-01  6:31 Qinglang Miao
  2020-12-01 10:19 ` Cornelia Huck
  2020-12-02  9:30 ` Vineeth Vijayan
  0 siblings, 2 replies; 3+ messages in thread
From: Qinglang Miao @ 2020-12-01  6:31 UTC (permalink / raw)
  To: Cornelia Huck, Vineeth Vijayan, Peter Oberparleiter,
	Heiko Carstens, Vasily Gorbik, Christian Borntraeger
  Cc: linux-s390, linux-kernel, Qinglang Miao

put_device calls release function which do kfree() inside.
So following use of sch&cdev would cause use-after-free bugs.

Fix these by simply adjusting the position of put_device.

Fixes: 37db8985b211 ("s390/cio: add basic protected virtualization support")
Reported-by: Hulk Robot <hulkci@huawei.com>
Suggested-by: Cornelia Huck <cohuck@redhat.com>
Signed-off-by: Qinglang Miao <miaoqinglang@huawei.com>
---
 This patch is indeed a v2 of older one. Considering that the
 patch's name has changed, I think a normal prefix 'PATCH' is
 better.

 drivers/s390/cio/device.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/s390/cio/device.c b/drivers/s390/cio/device.c
index b29fe8d50..33280ca18 100644
--- a/drivers/s390/cio/device.c
+++ b/drivers/s390/cio/device.c
@@ -1664,10 +1664,10 @@ void __init ccw_device_destroy_console(struct ccw_device *cdev)
 	struct io_subchannel_private *io_priv = to_io_private(sch);
 
 	set_io_private(sch, NULL);
-	put_device(&sch->dev);
-	put_device(&cdev->dev);
 	dma_free_coherent(&sch->dev, sizeof(*io_priv->dma_area),
 			  io_priv->dma_area, io_priv->dma_area_dma);
+	put_device(&sch->dev);
+	put_device(&cdev->dev);
 	kfree(io_priv);
 }
 
-- 
2.23.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] s390: cio: fix use-after-free in ccw_device_destroy_console
  2020-12-01  6:31 [PATCH] s390: cio: fix use-after-free in ccw_device_destroy_console Qinglang Miao
@ 2020-12-01 10:19 ` Cornelia Huck
  2020-12-02  9:30 ` Vineeth Vijayan
  1 sibling, 0 replies; 3+ messages in thread
From: Cornelia Huck @ 2020-12-01 10:19 UTC (permalink / raw)
  To: Qinglang Miao
  Cc: Vineeth Vijayan, Peter Oberparleiter, Heiko Carstens,
	Vasily Gorbik, Christian Borntraeger, linux-s390, linux-kernel

On Tue, 1 Dec 2020 14:31:50 +0800
Qinglang Miao <miaoqinglang@huawei.com> wrote:

> put_device calls release function which do kfree() inside.
> So following use of sch&cdev would cause use-after-free bugs.
> 
> Fix these by simply adjusting the position of put_device.
> 
> Fixes: 37db8985b211 ("s390/cio: add basic protected virtualization support")
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Suggested-by: Cornelia Huck <cohuck@redhat.com>
> Signed-off-by: Qinglang Miao <miaoqinglang@huawei.com>
> ---
>  This patch is indeed a v2 of older one. Considering that the
>  patch's name has changed, I think a normal prefix 'PATCH' is
>  better.
> 
>  drivers/s390/cio/device.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Cornelia Huck <cohuck@redhat.com>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] s390: cio: fix use-after-free in ccw_device_destroy_console
  2020-12-01  6:31 [PATCH] s390: cio: fix use-after-free in ccw_device_destroy_console Qinglang Miao
  2020-12-01 10:19 ` Cornelia Huck
@ 2020-12-02  9:30 ` Vineeth Vijayan
  1 sibling, 0 replies; 3+ messages in thread
From: Vineeth Vijayan @ 2020-12-02  9:30 UTC (permalink / raw)
  To: Qinglang Miao, Cornelia Huck, Vineeth Vijayan,
	Peter Oberparleiter, Heiko Carstens, Vasily Gorbik,
	Christian Borntraeger
  Cc: linux-s390, linux-kernel

Thank you.With a very minor modification in the commit-message,

Reviewed-by: Vineeth Vijayan <vneethv@linux.ibm.com>

I will push this and Vasliy/Heiko will take this up for the next 
s390-tree upstream-release.


On 12/1/20 7:31 AM, Qinglang Miao wrote:
> put_device calls release function which do kfree() inside.
> So following use of sch&cdev would cause use-after-free bugs.
>
> Fix these by simply adjusting the position of put_device.

Modified the commit-message as below. Just for the clarification.

--

Use of sch->dev reference after the put_device() call could trigger
the use-after-free bugs.

Fix this by simply adjusting the position of put_device.
--
>
> Fixes: 37db8985b211 ("s390/cio: add basic protected virtualization support")
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Suggested-by: Cornelia Huck <cohuck@redhat.com>
> Signed-off-by: Qinglang Miao <miaoqinglang@huawei.com>
> ---
>   This patch is indeed a v2 of older one. Considering that the
>   patch's name has changed, I think a normal prefix 'PATCH' is
>   better.
>
>   drivers/s390/cio/device.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/s390/cio/device.c b/drivers/s390/cio/device.c
> index b29fe8d50..33280ca18 100644
> --- a/drivers/s390/cio/device.c
> +++ b/drivers/s390/cio/device.c
> @@ -1664,10 +1664,10 @@ void __init ccw_device_destroy_console(struct ccw_device *cdev)
>   	struct io_subchannel_private *io_priv = to_io_private(sch);
>   
>   	set_io_private(sch, NULL);
> -	put_device(&sch->dev);
> -	put_device(&cdev->dev);
>   	dma_free_coherent(&sch->dev, sizeof(*io_priv->dma_area),
>   			  io_priv->dma_area, io_priv->dma_area_dma);
> +	put_device(&sch->dev);
> +	put_device(&cdev->dev);
>   	kfree(io_priv);
>   }
>   

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-12-02  9:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-01  6:31 [PATCH] s390: cio: fix use-after-free in ccw_device_destroy_console Qinglang Miao
2020-12-01 10:19 ` Cornelia Huck
2020-12-02  9:30 ` Vineeth Vijayan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome