From nobody Thu Sep 03 03:53:25 2026 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hb5Ky03TBz6qW1B for ; Thu, 03 Sep 2026 03:53:26 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hb5Kx4XMGz3nD2 for ; Thu, 03 Sep 2026 03:53:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1788407605; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=gHeWURjXXrziMfpfjJ6ibIiXwRcjTpBO12MHe9FZDFo=; b=hIllBzgtM4hHysxtIv4iD0Ejh93QcZox7LxcwOz0GzqecqYRbestKW8FnGJfanN0Xxfdoc cEEF1tkZLDktkJ7y1gM+ZDnV1ZyNvwNI1cM6DY7X3ryH0X2W/CYU7ircigy9XxB/pEoXAT +wd8tpioNZ7g9dLk28iyHnivCx6VInJusra/J8qdno36HK8+A349PC2sxl1o40JtryI7U/ WHBShuY9URdlK5/XRdbubrZcHY4Le4qIIPoD8Jylu/Iw9+u7rUXLoMtVJy581DpRb+C1xq cLUzEnPt2Hlb8/jUisVYlf2RSmYAj4DdQxklT0d9geEcWhAz4ahqqRgXE7g0Qw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1788407605; a=rsa-sha256; cv=none; b=Kf2+V7oTmOk1Wpw6laiVl2AWulmesyxLwkN8mZ3sAAPQWJSZPomKlXwOtuXmKORMDIyfKC ftsYlC2EGsJ2kDxMsIVSpq+vqsiKQ7EIm/jqWQFLuVfq5CH+H9NoyyI0KdJnjQZ+qR3IuQ AQaM8DYMpkuUBCjoFpq4+xy8K03JrF/2OD7F2Eaan+lqwg0X+Mo+IlbEENxp5jPoxh2vC5 lhq4c2n7CGEnkvc2lpcU4exlL8ZOLEp1h5Mz1doF68NTFYrLpolc2kdqRMO469XrpaLhUh iFtCFtZtzcNJ3ivZgvuuC8E0Nw1SzDexen9ddPZXUsLe5u6O4AaUmBToPUxa3Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1788407605; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=gHeWURjXXrziMfpfjJ6ibIiXwRcjTpBO12MHe9FZDFo=; b=EUMHZ111es7bc9JgJdvikeFveRZW9mEufeNQ0n+XMgTUawgWIPWO8OJh4x5u47DeAOUjUv D58ztwNHCXSS90Cjiof19IEaBQ2YINol4plWngJnnkoqj2oPzbNtObA8KndDzCYMb4TB94 Bs5UTKS87ymDBNUj/G5rRbtnqE9dHmVAG7zL3UdVKQP7ryoz051h8AA+dzxzVH+gyNn/yY vCyzcmdklyI1ebp6W1I2q+9BiwdDQLi1Duug+Pz+A+ae+1GMrQdGzvYHMMu6/LwToKBjo6 vSsRArKdy/FI1G3sCUxDw1Mg64N6H/tVFreIaTtJ35ERFX+dU674Mh2D7sbwrg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hb5Kx3Fd5z1BwB for ; Thu, 03 Sep 2026 03:53:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 37fa8 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 03 Sep 2026 03:53:25 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kevin Bowling Subject: git: a0da653aaeae - main - tpm20: Initialize common state before testing TIS interrupts List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kbowling X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a0da653aaeae313479f2ab37d0faca483f530fa6 Auto-Submitted: auto-generated Date: Thu, 03 Sep 2026 03:53:25 +0000 Message-Id: <6a98ef35.37fa8.48a698bb@gitrepo.freebsd.org> The branch main has been updated by kbowling: URL: https://cgit.FreeBSD.org/src/commit/?id=a0da653aaeae313479f2ab37d0faca483f530fa6 commit a0da653aaeae313479f2ab37d0faca483f530fa6 Author: Kevin Bowling AuthorDate: 2026-08-26 10:51:58 +0000 Commit: Kevin Bowling CommitDate: 2026-09-03 03:53:02 +0000 tpm20: Initialize common state before testing TIS interrupts The TIS attach path tested its interrupt by transmitting GetRandom before tpm20_init() allocated the internal command buffer. A TPM2 FIFO device with a usable IRQ could therefore dereference a null internal_priv. Initialize the common TPM2 state before running the interrupt test. Make common cleanup safe for partially initialized devices and leave cleanup to the attachment after tpm20_init() fails, avoiding duplicate release of the lock, command buffer, and random-source state. Clear the IRQ resource pointer after releasing it when interrupt handler setup fails so the later polling-mode detach does not release it twice. Free the internal command allocation through its object pointer rather than relying on its embedded buffer being the first structure member. Reviewed by: kevans MFC after: 2 weeks Sponsored by: BBOX.io Differential Revision: https://reviews.freebsd.org/D59196 --- sys/dev/tpm/tpm20.c | 19 ++++++++++++++----- sys/dev/tpm/tpm20.h | 1 + sys/dev/tpm/tpm_tis_core.c | 14 +++++++++----- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/sys/dev/tpm/tpm20.c b/sys/dev/tpm/tpm20.c index 22189d112656..20521b2ed361 100644 --- a/sys/dev/tpm/tpm20.c +++ b/sys/dev/tpm/tpm20.c @@ -157,7 +157,7 @@ tpm20_priv_dtor(void *data) { struct tpm_priv *priv = data; - free(priv->buf, M_TPM20); + free(priv, M_TPM20); } int @@ -209,7 +209,7 @@ tpm20_init(struct tpm_sc *sc) args.mda_si_drv1 = sc; result = make_dev_s(&args, &sc->sc_cdev, TPM_CDEV_NAME); if (result != 0) - tpm20_release(sc); + return (result); #if defined TPM_HARVEST || defined RANDOM_ENABLE_TPM random_source_register(&random_tpm); @@ -217,6 +217,7 @@ tpm20_init(struct tpm_sc *sc) tpm20_harvest, sc); taskqueue_enqueue_timeout(taskqueue_thread, &sc->harvest_task, 0); #endif + sc->common_initialized = true; return (result); @@ -226,16 +227,24 @@ void tpm20_release(struct tpm_sc *sc) { + if (!sc->common_initialized) + goto out; #if defined TPM_HARVEST || defined RANDOM_ENABLE_TPM if (device_is_attached(sc->dev)) taskqueue_drain_timeout(taskqueue_thread, &sc->harvest_task); random_source_deregister(&random_tpm); #endif - - tpm20_priv_dtor(sc->internal_priv); + sc->common_initialized = false; +out: + if (sc->internal_priv != NULL) { + tpm20_priv_dtor(sc->internal_priv); + sc->internal_priv = NULL; + } sx_destroy(&sc->dev_lock); - if (sc->sc_cdev != NULL) + if (sc->sc_cdev != NULL) { destroy_dev(sc->sc_cdev); + sc->sc_cdev = NULL; + } } int diff --git a/sys/dev/tpm/tpm20.h b/sys/dev/tpm/tpm20.h index a004bdea9e06..7570812219b9 100644 --- a/sys/dev/tpm/tpm20.h +++ b/sys/dev/tpm/tpm20.h @@ -128,6 +128,7 @@ struct tpm_sc { void *intr_cookie; int intr_type; /* Current event type */ bool interrupts; + bool common_initialized; struct tpm_priv *internal_priv; diff --git a/sys/dev/tpm/tpm_tis_core.c b/sys/dev/tpm/tpm_tis_core.c index 95e914fa570b..15370e648f1e 100644 --- a/sys/dev/tpm/tpm_tis_core.c +++ b/sys/dev/tpm/tpm_tis_core.c @@ -120,17 +120,21 @@ tpmtis_attach(device_t dev) result = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_MISC | INTR_MPSAFE, NULL, tpmtis_intr_handler, sc, &sc->intr_cookie); if (result != 0) { - bus_release_resource(dev, SYS_RES_IRQ, sc->irq_rid, sc->irq_res); + if (bus_release_resource(dev, SYS_RES_IRQ, sc->irq_rid, + sc->irq_res) == 0) + sc->irq_res = NULL; goto skip_irq; } - tpmtis_setup_intr(sc); - skip_irq: result = tpm20_init(sc); - if (result != 0) + if (result != 0) { tpmtis_detach(dev); + return (result); + } + if (sc->intr_cookie != NULL) + tpmtis_setup_intr(sc); - return (result); + return (0); } static int