Skip to contentSkip to conversation

s390: cio: fix use-after-free in ccw_device_destroy_console

PATCH In review Qinglang Miao 3 participants 3 messages Dec 1, 2020 – Dec 2, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 s390: cio: fix use-after-free in ccw_device_destroy_console

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")

---
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(-)
drivers/s390/cio/device.c +2 -2
index b29fe8d50..33280ca18 100644
@@ -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);
 }
 
Signature · 1 line
2.23.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · On Tue, 1 Dec 2020 14:31:50 +0800 Qinglang Miao <[email protected]> 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")
Quoted 7 lines

---
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 on v1 1/1
#2 lore raw
In reply to Qinglang Miao

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

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

Quoted 4 lines · 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.

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. --

Quoted 30 lines
Fixes 37db8985b211 ("s390/cio: add basic protected virtualization support")

---
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(-)
drivers/s390/cio/device.c +2 -2
index b29fe8d50..33280ca18 100644
@@ -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);
  }