char: tpm: tpm-buf: Add sanity check fallback in read helpers
Subsystems (2)
PATCH v2 1/1 char: tpm: tpm-buf: Add sanity check fallback in read helpers
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.
---
V1 - https://lore.kernel.org/all/[email protected]/
V2 - Update commit message to clarify patch adds a sanity check
drivers/char/tpm/tpm-buf.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/char/tpm/tpm-buf.c +3 -3
@@ -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);
Signature · 1 line
2.34.1
Quoted 60 lines · Purva Yeshi
Fix Smatch-detected issue:
drivers/char/tpm/tpm-buf.c:208tpm_buf_read_u8()error:
uninitialized symbol 'value'.drivers/char/tpm/tpm-buf.c:225tpm_buf_read_u16()error:
uninitialized symbol 'value'.drivers/char/tpm/tpm-buf.c:242tpm_buf_read_u32()error:
uninitialized symbol 'value'.Zero-initialize the return values in
tpm_buf_read_u8(),tpm_buf_read_u16(), andtpm_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 <[email protected]>---
V1 - https://lore.kernel.org/all/[email protected]/
V2 - Update commit message to clarify patch adds a sanity checkdrivers/char/tpm/tpm-buf.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/char/tpm/tpm-buf.c +3
-3@@ -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);Signature · 1 line
2.34.1
It's good and I think this change is appropriate overall!
BR, Jarkko
Quoted 64 lines · Jarkko Sakkinen
Quoted 60 lines · Purva Yeshi
Fix Smatch-detected issue:
drivers/char/tpm/tpm-buf.c:208tpm_buf_read_u8()error:
uninitialized symbol 'value'.drivers/char/tpm/tpm-buf.c:225tpm_buf_read_u16()error:
uninitialized symbol 'value'.drivers/char/tpm/tpm-buf.c:242tpm_buf_read_u32()error:
uninitialized symbol 'value'.Zero-initialize the return values in
tpm_buf_read_u8(),tpm_buf_read_u16(), andtpm_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 <[email protected]>---
V1 - https://lore.kernel.org/all/[email protected]/
V2 - Update commit message to clarify patch adds a sanity checkdrivers/char/tpm/tpm-buf.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/char/tpm/tpm-buf.c +3
-3@@ -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);Signature · 1 line
2.34.1It's good and I think this change is appropriate overall!
Quoted 3 lines
Reviewed-by Jarkko Sakkinen <[email protected]>BR, Jarkko
Thank you for the review.
Best Regards,
Purva Yeshi
Quoted 13 lines · Purva Yeshi
Fix Smatch-detected issue:
drivers/char/tpm/tpm-buf.c:208tpm_buf_read_u8()error:
uninitialized symbol 'value'.drivers/char/tpm/tpm-buf.c:225tpm_buf_read_u16()error:
uninitialized symbol 'value'.drivers/char/tpm/tpm-buf.c:242tpm_buf_read_u32()error:
uninitialized symbol 'value'.Zero-initialize the return values in
tpm_buf_read_u8(),tpm_buf_read_u16(), andtpm_buf_read_u32()to guard against uninitialized data in case of a boundary overflow.
Quoted 8 lines
Add defensive initialization ensures the return values are always defined, preventing undefined behavior if the unexpected happens.
Signed-off-by Purva Yeshi <[email protected]>---
V1 - https://lore.kernel.org/all/[email protected]/
V2 - Update commit message to clarify patch adds a sanity check
LGTM!
Quoted 39 lines
drivers/char/tpm/tpm-buf.c| 6 +++---1 file changed, 3 insertions(+), 3 deletions(-)drivers/char/tpm/tpm-buf.c +3
-3@@ -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);Signature · 1 line
2.34.1
Quoted 18 lines · Stefano Garzarella
Quoted 17 lines · Purva Yeshi
Fix Smatch-detected issue:
drivers/char/tpm/tpm-buf.c:208tpm_buf_read_u8()error:
uninitialized symbol 'value'.drivers/char/tpm/tpm-buf.c:225tpm_buf_read_u16()error:
uninitialized symbol 'value'.drivers/char/tpm/tpm-buf.c:242tpm_buf_read_u32()error:
uninitialized symbol 'value'.Zero-initialize the return values in
tpm_buf_read_u8(),tpm_buf_read_u16(), andtpm_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.
Quoted 8 lines
Quoted 4 lines
Signed-off-by Purva Yeshi <[email protected]>---
V1 - https://lore.kernel.org/all/20250409205536.210202-1- [email protected]/ V2 - Update commit message to clarify patch adds a sanity checkLGTM!
Reviewed-by Stefano Garzarella <[email protected]>
Thank you for the review.
Quoted 35 lines
Quoted 35 lines
drivers/char/tpm/tpm-buf.c| 6 +++---1 file changed, 3 insertions(+), 3 deletions(-)drivers/char/tpm/tpm-buf.c +0
-0@@ -201,7 +201,7 @@ static void tpm_buf_read(struct tpm_buf *buf,
off_t*offset,size_tcount, void
*/
u8tpm_buf_read_u8(struct tpm_buf *buf, off_t *offset){
- u8 value;
+ u8 value = 0;tpm_buf_read(buf, offset, sizeof(value), &value);
drivers/char/tpm/tpm-buf.c +2
-2@@ -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;
Quoted 7 lines
Quoted 6 lines
drivers/char/tpm/tpm-buf.c +0
-0tpm_buf_read(buf, offset, sizeof(value), &value);Signature · 1 line
2.34.1
Best Regards,
Purva