• Wolfram Sang's avatar
    virtio-mmio: don't break lifecycle of vm_dev · 55c91fed
    Wolfram Sang authored
    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: 7eb781b1 ("virtio_mmio: add cleanup for virtio_mmio_probe")
    Signed-off-by: default avatarWolfram Sang <wsa+renesas@sang-engineering.com>
    Message-Id: <20230629120526.7184-1-wsa+renesas@sang-engineering.com>
    Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
    55c91fed
virtio_mmio.c 21.4 KB