public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Shahriyar <shahriyar@posteo.de>
To: Paul Menzel <pmenzel@molgen.mpg.de>
Cc: jarkko@kernel.org, peterhuewe@gmx.de, jgg@ziepe.ca,
	linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5] tpm: infineon: add bounds check in tpm_inf_recv
Date: Fri, 10 Oct 2025 08:05:54 +0000	[thread overview]
Message-ID: <dfc2e998-dc26-40be-8e17-e44f46b88f1a@posteo.de> (raw)
In-Reply-To: <b1fbadb2-235e-4b08-afba-e397c6d076df@molgen.mpg.de>

On 10/10/25 10:02 AM, Paul Menzel wrote:
> Dear Shahriyar,
> 
> 
> Thank you for the improved version.
> 
> Am 10.10.25 um 09:49 schrieb Shahriyar Jalayeri:
>> Add two buffer size validations to prevent buffer overflows in
>> tpm_inf_recv():
>>
>> 1. Validate that the provided buffer can hold at least the 4-byte header
>>     before attempting to read it.
>> 2. Validate that the buffer is large enough to hold the data size 
>> reported
>>     by the TPM before reading the payload.
>>
>> Without these checks, a malicious or malfunctioning TPM could cause 
>> buffer
>> overflows by reporting data sizes larger than the provided buffer, 
>> leading
>> to memory corruption.
>>
>> Fixes: ebb81fdb3dd0 ("[PATCH] tpm: Support for Infineon TPM")
>> Signed-off-by: Shahriyar Jalayeri <shahriyar@posteo.de>
>> ---
>> Changelog:
>> v5:
>>     - replaced space indentation with tabs before the header comment
>> v4:
>>     - removed the curly braces around one line statements
>> v3:
>>     - removed dev_err() logs
>>     - added missing "fixes" tag
>>     - described header structure
>>     - fixed commit message length
>>     - removed use of local variable as constant
>>     - fixed check to account for off-by-six bytes
>> v2:
>>     - added complete changes in the commit message
>>     - dev_err() logged expected sizes and stated operation is aborted
>>
>>   drivers/char/tpm/tpm_infineon.c | 7 +++++++
>>   1 file changed, 7 insertions(+)
>>
>> diff --git a/drivers/char/tpm/tpm_infineon.c b/drivers/char/tpm/ 
>> tpm_infineon.c
>> index 7638b65b8..d76aae08b 100644
>> --- a/drivers/char/tpm/tpm_infineon.c
>> +++ b/drivers/char/tpm/tpm_infineon.c
>> @@ -250,6 +250,10 @@ static int tpm_inf_recv(struct tpm_chip *chip, u8 
>> * buf, size_t count)
>>       number_of_wtx = 0;
>>   recv_begin:
>> +    /* expect at least 1-byte VL header, 1-byte ctrl-tag, 2-byte data 
>> size */
>> +    if (count < 4)
>> +        return -EIO;
>> +
>>       /* start receiving header */
>>       for (i = 0; i < 4; i++) {
>>           ret = wait(chip, STAT_RDA);
>> @@ -268,6 +272,9 @@ 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 + 6 > count)
>> +            return -EIO;
>> +
>>           for (i = 0; i < size; i++) {
>>               wait(chip, STAT_RDA);
>>               buf[i] = tpm_data_in(RDFIFO);
> 
> Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de>
> 
> 
> Kind regards,
> 
> Paul

Thank you for your patience with newcomers.

-- 
BR.
/shj

      reply	other threads:[~2025-10-10  8:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-10  7:49 [PATCH v5] tpm: infineon: add bounds check in tpm_inf_recv Shahriyar Jalayeri
2025-10-10  8:02 ` Paul Menzel
2025-10-10  8:05   ` Shahriyar [this message]

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=dfc2e998-dc26-40be-8e17-e44f46b88f1a@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 \
    --cc=pmenzel@molgen.mpg.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