From nobody Tue Nov 24 11:21:46 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=82.195.75.108 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794391108; b=jdpt9BoaOwha4Znwvvm2Tdz2EMH3Ee3cE4Hs0v4qJjgYhl4QQ0Z8DGsxTTA7p+4aWQKG fyV3e97nL+oxeK121xu2JtyCAXWoUuZM4tVjdxDj7579kwTwxEyekVO8S15Ge379jnbxn UXaE724E0wfzrT8wPPkJJReiueQFPjZo6dEUQRVntLqHMKLx1xGCWs0nC+ep13T8ykTvc 9dqHFj/sNDRU2tdP/TfHi9ML7M8QntSqjtpZbx3052YgvcePbIgvGIfB6MMEaT+0eZBm1 kYZJkkGiJfPWi31YyxgLQLkATURtoYNRBfPlwGIA5aO3nWzO5ArKJfci5JpHBiAXqCw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794391108; h=DMARC-Filter:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Content-Transfer-Encoding:Message-Id:References: In-Reply-To:To:Cc:X-Mailer:X-Developer-Signature:X-Developer-Key: X-Debian-User; bh=tGushzrFtrW77V7rVvL3s1nIofkTvVLHjtzLyoCHfR0=; b=YB2g0uH3ll+kjj7nxyhzSakRiqrr6p0xi/XEtJ8Xij/Gejt/5/f6fpKXxo1Dm0F61PnF E31W/NP+ObOazqfxJ4nlxKUP/14Xb5NDtLJA++4aWNtiCm28XF+htG9tUCqiGZujlCXyf ne0/HxtLZB/qUvksxW8Nlm1NNJrU6u1MYlSOcXk8n/XCM2JYuaEvyJWJ0hgnmbS1Zk1AJ 4ETOw+fW+8pMy8vwGiFI3KqxeatI2B1NG3yHrRiujl/OnybpDWXceObdSSbK9zGlTVcsZ hUaJvEgQzIgrFySzHmcxL7HnKEsUuBYWmGEGaJpDKwcRZqpwhYotCXWkR7MK0SdUxCQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=debian.org; spf=pass smtp.mailfrom=debian.org; dkim=pass header.d=debian.org header.i=@debian.org header.a=rsa-sha256 header.s=smtpauto.stravinsky header.b="dD/jUv4H"; arc=none smtp.remote-ip=82.195.75.108 Received: from stravinsky.debian.org (stravinsky.debian.org [82.195.75.108]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BDDF5606A331; Wed, 11 Nov 2026 09:58:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BDDF5606A331 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=debian.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.a=rsa-sha256 header.s=smtpauto.stravinsky header.b=dD/jUv4H DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debian.org; s=smtpauto.stravinsky; h=X-Debian-User:Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description; bh=tGushzrFtrW77V7rVvL3s1nIofkTvVLHjtzLyoCHfR0=; b=dD/jUv4HR7WhMkgCSpIrvyXvMy CdQzp8TivJzNsLmT2f/ww1N1E9Pf9BsaMqseJ7w2EyKldnuJNgpGPnmA3l4G3MgzuMG672gyiHzgi n7DQx8je9z7OMKes3Is0AAN607y35wMnjpnECI1irDFnOZrSAxUZVVjRcp/ll2Hc2ApS/4+kr3Wwf F1F1ShwvoeMBQubmAZrfrIOcTLSrTfeUUtNwc4unBeUWBQLuZzQTKggOkmHDAvoog/sT9npN4unks pBoHrlB3ZY/zL+BCLdMu/W0RWz+dbiTOB++rKkd7Uif7u1Ot5jYi7JDS5AzJrcEY+vx105WDBE/oV QNdV486g==; Received: from authenticated-user by stravinsky.debian.org with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96) (envelope-from ) id 1xR562-00D6Ag-05; Wed, 11 Nov 2026 09:58:26 +0000 From: Breno Leitao Date: Wed, 11 Nov 2026 01:57:33 -0800 Subject: [PATCH 1/2] tpm: Disable a TPM that stops responding X-Mailing-List: linux-kernel@vger.kernel.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: quoted-printable Message-Id: <20261111-tpm_unresponsive-v1-1-42ac1b965eb9@debian.org> References: <20261111-tpm_unresponsive-v1-0-42ac1b965eb9@debian.org> In-Reply-To: <20261111-tpm_unresponsive-v1-0-42ac1b965eb9@debian.org> To: Peter Huewe , Jarkko Sakkinen , Jason Gunthorpe Cc: linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, surenkj@amazon.com, noodles@meta.com, Breno Leitao , kernel-team@meta.com X-Mailer: b4 0.17-dev-ce4c1 X-Developer-Signature: v=1; a=openpgp-sha256; l=3226; i=leitao@debian.org; h=from:subject:message-id; bh=8Km7/zIGwygrBCifvoU5JjUY37dEAbTHjT/QlxC2Mg0=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBq9Dw6mXcwy7JFyMKMD/gGq1CRDCXJOX/lNYyro 2mvMri2EgmJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCavQ8OgAKCRA1o5Of/Hh3 bZFrD/98RXf5kHalz/1PQLMnbHU+hEOlg65ukjdVNPFplWDqK5hCTUZfkGdN2aClZQQrPwdbAqI RTWUBcYSmFjI2ejA236zenSJpuqYWTsEV6YyHhjk0uIkbMtAC4XfirgNDx1d07ElKfVuZ0s6WfM P+Zwiwmg0DI/sBdQpQdQPfSxxmji+bHG6qzDwzpu6W++70dq13JPwEjMOt+3Ect6V8BRiOGwtDf RjwK4pGtNzDzv2HBkRs61s7ghHyLUgU5V7E/edjZIDvuuz0917+Ipvw7SylExpJ1b7kKvB1Yzwn KohUgpWKLuUM0Ot8TjlulT4Y3xFgEwocdWXT7REFyec5tyO4v+cMZaT0Rr7axjbxrh2MIOYDs+Q 0uzPGqgNVCob0toxzV+Xo4y0nyYBdTCaPSEBQPsKQx0yZtyZfPYloAkevy4LHyLKC9vaygFB9mP E2tCY3X2mAFkUA1BCwSGhE6GCkcrMYbwWWYNPiN7UvgxkAmi53++1Bvu7ZhQ5O7L4TuXqrjcAYv 4RW32Pu4AtPuJnvg+XneKxGWAxQoyQGtzMHkV1SUtS/+ASW6JabnStg7ngtLSs6RV12xW44rObX XztVNonmw1oyJL9G497wak38ORCJlnXz/07iqiKXZXu5+bK3DeGZ7kTUUHeHxmYaMx34/F2i1TM 0a+N2ssXZLNU+iA== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao A TPM that stops responding fails each command only after the transport timeout, and its callers keep sending more: the hwrng thread every 10 seconds forever, and userspace through /dev/tpmrm0. Each attempt holds tpm_mutex for the whole timeout and logs an error: tpm tpm0: invalid TPM_STS.x 0xff, dumping stack for forensics tpm tpm0: tpm_try_transmit: send(): error -62 tpm tpm0: tpm_try_transmit: send(): error -62 ... The core already stops using a TPM it cannot trust: tpm_try_get_ops() fails with -EIO once TPM_CHIP_FLAG_DISABLE is set, which tpm2_load_null() does when it cannot restore the null key. Set the same flag when commands have kept timing out for ten minutes, with none completing in between. A completed command, whatever its TPM return code, resets the clock. A disabled TPM stays disabled until the driver is rebound or the machine reboots. Signed-off-by: Breno Leitao --- drivers/char/tpm/tpm-interface.c | 29 +++++++++++++++++++++++++++++ include/linux/tpm.h | 2 ++ 2 files changed, 31 insertions(+) diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interf= ace.c index e0385b16616b46..c6278ef8d1095e 100644 --- a/drivers/char/tpm/tpm-interface.c +++ b/drivers/char/tpm/tpm-interface.c @@ -30,6 +30,8 @@ =20 #include "tpm.h" =20 +#define TPM_UNRESPONSIVE_TIMEOUT (10 * 60 * HZ) + /* * Bug workaround - some TPM's don't flush the most * recently changed pcr on suspend, so force the flush @@ -206,6 +208,31 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip,= void *buf, size_t bufsiz) return rc ? rc : len; } =20 +/* + * Disable the TPM once commands keep timing out for TPM_UNRESPONSIVE_TIME= OUT. + * A few timeouts are not enough: some TPMs stall for half a minute and re= cover. + */ +static void tpm_check_unresponsive(struct tpm_chip *chip, ssize_t ret) +{ + if (ret >=3D 0) { + chip->nr_timeouts =3D 0; + return; + } + if (ret !=3D -ETIME || (chip->flags & TPM_CHIP_FLAG_DISABLE)) + return; + if (!chip->nr_timeouts++) { + chip->first_timeout =3D jiffies; + return; + } + if (time_before(jiffies, + chip->first_timeout + TPM_UNRESPONSIVE_TIMEOUT)) + return; + + dev_err(&chip->dev, "%u commands timed out in %lu seconds, disabling the = TPM\n", + chip->nr_timeouts, (jiffies - chip->first_timeout) / HZ); + chip->flags |=3D TPM_CHIP_FLAG_DISABLE; +} + /** * tpm_transmit - Internal kernel interface to transmit TPM commands. * @chip: a TPM chip to use @@ -268,6 +295,8 @@ ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, si= ze_t bufsiz) delay_msec *=3D 2; memcpy(buf, save, save_size); } + + tpm_check_unresponsive(chip, ret); return ret; } =20 diff --git a/include/linux/tpm.h b/include/linux/tpm.h index 0db277af45c393..4264c87a04d98c 100644 --- a/include/linux/tpm.h +++ b/include/linux/tpm.h @@ -131,6 +131,8 @@ struct tpm_chip { struct hwrng hwrng; =20 struct mutex tpm_mutex; /* tpm is processing */ + unsigned int nr_timeouts; /* consecutive command timeouts */ + unsigned long first_timeout; /* jiffies */ =20 unsigned long timeout_a; /* jiffies */ unsigned long timeout_b; /* jiffies */ --=20 2.53.0-Meta From nobody Tue Nov 24 11:21:46 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=82.195.75.108 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794391112; b=GZTjdHJ1zy9xF8l6+ASxw/PIZjtFNbFggR4VngRn0xGhREZMl384liKUMvecSqpVBsDc dTd7Fnmr+ul36KM6mXGAZi2H3HcLTjvAWQ3BIfXjh2GFQXfgfhkTbdKXmFr+w/y2DDLI8 AFeSgxGRXZgaUmnb1k0yHioZUwGxOx2KCCQhD8xZH3IeIEudA8ZjIZygsQH2dxMwHxP9D lUyHOZ4G/FkvmzkdWnRJTuWdNmRYn8Lr4v5WzHfVxUosB0AZxRgarGnmRtLgOSV19ZiJP 1ySxK8mP5rfwr5wD/KQMQDPZoetkMI4sA4q6CBNTXpQkIk4TFDa6RVVQlN6aIBTLO9g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794391112; h=DMARC-Filter:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Content-Transfer-Encoding:Message-Id:References: In-Reply-To:To:Cc:X-Mailer:X-Developer-Signature:X-Developer-Key: X-Debian-User; bh=7qBqijEg3j5itL5NDjhxpRdtP7gusIM2gmMrcRmtQxI=; b=20RmIj+RfOT2x2/9YkvkFB/kytHYA8SIlEIjJtgt6KlPiDM3pb1waHF5FqhiUGDfhEKX dwCUaIZrwOw7JWzS3mYUjfJ+sy6J0ntq1cEQmnxFpp3Pn3tz3V+0GFeIKmXut0O+SezgM 0PBImA93QzJJs4x5JqShkrL90kI6yiGpCeBucN2T0n84dImeb8qGmyuThWJYJCLhRE2BV /eYCLOUd89r6MDn1Vu5plm5g+XzVxyOVdvHSayhSJVNRi5OSMVuIzez0qbmu0R30ozclx OH59xP3vWBnjeo66ie2o6v0t4hwMTRb5Hsl88eO9Mjlm/fsj9wPz5lil0ALbHUcmvNA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=debian.org; spf=pass smtp.mailfrom=debian.org; dkim=pass header.d=debian.org header.i=@debian.org header.a=rsa-sha256 header.s=smtpauto.stravinsky header.b=bQf4fdnb; arc=none smtp.remote-ip=82.195.75.108 Received: from stravinsky.debian.org (stravinsky.debian.org [82.195.75.108]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0281A606A331; Wed, 11 Nov 2026 09:58:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0281A606A331 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=debian.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.a=rsa-sha256 header.s=smtpauto.stravinsky header.b=bQf4fdnb DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debian.org; s=smtpauto.stravinsky; h=X-Debian-User:Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description; bh=7qBqijEg3j5itL5NDjhxpRdtP7gusIM2gmMrcRmtQxI=; b=bQf4fdnbJPHep2hoXXtpkKYvBn bp9mEP/pS2wX7uQUf7HhOzrEdYThhEYvSEX33s7arKtv92v0oyaJtbeaPqTWewacYFq/TjJaUp8ag vMXmjbPSDRVfJs4H8Oh3rtPMUabFiZ9v0v/vC6i7owDjUHP0M44vAxlbNL8RcEasLSSwhWT3WxI0Z ou5N6p5iBdjLOHgTxKgYurJiQ2YAlrAiT9xRhVl+/YNZLmdQJEG/bMOefNhxoBxyrsqiJrMO/+X6W jh1SWy6cbt7RHh8bY7TFuTQ51bHu4J4UM1l8IREe052P1f5sWGsQHfFxGZ/7HkgdgrJ0JJGdtqbdr I6KPnnXA==; Received: from authenticated-user by stravinsky.debian.org with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96) (envelope-from ) id 1xR566-00D6Av-0Q; Wed, 11 Nov 2026 09:58:30 +0000 From: Breno Leitao Date: Wed, 11 Nov 2026 01:57:34 -0800 Subject: [PATCH 2/2] tpm: Disable a TPM whose hwrng reads keep failing X-Mailing-List: linux-kernel@vger.kernel.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: quoted-printable Message-Id: <20261111-tpm_unresponsive-v1-2-42ac1b965eb9@debian.org> References: <20261111-tpm_unresponsive-v1-0-42ac1b965eb9@debian.org> In-Reply-To: <20261111-tpm_unresponsive-v1-0-42ac1b965eb9@debian.org> To: Peter Huewe , Jarkko Sakkinen , Jason Gunthorpe Cc: linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, surenkj@amazon.com, noodles@meta.com, Breno Leitao , kernel-team@meta.com X-Mailer: b4 0.17-dev-ce4c1 X-Developer-Signature: v=1; a=openpgp-sha256; l=2655; i=leitao@debian.org; h=from:subject:message-id; bh=smou7fUGe3NRb6a1h+kZU3AB4shLYZ9dPaGLC8pnQzw=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBq9Dw66TawD4Z/0NUvVIZWwOkxC3+hxyei2R89B z8jyvVfQVuJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCavQ8OgAKCRA1o5Of/Hh3 baJGD/0QH6odvOY+bXjc7t4CSBu7W6JHpamlsiEzqBDKIYc80KA3qFzKd86b4E6pxfiJjcdvcvq L4hbrOP7so2K4VWNNy4vlRvML+PcWSUThCwJy16aQRC/fA5kn5axNcj4sH+7Vq+k5jsPJvxz00q FkSfLU7b+eV2m5+D0j4YtdNo1mn6jVMCOnANmqFvm0bWBs336krMVaGcQM96MZDllk6OJeKGbzo BdEYvyyki0ENYhhiuS5ffIGdSpbKPMoIkHeK3yaMaiccMtLnS8q40bABC1C7BzC4aq6a00xluY8 pTgjIXspYKuqvaRpJKaqiYuIkOpFUbTcuBXtbHsJlXdk6vnrHzvcvnOTXvZ5/Ima81KiWAunMuf ZApnYJX0B1efKi/nAFarpy6BqvdD3RaheRswNYGWjmDu3ZsJ3iwBQUQjrOtUKigNgEotcFDlaq9 OKycfEoxVDT/gOieWL++iSGj7XyuYjPDrFyR89Vh6GOmQXaX+t0oBV7O7eQfowyvoadBbB7mTRf L2Jg3APt+b4AkjdX4o868E5ZXJvE0X8XXL+cvSx2uUayKJ7wCFz+MvgxzQ8SvzhrKs/Pooq02zs p0U8RY6CPTK3BKFaiidx40cYYk+HKHW1sJGORNzQjuTsJ2nNasWXX0+ZAFhl7CXxT6IpF3tAMHl L9sA0ntl+pKo33A== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao The hwrng core retries a failed read every 10 seconds, forever. When the TPM keeps answering GetRandom with an error, each retry logs a line: tpm tpm0: A TPM error (256) occurred attempting get random tpm tpm0: A TPM error (256) occurred attempting get random ... Neither clears on its own, and the TPM does answer, so the timeout check in tpm_transmit() never fires. After 60 failed reads in a row, ~ten minutes of retries on my system, set TPM_CHIP_FLAG_DISABLE as tpm_transmit() does for a TPM that stopped responding. Later reads then fail in tpm_try_get_ops() without sending the TPM a command. A successful read resets the count. A handful of failures is not enough, since some TPMs stall for half a minute and then recover. This also takes the TPM away from userspace, which could otherwise still send TPM2_Startup or query the failure mode. Rebinding the driver brings it back. Signed-off-by: Breno Leitao --- drivers/char/tpm/tpm-chip.c | 20 +++++++++++++++++++- include/linux/tpm.h | 1 + 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index 0be5dbfaa72ebf..d94ea462a5ef0c 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c @@ -466,11 +466,29 @@ static int tpm_add_legacy_sysfs(struct tpm_chip *chip) return 0; } =20 +#define TPM_HWRNG_MAX_FAILURES 60 /* ~10 minutes of retries */ + static int tpm_hwrng_read(struct hwrng *rng, void *data, size_t max, bool = wait) { struct tpm_chip *chip =3D container_of(rng, struct tpm_chip, hwrng); + int rc; + + rc =3D tpm_get_random(chip, data, max); + if (rc > 0) { + chip->hwrng_failures =3D 0; + return rc; + } + + if (++chip->hwrng_failures =3D=3D TPM_HWRNG_MAX_FAILURES && + !(chip->flags & TPM_CHIP_FLAG_DISABLE)) { + dev_err(&chip->dev, "hwrng: %u reads failed in a row, disabling the TPM\= n", + chip->hwrng_failures); + mutex_lock(&chip->tpm_mutex); + chip->flags |=3D TPM_CHIP_FLAG_DISABLE; + mutex_unlock(&chip->tpm_mutex); + } =20 - return tpm_get_random(chip, data, max); + return rc; } =20 static bool tpm_is_hwrng_enabled(struct tpm_chip *chip) diff --git a/include/linux/tpm.h b/include/linux/tpm.h index 4264c87a04d98c..402b5160db962c 100644 --- a/include/linux/tpm.h +++ b/include/linux/tpm.h @@ -129,6 +129,7 @@ struct tpm_chip { =20 char hwrng_name[64]; struct hwrng hwrng; + unsigned int hwrng_failures; /* consecutive failed reads */ =20 struct mutex tpm_mutex; /* tpm is processing */ unsigned int nr_timeouts; /* consecutive command timeouts */ --=20 2.53.0-Meta