CVE-2026-143091: xen/privcmd: fix double free when an irqfd is shut down twice
In the Linux kernel, the following vulnerability has been resolved:
xen/privcmd: fix double free when an irqfd is shut down twice
irqfddeactivate() takes the irqfd off irqfdslist and queues irqfdshutdown(). queuework() is not a once-only gate: it refuses to enqueue a work item only while WORKSTRUCTPENDING is set, and processonework() clears that bit before it calls the work function. So nothing records that the shutdown work has already been queued, and nothing protects the window between the start of irqfdshutdown() and the kfree() at its end.
Two paths call irqfddeactivate() for the same irqfd:
- privcmdirqfddeassign(), from the PRIVCMDIRQFDFLAGDEASSIGN ioctl;
- irqfdwakeup(), with EPOLLHUP set, when the last reference to the eventfd file goes away, which runs wakeuppoll(&ctx->wqh, EPOLLHUP) from eventfdrelease().
irqfdslock serialises the two calls, but it does not make the second one a no-op, and eventfdctxfdget() takes a reference to the eventfdctx, not to the struct file, so the last fd can still be closed while the ioctl is running:
CPU0 CPU1
eventfdctxfdget() spinlock(irqfdslock) listdelinit(&kirqfd->list) queuework(&kirqfd->shutdown) close(fd) eventfdrelease() wakeuppoll(EPOLLHUP) irqfdwakeup() spinlock(irqfdslock) irqfddeactivate() again
If the work item has already started by then, its pending bit has been cleared and the second queuework() succeeds. irqfdshutdown() then runs twice, so eventfdctxremovewaitqueue(), eventfdctxput() and kfree() each hit the same object a second time; and when the second queuework() lands after the irqfd has been freed, the workqueue list operations write to freed memory.
virt/kvm/eventfd.c has the same two callers and has had this guard since the original irqfd support (721eecbf4fe99): irqfdwakeup() calls irqfddeactivate() only if irqfdisactive(). The comment there explains why that is enough: the other side deactivates the irqfd before it takes it off the waitqueue, and irqfdshutdown() needs the waitqueue lock, which this callback holds, so the irqfd cannot be freed under it.
Do the same here. listdelinit() leaves the list head empty and the irqfd stays off the list until kfree(), so it serves as a one-way "active" flag. The test is in irqfddeactivate() rather than in irqfdwakeup() because privcmdirqfddeassign() walks irqfdslist and can therefore never reach an inactive irqfd; only the wakeup path can, and a single test covers both callers.