Skip to contentSkip to conversation

um: virtio_uml: Fix use-after-free after put_device in probe

PATCH Superseded Miaoqian Lin 2 participants 2 messages Aug 4, 2025 – Aug 25, 2025 User-mode Linux (UML)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 um: virtio_uml: Fix use-after-free after put_device in probe

When register_virtio_device() fails in virtio_uml_probe(), the code sets vu_dev->registered = 1 even though the device was not successfully registered.
This can lead to use-after-free or other issues.

Fixes 04e5b1fb0183 ("um: virtio: Remove device on disconnect")
---
 arch/um/drivers/virtio_uml.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/um/drivers/virtio_uml.c +3 -1
index ad8d78fb1d9a..c402c4cc908a 100644
@@ -1250,8 +1250,10 @@ static int virtio_uml_probe(struct platform_device *pdev)
 	device_set_wakeup_capable(&vu_dev->vdev.dev, true);
 
 	rc = register_virtio_device(&vu_dev->vdev);
-	if (rc)
+	if (rc) {
 		put_device(&vu_dev->vdev.dev);
+		return rc;
+	}
 	vu_dev->registered = 1;
 	return rc;
 
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 17 lines · Miaoqian Lin

When register_virtio_device() fails in virtio_uml_probe(), the code sets vu_dev->registered = 1 even though the device was not successfully registered.
This can lead to use-after-free or other issues.

Fixes 04e5b1fb0183 ("um: virtio: Remove device on disconnect")
---
 arch/um/drivers/virtio_uml.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/um/drivers/virtio_uml.c +0 -0
index ad8d78fb1d9a..c402c4cc908a 100644
@@ -1250,8 +1250,10 @@ static int virtio_uml_probe(struct platform_device *pdev)
 	device_set_wakeup_capable(&vu_dev->vdev.dev, true);

arch/um/drivers/virtio_uml.c static int virtio_uml_probe(struct platform_device *pdev) · line 1259

Quoted 10 lines
arch/um/drivers/virtio_uml.c +3 -1
 
 	rc = register_virtio_device(&vu_dev->vdev);
-	if (rc)
+	if (rc) {
 		put_device(&vu_dev->vdev.dev);
+		return rc;
+	}
 	vu_dev->registered = 1;
 	return rc;
 

This should now statically 'return 0' at the end.

johannes