Patch "virtio-mmio: don't break lifecycle of vm_dev" has been added to the 4.19-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    virtio-mmio: don't break lifecycle of vm_dev

to the 4.19-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     virtio-mmio-don-t-break-lifecycle-of-vm_dev.patch
and it can be found in the queue-4.19 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit a0fbedeefbd12ac6a8b6d1877f5f728bd21286b1
Author: Wolfram Sang <wsa+renesas@xxxxxxxxxxxxxxxxxxxx>
Date:   Thu Jun 29 14:05:26 2023 +0200

    virtio-mmio: don't break lifecycle of vm_dev
    
    [ Upstream commit 55c91fedd03d7b9cf0c5199b2eb12b9b8e95281a ]
    
    vm_dev has a separate lifecycle because it has a 'struct device'
    embedded. Thus, having a release callback for it is correct.
    
    Allocating the vm_dev struct with devres totally breaks this protection,
    though. Instead of waiting for the vm_dev release callback, the memory
    is freed when the platform_device is removed. Resulting in a
    use-after-free when finally the callback is to be called.
    
    To easily see the problem, compile the kernel with
    CONFIG_DEBUG_KOBJECT_RELEASE and unbind with sysfs.
    
    The fix is easy, don't use devres in this case.
    
    Found during my research about object lifetime problems.
    
    Fixes: 7eb781b1bbb7 ("virtio_mmio: add cleanup for virtio_mmio_probe")
    Signed-off-by: Wolfram Sang <wsa+renesas@xxxxxxxxxxxxxxxxxxxx>
    Message-Id: <20230629120526.7184-1-wsa+renesas@xxxxxxxxxxxxxxxxxxxx>
    Signed-off-by: Michael S. Tsirkin <mst@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
index d654e8953b6cb..07be3a374efbb 100644
--- a/drivers/virtio/virtio_mmio.c
+++ b/drivers/virtio/virtio_mmio.c
@@ -537,9 +537,8 @@ static void virtio_mmio_release_dev(struct device *_d)
 	struct virtio_device *vdev =
 			container_of(_d, struct virtio_device, dev);
 	struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev);
-	struct platform_device *pdev = vm_dev->pdev;
 
-	devm_kfree(&pdev->dev, vm_dev);
+	kfree(vm_dev);
 }
 
 /* Platform device */
@@ -550,7 +549,7 @@ static int virtio_mmio_probe(struct platform_device *pdev)
 	unsigned long magic;
 	int rc;
 
-	vm_dev = devm_kzalloc(&pdev->dev, sizeof(*vm_dev), GFP_KERNEL);
+	vm_dev = kzalloc(sizeof(*vm_dev), GFP_KERNEL);
 	if (!vm_dev)
 		return -ENOMEM;
 



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux