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

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


  • To: Jürgen Groß <jgross@xxxxxxxx>
  • From: Wong Steve <shyckless@xxxxxxxxx>
  • Date: Fri, 20 Nov 2026 03:31:53 +0800
  • Arc-authentication-results: i=1; mx.google.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=zHELh1wvQ9nrwWZUArifTWwLGXrX5lfqWf4Gv/ulNME=; fh=a1Kfrk7nuDrlJfijhICnpfuCCPB9yKBd83Udh67O3II=; b=cMCUWzEbrHl8g4/FTkYZQK0legvk78dAwoUVIK/gJaGEy6bs0S/T7axWuRx7WPQvHN F6Gc5OtM49ocqdRuC0NScipYKYxUy8unobxWA0qnxdtmHiTs2v9bHkkriHwK4mYba5xs I4pTa1/FCRNFl0Yr7Rc6rQmrAHoNmsOit+aaSECbSsNIMuSci8lexGFetKdXpxLJytif wpqW2iQQBw8GnsCe7+K+42jC076VZBxijZ2DJCowELbNJEgJxdH4y1O7zm3A8FmthBQP n7b0DImZpSnYxCjBYKSilSYwaOcmPx2MHqN7lHwt+niONBaYIm12Jx7j0GnXdF4dZ7la uSbg==; darn=lists.xenproject.org
  • Arc-seal: i=1; a=rsa-sha256; t=1795116726; cv=none; d=google.com; s=arc-20260327; b=X4h2oaX/CcWush2Es3/QHO/bPoBC+xf/k7dQ2MbWX9/FK1kFORuTuRj+5x2Gp4FsUr S96hEj6GUo+WadIufO3Qy26NTaKmjsMVu1xkHzozA70/PI7jQAyuK1JSFR8HzLOzdOng Ae6t8ddlk2pl75ZA1VHfyyHVwHePKl2RVymjJDU1r18uonkz3PcDBcCBap81z3pfAGmb HfsxuQEk8yliRELuYqO58UxwmK4CxouonhFMgXXSK/Iu5mA84XYAh/WZ/MJP5h/IMVMK QvgStKVx44Hf5SiRQwCoyLDRiVUdrhJEw4d/elWW3PtpOFn4ElFh/WVAKX10xPej/1A6 QyIw==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=20260707 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To:References:MIME-Version"
  • Cc: Jarkko Sakkinen <jarkko@xxxxxxxxxx>, jgg@xxxxxxxx, linux-kernel@xxxxxxxxxxxxxxx, sstabellini@xxxxxxxxxx, linux-integrity@xxxxxxxxxxxxxxx, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Thu, 19 Nov 2026 19:54:56 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Hi Juergen, Jarkko,

Thanks Juergen, that explains why nobody has run into it: with the
stubdom backend the frontend never sees Closing or Closed, so this
path is only reached with a backend that does close. I agree the
normal state machine should stay.

So with today's backend this is latent. Jarkko, if you prefer, I can
send a v2 that says so in the commit message and drops the
Cc: stable.

Thanks,
Suyuan

Jürgen Groß <jgross@xxxxxxxx> 于2026年11月20日周五 00:32写道:
>
> On 19.11.26 17:30, Jarkko Sakkinen wrote:
> > On Thu, Nov 19, 2026 at 04:35:02PM +0100, Jürgen Groß wrote:
> >> On 19.11.26 16:20, Jarkko Sakkinen wrote:
> >>> On Thu, Nov 19, 2026 at 11:20:33AM +0000, Suyuan Wang via B4 Relay wrote:
> >>>> 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);
> >>>
> >>> Not a NAK but makes me wonder why this has not hit the wall ever.
> >>>
> >>> I.e. "feeling confused".
> >> Is there any vtpm backend other than the stubdom based one?
> >>
> >> If not, then it is quite easy: this backend never switches state to
> >> XenbusStateClosing or XenbusStateClosed.
> >>
> >>
> >> Juergen
> >
> > Should it be removed use the default-fallback?
> I don't think so.
>
> There might be other backends in future, so following the normal Xen PV-device
> state machine should be kept.
>
>
> Juergen



 


Rackspace

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