On Thu, Nov 19, 2026 at 09:36:02PM +0000, Suyuan Wang via B4 Relay wrote: > From: Suyuan Wang <[email protected]> > > When the backend moves to Closing or Closed, backend_changed() > unregisters the device and then keeps using it: > > device_unregister(&dev->dev); > xenbus_frontend_closed(dev); > > The xenbus watch callback that calls backend_changed() does not hold a > reference to the device. The tpm_chip registered by xen-tpmfront has dev > as its parent and holds a reference to it, but tpmfront_remove() drops > that reference when it unregisters the chip. So device_unregister() can > release the last reference and free the xenbus_device, and > xenbus_frontend_closed(dev) then accesses freed memory. > > The stubdom based vTPM backend, the only one in use today, never > switches to Closing or Closed, so this path is not reached with it. It > is reached with any backend that follows the normal xenbus state > machine on shutdown. > > Take a temporary reference before unregistering and drop it after > xenbus_frontend_closed(). This keeps dev alive for the last access and > keeps the existing order, in which TPM operations are stopped before > the frontend is marked Closed. > > Found with a static analysis tool and checked by hand. > > Fixes: e2683957fb26 ("drivers/tpm: add xen tpmfront interface")
This should not have a fixes tag. Br, Jarkko
