tpm: Check the bios_dir entry for NULL before accessing it
PATCH 1/1 tpm: Check the bios_dir entry for NULL before accessing it
Check the bios_dir entry for NULL before accessing it. Currently this crashes the driver when a TPM 2 is attached and the entries are NULL.
--- drivers/char/tpm/tpm_eventlog.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/char/tpm/tpm_eventlog.c +7 -5
@@ -455,10 +455,12 @@ void tpm_bios_log_teardown(struct tpm_chip *chip)* This design ensures that open() either safely gets kref or fails. */ for (i = (TPM_NUM_EVENT_LOG_FILES -1 ); i >=0 ; i--) { - inode =d_inode (chip->bios_dir[i]); -inode_lock (inode); - inode->i_private =NULL ; -inode_unlock (inode); -securityfs_remove (chip->bios_dir[i]); +if (chip->bios_dir[i]) { + inode =d_inode (chip->bios_dir[i]); +inode_lock (inode); + inode->i_private =NULL ; +inode_unlock (inode); +securityfs_remove (chip->bios_dir[i]); + } } }
Signature · 4 lines
2.4.3 ------------------------------------------------------------------------------
Quoted 3 lines · Stefan Berger
Check the
bios_direntry for NULL before accessing it. Currently this crashes the driver when a TPM 2 is attached and the entries are NULL.
Thanks Stefan !! I think it would be good to also add Fixes in commit description here.
Thanks & Regards,
- Nayna
Quoted 19 lines
Signed-off-by Stefan Berger <[email protected]>--- drivers/char/tpm/tpm_eventlog.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)drivers/char/tpm/tpm_eventlog.c +0
-4@@ -455,10 +455,12 @@ void tpm_bios_log_teardown(struct tpm_chip *chip)* This design ensures that open() either safely gets kref or fails. */ for (i = (TPM_NUM_EVENT_LOG_FILES -1 ); i >=0 ; i--) { - inode =d_inode (chip->bios_dir[i]); -inode_lock (inode); - inode->i_private =NULL ; -inode_unlock (inode);
drivers/char/tpm/tpm_eventlog.c void tpm_bios_log_teardown(struct tpm_chip *chip) · line 466
Quoted 10 lines
drivers/char/tpm/tpm_eventlog.c +7
-1-securityfs_remove (chip->bios_dir[i]); +if (chip->bios_dir[i]) { + inode =d_inode (chip->bios_dir[i]); +inode_lock (inode); + inode->i_private =NULL ; +inode_unlock (inode); +securityfs_remove (chip->bios_dir[i]); + } } }
------------------------------------------------------------------------------
Jarkko Sakkinen
Reviewed-byQuoted 5 lines · Stefan Berger
Check the
bios_direntry for NULL before accessing it. Currently this crashes the driver when a TPM 2 is attached and the entries are NULL.Signed-off-by Stefan Berger <[email protected]>
Quoted 28 lines
--- drivers/char/tpm/tpm_eventlog.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)drivers/char/tpm/tpm_eventlog.c +7
-5@@ -455,10 +455,12 @@ void tpm_bios_log_teardown(struct tpm_chip *chip)* This design ensures that open() either safely gets kref or fails. */ for (i = (TPM_NUM_EVENT_LOG_FILES -1 ); i >=0 ; i--) { - inode =d_inode (chip->bios_dir[i]); -inode_lock (inode); - inode->i_private =NULL ; -inode_unlock (inode); -securityfs_remove (chip->bios_dir[i]); +if (chip->bios_dir[i]) { + inode =d_inode (chip->bios_dir[i]); +inode_lock (inode); + inode->i_private =NULL ; +inode_unlock (inode); +securityfs_remove (chip->bios_dir[i]); + } } }Signature · 1 line
2.4.3
/Jarkko
------------------------------------------------------------------------------
Quoted 11 lines · Nayna
Quoted 3 lines · Stefan Berger
Check the
bios_direntry for NULL before accessing it. Currently this crashes the driver when a TPM 2 is attached and the entries are NULL.Thanks Stefan !! I think it would be good to also add Fixes in commit description here.
Fixes d660a91a1b9d (tpm: adds NULL check for securityfs pseudo files)
Not mandatory as this is not in the mainline tree but doesn't hurt either.
/Jarkko
Quoted 25 lines
Thanks & Regards,
- NaynaQuoted 21 lines
Signed-off-by Stefan Berger <[email protected]>--- drivers/char/tpm/tpm_eventlog.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)drivers/char/tpm/tpm_eventlog.c +2
-5@@ -455,10 +455,12 @@ void tpm_bios_log_teardown(struct tpm_chip *chip)* This design ensures that open() either safely gets kref or fails. */ for (i = (TPM_NUM_EVENT_LOG_FILES -1 ); i >=0 ; i--) { - inode =d_inode (chip->bios_dir[i]); -inode_lock (inode); - inode->i_private =NULL ; -inode_unlock (inode); -securityfs_remove (chip->bios_dir[i]); +if (chip->bios_dir[i]) { + inode =d_inode (chip->bios_dir[i]);
Quoted 9 lines
drivers/char/tpm/tpm_eventlog.c void tpm_bios_log_teardown(struct tpm_chip *chip) · line 466
Quoted 8 lines
drivers/char/tpm/tpm_eventlog.c +5
-0+inode_lock (inode); + inode->i_private =NULL ; +inode_unlock (inode); +securityfs_remove (chip->bios_dir[i]); + } } }
------------------------------------------------------------------------------
Quoted 6 lines · Jarkko Sakkinen
Quoted 5 lines · Nayna
Quoted 3 lines · Stefan Berger
Check the
bios_direntry for NULL before accessing it. Currently this crashes the driver when a TPM 2 is attached and the entries are NULL.
Quoted 6 lines
Quoted 4 lines
Thanks Stefan !! I think it would be good to also add Fixes in commit description here.
Fixes d660a91a1b9d (tpm: adds NULL check for securityfs pseudo files)Not mandatory as this is not in the mainline tree but doesn't hurt either.
I wished you could just merge this fix patch into Nayna's original patch -- makes bisecting the code a lot easier.
Stefan
Quoted 26 lines
/Jarkko
Quoted 23 lines
Thanks & Regards,
- NaynaQuoted 20 lines
Signed-off-by Stefan Berger <[email protected]>--- drivers/char/tpm/tpm_eventlog.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)drivers/char/tpm/tpm_eventlog.c +2
-5@@ -455,10 +455,12 @@ void tpm_bios_log_teardown(struct tpm_chip *chip)* This design ensures that open() either safely gets kref or fails. */ for (i = (TPM_NUM_EVENT_LOG_FILES -1 ); i >=0 ; i--) { - inode =d_inode (chip->bios_dir[i]); -inode_lock (inode); - inode->i_private =NULL ; -inode_unlock (inode); -securityfs_remove (chip->bios_dir[i]); +if (chip->bios_dir[i]) { + inode =d_inode (chip->bios_dir[i]);
Quoted 8 lines
Quoted 8 lines
drivers/char/tpm/tpm_eventlog.c void tpm_bios_log_teardown(struct tpm_chip *chip) · line 466
Quoted 8 lines
drivers/char/tpm/tpm_eventlog.c +5
-0+inode_lock (inode); + inode->i_private =NULL ; +inode_unlock (inode); +securityfs_remove (chip->bios_dir[i]); + } } }
------------------------------------------------------------------------------
Quoted 10 lines · Stefan Berger
Quoted 9 lines · Jarkko Sakkinen
Quoted 8 lines · Nayna
Quoted 3 lines · Stefan Berger
Check the
bios_direntry for NULL before accessing it. Currently this crashes the driver when a TPM 2 is attached and the entries are NULL.Thanks Stefan !! I think it would be good to also add Fixes in commit description here.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Fixes d660a91a1b9d (tpm: adds NULL check for securityfs pseudo files)Not mandatory as this is not in the mainline tree but doesn't hurt either.
I wished you could just merge this fix patch into Nayna's original patch -- makes bisecting the code a lot easier.
Stefan
Works for me.
/Jarkko
Quoted 27 lines
Quoted 27 lines
/Jarkko
Quoted 23 lines
Thanks & Regards,
- NaynaQuoted 20 lines
Signed-off-by Stefan Berger <[email protected]>--- drivers/char/tpm/tpm_eventlog.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)drivers/char/tpm/tpm_eventlog.c +2
-5@@ -455,10 +455,12 @@ void tpm_bios_log_teardown(struct tpm_chip *chip)* This design ensures that open() either safely gets kref or fails. */ for (i = (TPM_NUM_EVENT_LOG_FILES -1 ); i >=0 ; i--) { - inode =d_inode (chip->bios_dir[i]); -inode_lock (inode); - inode->i_private =NULL ; -inode_unlock (inode); -securityfs_remove (chip->bios_dir[i]); +if (chip->bios_dir[i]) { + inode =d_inode (chip->bios_dir[i]);
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
drivers/char/tpm/tpm_eventlog.c void tpm_bios_log_teardown(struct tpm_chip *chip) · line 466
Quoted 8 lines
drivers/char/tpm/tpm_eventlog.c +5
-0+inode_lock (inode); + inode->i_private =NULL ; +inode_unlock (inode); +securityfs_remove (chip->bios_dir[i]); + } } }
------------------------------------------------------------------------------
Quoted 3 lines · Stefan Berger
Check the
bios_direntry for NULL before accessing it. Currently this crashes the driver when a TPM 2 is attached and the entries are NULL.
Yep
drivers/char/tpm/tpm_eventlog.c void tpm_bios_log_teardown(struct tpm_chip *chip) · line 458
Quoted 7 lines
drivers/char/tpm/tpm_eventlog.c +1
-5for (i = (TPM_NUM_EVENT_LOG_FILES -1 ); i >=0 ; i--) { - inode =d_inode (chip->bios_dir[i]); -inode_lock (inode); - inode->i_private =NULL ; -inode_unlock (inode); -securityfs_remove (chip->bios_dir[i]); +if (chip->bios_dir[i]) {
Nope, this must be is_err_or_null, we store err ptrs in this array.
Jason
------------------------------------------------------------------------------
Quoted 7 lines · Jason Gunthorpe
Quoted 3 lines · Stefan Berger
Check the
bios_direntry for NULL before accessing it. Currently this crashes the driver when a TPM 2 is attached and the entries are NULL.Yep
Quoted 9 lines
drivers/char/tpm/tpm_eventlog.c void tpm_bios_log_teardown(struct tpm_chip *chip) · line 458
Quoted 7 lines
drivers/char/tpm/tpm_eventlog.c +1
-5for (i = (TPM_NUM_EVENT_LOG_FILES -1 ); i >=0 ; i--) { - inode =d_inode (chip->bios_dir[i]); -inode_lock (inode); - inode->i_private =NULL ; -inode_unlock (inode); -securityfs_remove (chip->bios_dir[i]); +if (chip->bios_dir[i]) {Nope, this must be
is_err_or_null, we store err ptrs in this array.
"
err:
chip->bios_dir[cnt] = NULL;
"
There is assignment to NULL so this should be fine.
/JArko
------------------------------------------------------------------------------
Jarkko Sakkinen
AppliedQuoted 18 lines · Jarkko Sakkinen
Quoted 7 lines · Jason Gunthorpe
Quoted 3 lines · Stefan Berger
Check the
bios_direntry for NULL before accessing it. Currently this crashes the driver when a TPM 2 is attached and the entries are NULL.Yep
Quoted 9 lines
drivers/char/tpm/tpm_eventlog.c void tpm_bios_log_teardown(struct tpm_chip *chip) · line 458
Quoted 7 lines
drivers/char/tpm/tpm_eventlog.c +1
-5for (i = (TPM_NUM_EVENT_LOG_FILES -1 ); i >=0 ; i--) { - inode =d_inode (chip->bios_dir[i]); -inode_lock (inode); - inode->i_private =NULL ; -inode_unlock (inode); -securityfs_remove (chip->bios_dir[i]); +if (chip->bios_dir[i]) {Nope, this must be
is_err_or_null, we store err ptrs in this array.
Quoted 6 lines
"
err:chip->bios_dir[cnt] = NULL;"
There is assignment to NULL so this should be fine.
Applied. Not yet squashed. I'll save that for the next week and possible other squashes to the point when I prepare the pull request.
/Jarkko
------------------------------------------------------------------------------
Quoted 9 lines · Jarkko Sakkinen
Quoted 2 lines
Nope, this must be
is_err_or_null, we store err ptrs in this array."
err:chip->bios_dir[cnt] = NULL;"
There is assignment to NULL so this should be fine.
Oh good, I'm glad that made it in
Jason
------------------------------------------------------------------------------