The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Purva Yeshi <purvayeshi550@gmail.com>
To: Stefano Garzarella <sgarzare@redhat.com>
Cc: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca,
	linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] char: tpm: tpm-buf: Add sanity check fallback in read helpers
Date: Fri, 11 Apr 2025 14:31:30 +0530	[thread overview]
Message-ID: <3a1c03c6-19da-4300-a56e-daf8264be064@gmail.com> (raw)
In-Reply-To: <6w3lsskngim3x6lx7akwfly3hrrzxyi4pq4itwyye3rywlqum7@oiwkjmvtawl7>

On 11/04/25 12:50, Stefano Garzarella wrote:
> On Thu, Apr 10, 2025 at 04:04:42PM +0530, Purva Yeshi wrote:
>> Fix Smatch-detected issue:
>>
>> drivers/char/tpm/tpm-buf.c:208 tpm_buf_read_u8() error:
>> uninitialized symbol 'value'.
>> drivers/char/tpm/tpm-buf.c:225 tpm_buf_read_u16() error:
>> uninitialized symbol 'value'.
>> drivers/char/tpm/tpm-buf.c:242 tpm_buf_read_u32() error:
>> uninitialized symbol 'value'.
>>
>> Zero-initialize the return values in tpm_buf_read_u8(),
>> tpm_buf_read_u16(), and tpm_buf_read_u32() to guard against
>> uninitialized data in case of a boundary overflow.
>>
>> Add defensive initialization ensures the return values are
>> always defined, preventing undefined behavior if the unexpected
>> happens.
>>
>> Signed-off-by: Purva Yeshi <purvayeshi550@gmail.com>
>> ---
>> V1 - https://lore.kernel.org/all/20250409205536.210202-1- 
>> purvayeshi550@gmail.com/
>> V2 - Update commit message to clarify patch adds a sanity check
> 
> LGTM!
> 
> Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>

Thank you for the review.

> 
>>
>> drivers/char/tpm/tpm-buf.c | 6 +++---
>> 1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/char/tpm/tpm-buf.c b/drivers/char/tpm/tpm-buf.c
>> index e49a19fea3bd..dc882fc9fa9e 100644
>> --- a/drivers/char/tpm/tpm-buf.c
>> +++ b/drivers/char/tpm/tpm-buf.c
>> @@ -201,7 +201,7 @@ static void tpm_buf_read(struct tpm_buf *buf, 
>> off_t *offset, size_t count, void
>>  */
>> u8 tpm_buf_read_u8(struct tpm_buf *buf, off_t *offset)
>> {
>> -    u8 value;
>> +    u8 value = 0;
>>
>>     tpm_buf_read(buf, offset, sizeof(value), &value);
>>
>> @@ -218,7 +218,7 @@ EXPORT_SYMBOL_GPL(tpm_buf_read_u8);
>>  */
>> u16 tpm_buf_read_u16(struct tpm_buf *buf, off_t *offset)
>> {
>> -    u16 value;
>> +    u16 value = 0;
>>
>>     tpm_buf_read(buf, offset, sizeof(value), &value);
>>
>> @@ -235,7 +235,7 @@ EXPORT_SYMBOL_GPL(tpm_buf_read_u16);
>>  */
>> u32 tpm_buf_read_u32(struct tpm_buf *buf, off_t *offset)
>> {
>> -    u32 value;
>> +    u32 value = 0;
>>
>>     tpm_buf_read(buf, offset, sizeof(value), &value);
>>
>> -- 
>> 2.34.1
>>
>>
> 

Best Regards,
Purva


      reply	other threads:[~2025-04-11  9:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-10 10:34 [PATCH v2] char: tpm: tpm-buf: Add sanity check fallback in read helpers Purva Yeshi
2025-04-10 12:37 ` Jarkko Sakkinen
2025-04-10 16:30   ` Purva Yeshi
2025-04-11  7:20 ` Stefano Garzarella
2025-04-11  9:01   ` Purva Yeshi [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=3a1c03c6-19da-4300-a56e-daf8264be064@gmail.com \
    --to=purvayeshi550@gmail.com \
    --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=sgarzare@redhat.com \
    /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