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

[PATCH] tpm: xen-tpmfront: fix use-after-free in backend_changed()


  • To: jgg@xxxxxxxx, jarkko@xxxxxxxxxx
  • From: Suyuan Wang via B4 Relay <devnull+shyckless.gmail.com@xxxxxxxxxx>
  • Date: Thu, 19 Nov 2026 11:20:33 +0000
  • Arc-authentication-results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77
  • Arc-message-signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1795087234; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:X-B4-Tracking:X-Change-ID:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To; bh=HxTh5QEOxLCvDecXq3k9qIqzQesIJHxSTR2i+oLJhDQ=; b=bX3YuFZXQJMR0X/FHcRfKcXKrZb/WE7vC7wv5e3SjqJjiUHbyGn9YJ0sLPVtPWLs4jX1 lTAptZvbwzpnk4qhXSEhfH9GA17ja50XqhgUFIAppUeiO9Ucn8aJKPygMWlwUj+btdPVK tITr4GcXkgb5ViED0lISuuZYf12pptBTzirudvlHUk3NFEShr1f2bgnRGcfaWpXOyUaNn Q58EGEesPEFZRGWmm2LFnUbSI6z73yfd7qgSbjdrfSAgj95hlXldQ7vG4XWpjg/vwzNzO Vly7xxxYvYt+XRIQ0O5006H7gu8yK0djVXf4WOHUs4DWYT+gbLKLdqnFm/Tw+/oLh/g==
  • Arc-seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1795087234; b=NBtDNZHQRdvXS5/S7NeuK/A+VW00YhVtEaK32ykzJG/J+V45CDvrbhu/+GlmrZwKH9cZ gOm3ofoVAd0c+woCunLIxfYA5mvFO+YYM5zYjiak5VROFuwQCbE4d7kEyZZ6s+bq4iGxB HzxtVqBaufzNkDoHXcfRq0rb0ovZAhrFFfVz7tUkehBLDE/970dARLAWgj18cYv6uRLNn B9nx74U/e3IflANmKrzghkiF/1cvW7ocIn818fpmxkLY5o5aM3KIuF7fTWz8N00OyDpVn GpUo2Utq5hbX6/ZlhwjIAWkOhVexBO+E7Ex1sVHMAHbtmFshCbNljZxM7ySGQq+kCPw==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=k20260515 header.d=kernel.org header.i="@kernel.org" header.h="From:Date:Subject:To:Cc:Reply-To"
  • Authentication-results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77
  • Cc: linux-kernel@xxxxxxxxxxxxxxx, jgross@xxxxxxxx, sstabellini@xxxxxxxxxx, linux-integrity@xxxxxxxxxxxxxxx, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Thu, 19 Nov 2026 11:20:45 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

From: Suyuan Wang <stevewong@xxxxxxxxxxx>

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.

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")
Cc: stable@xxxxxxxxxxxxxxx
Co-developed-by: Kaixuan Li <kaixuan.li@xxxxxxxxxx>
Signed-off-by: Kaixuan Li <kaixuan.li@xxxxxxxxxx>
Signed-off-by: Suyuan Wang <stevewong@xxxxxxxxxxx>
---
Compile tested on x86_64 (W=1, no new warnings). Not run with a Xen vTPM
backend.
---
 drivers/char/tpm/xen-tpmfront.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/char/tpm/xen-tpmfront.c b/drivers/char/tpm/xen-tpmfront.c
index 3c0cce57c4ae..1be925cca535 100644
--- a/drivers/char/tpm/xen-tpmfront.c
+++ b/drivers/char/tpm/xen-tpmfront.c
@@ -397,8 +397,11 @@ static void backend_changed(struct xenbus_device *dev,
 
        case XenbusStateClosing:
        case XenbusStateClosed:
+               /* device_unregister() can drop the last reference to dev */
+               get_device(&dev->dev);
                device_unregister(&dev->dev);
                xenbus_frontend_closed(dev);
+               put_device(&dev->dev);
                break;
        default:
                break;







 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.