From: Shahriyar Jalayeri <shahriyar@posteo.de>
To: peterhuewe@gmx.de
Cc: jarkko@kernel.org, jgg@ziepe.ca, linux-integrity@vger.kernel.org,
linux-kernel@vger.kernel.org,
Shahriyar Jalayeri <shahriyar@posteo.de>
Subject: [PATCH] tpm: infineon: add bounds check in tpm_inf_recv
Date: Fri, 03 Oct 2025 09:25:47 +0000 [thread overview]
Message-ID: <20251003092544.12118-1-shahriyar@posteo.de> (raw)
Ensure tpm_inf_recv() does not overflow the provided buffer when
the TPM reports more data than the caller expects.
Signed-off-by: Shahriyar Jalayeri <shahriyar@posteo.de>
---
drivers/char/tpm/tpm_infineon.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/drivers/char/tpm/tpm_infineon.c b/drivers/char/tpm/tpm_infineon.c
index 7638b65b8..eb6dd55ff 100644
--- a/drivers/char/tpm/tpm_infineon.c
+++ b/drivers/char/tpm/tpm_infineon.c
@@ -250,6 +250,12 @@ static int tpm_inf_recv(struct tpm_chip *chip, u8 * buf, size_t count)
number_of_wtx = 0;
recv_begin:
+ if (count < 4) {
+ dev_err(&chip->dev,
+ "count less than the header size!\n");
+ return -EIO;
+ }
+
/* start receiving header */
for (i = 0; i < 4; i++) {
ret = wait(chip, STAT_RDA);
@@ -268,6 +274,12 @@ static int tpm_inf_recv(struct tpm_chip *chip, u8 * buf, size_t count)
/* size of the data received */
size = ((buf[2] << 8) | buf[3]);
+ if (size > count) {
+ dev_err(&chip->dev,
+ "Buffer too small for incoming data!\n");
+ return -EIO;
+ }
+
for (i = 0; i < size; i++) {
wait(chip, STAT_RDA);
buf[i] = tpm_data_in(RDFIFO);
--
2.43.0
next reply other threads:[~2025-10-03 9:25 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-03 9:25 Shahriyar Jalayeri [this message]
2025-10-03 11:22 ` Paul Menzel
2025-10-04 8:35 ` Shahriyar
2025-10-04 12:29 ` Jarkko Sakkinen
2025-10-04 9:04 Shahriyar Jalayeri
2025-10-04 12:33 ` Jarkko Sakkinen
2025-10-07 9:07 Shahriyar Jalayeri
2025-10-07 19:25 ` Jarkko Sakkinen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251003092544.12118-1-shahriyar@posteo.de \
--to=shahriyar@posteo.de \
--cc=jarkko@kernel.org \
--cc=jgg@ziepe.ca \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterhuewe@gmx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®