Skip to contentSkip to conversation

tpm: Check the bios_dir entry for NULL before accessing it

PATCH Applied Stefan Berger 4 participants 10 messages Nov 16, 2016 6 messages not in the archive TPM device driver

lore
Share & tools
lore
#0 lore raw

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
index ebec4ac..fb603a7 100644
@@ -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


------------------------------------------------------------------------------
#2 lore raw
In reply to a message not in the archive
Quoted 3 lines · Stefan Berger

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.

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)

Thanks & Regards,
- Nayna

Quoted 19 lines
---
  drivers/char/tpm/tpm_eventlog.c | 12 +++++++-----
  1 file changed, 7 insertions(+), 5 deletions(-)
drivers/char/tpm/tpm_eventlog.c +0 -4
index ebec4ac..fb603a7 100644
@@ -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]);
+		}
  	}
  }

------------------------------------------------------------------------------

Reviewed-by
#9 lore raw
In reply to a message not in the archive
Quoted 5 lines · Stefan Berger

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.

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
index ebec4ac..fb603a7 100644
@@ -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

------------------------------------------------------------------------------

#4 lore raw
In reply to a message not in the archive
Quoted 11 lines · Nayna
Quoted 3 lines · Stefan Berger

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.

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,
- Nayna

Quoted 21 lines
---
  drivers/char/tpm/tpm_eventlog.c | 12 +++++++-----
  1 file changed, 7 insertions(+), 5 deletions(-)
drivers/char/tpm/tpm_eventlog.c +2 -5
index ebec4ac..fb603a7 100644
@@ -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]);
+		}
  	}
  }

------------------------------------------------------------------------------

#6 lore raw
In reply to a message not in the archive
Quoted 6 lines · Jarkko Sakkinen
Quoted 5 lines · Nayna
Quoted 3 lines · Stefan Berger

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.

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,
- Nayna

Quoted 20 lines
---
   drivers/char/tpm/tpm_eventlog.c | 12 +++++++-----
   1 file changed, 7 insertions(+), 5 deletions(-)
drivers/char/tpm/tpm_eventlog.c +2 -5
index ebec4ac..fb603a7 100644
@@ -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]);
+		}
   	}
   }

------------------------------------------------------------------------------

#8 lore raw
In reply to a message not in the archive
Quoted 10 lines · Stefan Berger
Quoted 9 lines · Jarkko Sakkinen
Quoted 8 lines · Nayna
Quoted 3 lines · Stefan Berger

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.

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,
- Nayna

Quoted 20 lines
---
   drivers/char/tpm/tpm_eventlog.c | 12 +++++++-----
   1 file changed, 7 insertions(+), 5 deletions(-)
drivers/char/tpm/tpm_eventlog.c +2 -5
index ebec4ac..fb603a7 100644
@@ -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]);
+		}
   	}
   }

------------------------------------------------------------------------------

#10 lore raw
In reply to a message not in the archive
Quoted 3 lines · Stefan Berger

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.

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 -5
 	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]) {

Nope, this must be is_err_or_null, we store err ptrs in this array.

Jason

------------------------------------------------------------------------------

#12 lore raw
In reply to a message not in the archive
Quoted 7 lines · Jason Gunthorpe
Quoted 3 lines · Stefan Berger

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.

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 -5
 	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]) {

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

------------------------------------------------------------------------------

#14 lore raw
In reply to a message not in the archive
Quoted 18 lines · Jarkko Sakkinen
Quoted 7 lines · Jason Gunthorpe
Quoted 3 lines · Stefan Berger

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.

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 -5
 	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]) {

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

------------------------------------------------------------------------------

#15 lore raw
In reply to a message not in the archive
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

------------------------------------------------------------------------------