]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
char: tpm: tpm-buf: Add sanity check fallback in read helpers
authorPurva Yeshi <purvayeshi550@gmail.com>
Thu, 10 Apr 2025 10:34:42 +0000 (16:04 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 4 Jun 2025 12:45:10 +0000 (14:45 +0200)
commite8fd089329f1e353d7b65894084596071c8a1263
tree13f002291e8223159a154a609e01ffe35e5ceca8
parentae24f6318bbd54b12e928108ea99cf3471ad9d0b
char: tpm: tpm-buf: Add sanity check fallback in read helpers

[ Upstream commit 32d495b384a2db7d23c2295e03e6b6edb1c0db8d ]

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>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/char/tpm/tpm-buf.c