Re: [PATCH v1] virt: acrn: Don't free a VM the hypervisor refused to destroy

From: Yuho Choi

Date: Mon Nov 23 2026 - 21:34:27 EST


On Fri, Nov 20, 2026 at 08:01:14AM +0000, Li, Fei1 wrote:
> Hi Yuho,
>
> Thanks for fixing this UAF issue!

Thank you for the review and suggestions.

> Besides your current change, I suggest:
>
> 1. In acrn_dev_release(), try calling hcall_pause_vm(vm->vmid) before
> acrn_vm_destroy(vm) when vm->vmid is valid and not yet marked as
> destroyed.

That makes sense. If the device model exits without pausing the
VM, the hypervisor refuses to destroy it and the VM ends up leaked.
Pausing it first in acrn_dev_release() would let it be cleaned up properly
in that case.

I'll make the pause best-effort and still attempt to destroy the VM if
it fails.
If the destroy also fails, the VM will be retained as in v1.

> 2. Call try_module_get(THIS_MODULE) in acrn_vm_create() (and roll it
> back on failure), paired with module_put(THIS_MODULE) when
> acrn_vm_destroy() succeeds. This keeps the module pinned when a VM
> cannot be destroyed and remains in memory, preventing rmmod from
> triggering a kernel crash via active ioeventfd kthreads or irqfd
> callbacks under CONFIG_ACRN_HSM=m.

Good point. I had missed the module unload case.

Since acrn_vm_create() is called through an ioctl and acrn_fops.owner
is already set to THIS_MODULE, the caller holds a module reference.
Could we instead use __module_get(THIS_MODULE) at the end of
acrn_vm_create(), after successful initialization? That would avoid
having to roll back the module reference on the creation failure paths.

Unless you prefer try_module_get(), I'll go with __module_get() and
incorporate both changes in v2.