public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Purva Yeshi <purvayeshi550@gmail.com>
To: Jarkko Sakkinen <jarkko@kernel.org>,
	Stefano Garzarella <sgarzare@redhat.com>
Cc: peterhuewe@gmx.de, jgg@ziepe.ca, linux-integrity@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] char: tpm: tpm-buf: Fix uninitialized return values in read helpers
Date: Thu, 10 Apr 2025 15:14:34 +0530	[thread overview]
Message-ID: <1bceb239-4f18-41c9-b6c7-acd4ce08ba8d@gmail.com> (raw)
In-Reply-To: <Z_eHWkSdhfOHxiNe@kernel.org>

On 10/04/25 14:24, Jarkko Sakkinen wrote:
> On Thu, Apr 10, 2025 at 09:51:09AM +0200, Stefano Garzarella wrote:
>> On Thu, Apr 10, 2025 at 09:14:58AM +0300, Jarkko Sakkinen wrote:
>>> On Thu, Apr 10, 2025 at 02:25:36AM +0530, Purva Yeshi wrote:
>>>> Fix Smatch-detected error:
> 
> Empty line and s/error/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'.
>>>>
>>>> Call tpm_buf_read() to populate value but do not check its return
>>>> status. If the read fails, value remains uninitialized, causing
>>>> undefined behavior when returned or processed.
>>>>
>>>> Initialize value to zero to ensure a defined return even if
>>>> tpm_buf_read() fails, avoiding undefined behavior from using
>>>> an uninitialized variable.
>>>
>>> How does tpm_buf_read() fail?
>>
>> If TPM_BUF_BOUNDARY_ERROR is set (or we are setting it), we are effectively
>> returning random stack bytes to the caller.
>> Could this be a problem?
> 
> It should never happen, if the kernel is working correctly. The commit
> message implies a legit failure scenario, which would imply that the
> patch is a bug fix, which it actually is not.
> 
> "Add a sanity check for boundary overflow, and zero out the value,
> if the unexpected happens" is what this patch actually does. I.e.,
> code change acceptable, commit message is all wrong.

Understood now. I’ll update the commit message to clearly state this is 
a sanity check for unexpected boundary overflows. Thanks for the 
clarification!

> 
>>
>> If it is, maybe instead of this patch, we could set `*output` to zero in the
>> error path of tpm_buf_read(). Or return an error from tpm_buf_read() so
>> callers can return 0 or whatever they want.
>>
>> Thanks,
>> Stefano
>>
>>
> 
> BR, Jarkko


      reply	other threads:[~2025-04-10  9:44 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-09 20:55 [PATCH] char: tpm: tpm-buf: Fix uninitialized return values in read helpers Purva Yeshi
2025-04-10  6:14 ` Jarkko Sakkinen
2025-04-10  7:51   ` Stefano Garzarella
2025-04-10  8:42     ` Purva Yeshi
2025-04-10  8:55       ` Jarkko Sakkinen
2025-04-10  8:57         ` Jarkko Sakkinen
2025-04-10  9:46         ` Purva Yeshi
2025-04-10  8:54     ` Jarkko Sakkinen
2025-04-10  9:44       ` 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=1bceb239-4f18-41c9-b6c7-acd4ce08ba8d@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