Re: [PATCH 2/2] tpm: st33zp24: Validate locality read result

Jarkko Sakkinen <[email protected]>
Newsgroups org.kernel.vger.linux-integrity,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
On Thu, Aug 13, 2026 at 11:30:32PM +0800, Ruoyu Wang wrote:
> check_locality() treats every nonzero transport return as success. SPI
> errors remain negative, while the I2C path can convert a negative write
> error through its byte-sized status variable. Either result is nonzero
> even though the TPM_ACCESS byte can remain unwritten, so indeterminate
> ACTIVE_LOCALITY and VALID bits can falsely report an active locality.
> 
> Require recv() to return exactly the requested byte before examining
> TPM_ACCESS. Transport errors and short reads now report an inactive
> locality, while successful reads retain the existing behavior.
> 
> This issue was found by a static analysis checker and confirmed by manual
> source review.
> 
> Fixes: 251a7b08213a ("TPM: STMicroelectronics ST33 I2C KERNEL 3.x")
> Signed-off-by: Ruoyu Wang <[email protected]>
> ---
>  drivers/char/tpm/st33zp24/st33zp24.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/char/tpm/st33zp24/st33zp24.c b/drivers/char/tpm/st33zp24/st33zp24.c
> index 898e8d01d26698..0e2deff94c3672 100644
> --- a/drivers/char/tpm/st33zp24/st33zp24.c
> +++ b/drivers/char/tpm/st33zp24/st33zp24.c
> @@ -106,10 +106,10 @@ static bool check_locality(struct tpm_chip *chip)
>  {
>  	struct st33zp24_dev *tpm_dev = dev_get_drvdata(&chip->dev);
>  	u8 data;
> -	u8 status;
> +	int status;
>  
>  	status = tpm_dev->ops->recv(tpm_dev->phy_id, TPM_ACCESS, &data, 1);
> -	if (status && (data &
> +	if (status == 1 && (data &
>  		(TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) ==
>  		(TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID))
>  		return true;
> -- 
> 2.51.0
> 

Reviewed-by: Jarkko Sakkinen <[email protected]>

BR, Jarkko
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.