tpm: fix crash in tpm_tis deinitialization
PATCH 1/1 tpm: fix crash in tpm_tis deinitialization
rmmod crashes the driver because tpm_chip_unregister() already sets ops to NULL. This commit fixes the issue by moving tpm2_shutdown() to tpm_chip_unregister(). This commit is also cleanup because it removes duplicate code from tpm_crb and tpm_tis to the core.
--- drivers/char/tpm/tpm-chip.c | 3 +++ drivers/char/tpm/tpm_crb.c | 3 --- drivers/char/tpm/tpm_tis.c | 3 --- 3 files changed, 3 insertions(+), 6 deletions(-)
drivers/char/tpm/tpm-chip.c +3 -0
@@ -361,6 +361,9 @@ void tpm_chip_unregister(struct tpm_chip *chip)if (!(chip->flags &TPM_CHIP_FLAG_REGISTERED ))return ; +if (chip->flags &TPM_CHIP_FLAG_TPM2 ) +tpm2_shutdown (chip,TPM2_SU_CLEAR ); +if (!(chip->flags &TPM_CHIP_FLAG_TPM2 ))sysfs_remove_link (&chip->dev.parent->kobj,"ppi" );
drivers/char/tpm/tpm_crb.c +0 -3
@@ -341,9 +341,6 @@ static int crb_acpi_remove(struct acpi_device *device)struct device *dev = &device->dev;struct tpm_chip *chip =dev_get_drvdata (dev); -if (chip->flags &TPM_CHIP_FLAG_TPM2 ) -tpm2_shutdown (chip,TPM2_SU_CLEAR ); -tpm_chip_unregister (chip);return 0 ;
drivers/char/tpm/tpm_tis.c +0 -3
@@ -681,9 +681,6 @@ static void tpm_tis_remove(struct tpm_chip *chip)struct priv_data *priv =dev_get_drvdata (&chip->dev);void __iomem *reg = priv->iobase +TPM_INT_ENABLE (priv->locality); -if (chip->flags &TPM_CHIP_FLAG_TPM2 ) -tpm2_shutdown (chip,TPM2_SU_CLEAR ); -iowrite32 (~TPM_GLOBAL_INT_ENABLE &ioread32 (reg), reg);release_locality (chip, priv->locality,1 ); }
Signature · 9 lines
2.7.4 ------------------------------------------------------------------------------ Find and fix application performance issues faster with Applications Manager Applications Manager provides deep performance insights into multiple tiers of your business applications. It resolves application problems quickly and reduces your MTTR. Get your free trial! http://pubads.g.doubleclick.net/ gampad/clk?id=1444514301&iu=/ca-pub-7940484522588532
Quoted 16 lines · Jarkko Sakkinen
rmmod crashes the driver because
tpm_chip_unregister()already sets ops to NULL. This commit fixes the issue by movingtpm2_shutdown()totpm_chip_unregister(). This commit is also cleanup because it removes duplicate code fromtpm_crbandtpm_tisto the core.Fixes 4d3eac5e156a ("tpm: Provide strong locking for device removal")drivers/char/tpm/tpm-chip.c | 3 +++ drivers/char/tpm/tpm_crb.c | 3 --- drivers/char/tpm/tpm_tis.c | 3 --- 3 files changed, 3 insertions(+), 6 deletions(-)drivers/char/tpm/tpm-chip.c +1
-0+++ b/drivers/char/tpm/tpm-chip.c
drivers/char/tpm/tpm-chip.c void tpm_chip_unregister(struct tpm_chip *chip) · line 368
Quoted 8 lines
drivers/char/tpm/tpm-chip.c +3
-0@@ -361,6 +361,9 @@ void tpm_chip_unregister(struct tpm_chip *chip)if (!(chip->flags &TPM_CHIP_FLAG_REGISTERED ))return ; +if (chip->flags &TPM_CHIP_FLAG_TPM2 ) +tpm2_shutdown (chip,TPM2_SU_CLEAR ); +if (!(chip->flags &TPM_CHIP_FLAG_TPM2 ))sysfs_remove_link (&chip->dev.parent->kobj,"ppi" );
This needs to be after ops is fenced, something like this.
drivers/char/tpm/tpm-chip.c +2 -3
@@ -269,6 +269,8 @@ static void tpm_del_char_device(struct tpm_chip *chip)/* Make the driver uncallable. */ down_write (&chip->ops_sem); +if (chip->flags &TPM_CHIP_FLAG_TPM2 ) +tpm2_shutdown (chip,TPM2_SU_CLEAR ); chip->ops =NULL ;up_write (&chip->ops_sem); }
@@ -361,9 +363,6 @@ void tpm_chip_unregister(struct tpm_chip *chip)if (!(chip->flags &TPM_CHIP_FLAG_REGISTERED ))return ; -if (chip->flags &TPM_CHIP_FLAG_TPM2 ) -tpm2_shutdown (chip,TPM2_SU_CLEAR ); -if (!(chip->flags &TPM_CHIP_FLAG_TPM2 ))sysfs_remove_link (&chip->dev.parent->kobj,"ppi" );
------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager Applications Manager provides deep performance insights into multiple tiers of your business applications. It resolves application problems quickly and reduces your MTTR. Get your free trial! http://pubads.g.doubleclick.net/
gampad/clk?id=1444514301&iu=/ca-pub-7940484522588532
Quoted 20 lines · Jason Gunthorpe
Quoted 19 lines · Jarkko Sakkinen
rmmod crashes the driver because
tpm_chip_unregister()already sets ops to NULL. This commit fixes the issue by movingtpm2_shutdown()totpm_chip_unregister(). This commit is also cleanup because it removes duplicate code fromtpm_crbandtpm_tisto the core.Fixes 4d3eac5e156a ("tpm: Provide strong locking for device removal")drivers/char/tpm/tpm-chip.c | 3 +++ drivers/char/tpm/tpm_crb.c | 3 --- drivers/char/tpm/tpm_tis.c | 3 --- 3 files changed, 3 insertions(+), 6 deletions(-)drivers/char/tpm/tpm-chip.c +1
-0+++ b/drivers/char/tpm/tpm-chip.c@@ -361,6 +361,9 @@ void tpm_chip_unregister(struct tpm_chip *chip)if (!(chip->flags &TPM_CHIP_FLAG_REGISTERED ))return ;
Quoted 7 lines
drivers/char/tpm/tpm-chip.c void tpm_chip_unregister(struct tpm_chip *chip) · line 368
Quoted 5 lines
drivers/char/tpm/tpm-chip.c +3
-0+if (chip->flags &TPM_CHIP_FLAG_TPM2 ) +tpm2_shutdown (chip,TPM2_SU_CLEAR ); +if (!(chip->flags &TPM_CHIP_FLAG_TPM2 ))sysfs_remove_link (&chip->dev.parent->kobj,"ppi" );This needs to be after ops is fenced, something like this.
I would appreciate a supporting argument.
I guess the argument here is that this will prevent user space from issuing TPM commands after the shutdown command has been sent?
/Jarkko
Quoted 14 lines
drivers/char/tpm/tpm-chip.c +2
-0@@ -269,6 +269,8 @@ static void tpm_del_char_device(struct tpm_chip *chip)/* Make the driver uncallable. */ down_write (&chip->ops_sem); +if (chip->flags &TPM_CHIP_FLAG_TPM2 ) +tpm2_shutdown (chip,TPM2_SU_CLEAR ); chip->ops =NULL ;up_write (&chip->ops_sem); }
drivers/char/tpm/tpm-chip.c void tpm_chip_unregister(struct tpm_chip *chip) · line 368
Quoted 9 lines
drivers/char/tpm/tpm-chip.c +0
-3@@ -361,9 +363,6 @@ void tpm_chip_unregister(struct tpm_chip *chip)if (!(chip->flags &TPM_CHIP_FLAG_REGISTERED ))return ; -if (chip->flags &TPM_CHIP_FLAG_TPM2 ) -tpm2_shutdown (chip,TPM2_SU_CLEAR ); -if (!(chip->flags &TPM_CHIP_FLAG_TPM2 ))sysfs_remove_link (&chip->dev.parent->kobj,"ppi" );
------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager Applications Manager provides deep performance insights into multiple tiers of your business applications. It resolves application problems quickly and reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
Quoted 6 lines · Jarkko Sakkinen
Quoted 1 line
This needs to be after ops is fenced, something like this.
I would appreciate a supporting argument.
I guess the argument here is that this will prevent user space from issuing TPM commands after the shutdown command has been sent?
It prevents everything including the kernel from issuing a command after shutdown. The shutdown is sent as the last command and no other commands can follow it.
It doesn't make any sense to allow commands to follow shutdown.
Jason
------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager Applications Manager provides deep performance insights into multiple tiers of your business applications. It resolves application problems quickly and reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
Quoted 9 lines · Jason Gunthorpe
Quoted 6 lines · Jarkko Sakkinen
Quoted 1 line
This needs to be after ops is fenced, something like this.
I would appreciate a supporting argument.
I guess the argument here is that this will prevent user space from issuing TPM commands after the shutdown command has been sent?
It prevents everything including the kernel from issuing a command
^^^^^^^^^^^^^^^^^^^^
That lock is not used to exclude kernel access. Read lock is only taken for the user space device in tpm-dev.c.
Quoted 4 lines
after shutdown. The shutdown is sent as the last command and no other commands can follow it.
It doesn't make any sense to allow commands to follow shutdown.
I agree with this.
Quoted 1 line
Jason
/Jarkko
------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager Applications Manager provides deep performance insights into multiple tiers of your business applications. It resolves application problems quickly and reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
Quoted 6 lines · Jarkko Sakkinen
Quoted 5 lines · Jason Gunthorpe
Quoted 4 lines · Jarkko Sakkinen
Quoted 1 line
This needs to be after ops is fenced, something like this.
I would appreciate a supporting argument.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
I guess the argument here is that this will prevent user space from issuing TPM commands after the shutdown command has been sent?
It prevents everything including the kernel from issuing a command
^^^^^^^^^^^^^^^^^^^^That lock is not used to exclude kernel access. Read lock is only taken for the user space device in
tpm-dev.c.
My bad. For the in-kernel API it is taken through tpm_find_get().
I'll update the fix.
/Jarkko
Quoted 7 lines · Jarkko Sakkinen
Quoted 5 lines
Quoted 1 line
It prevents everything including the kernel from issuing a command
^^^^^^^^^^^^^^^^^^^^That lock is not used to exclude kernel access. Read lock is only taken for the user space device in
tpm-dev.c.My bad. For the in-kernel API it is taken through
tpm_find_get().
Right. At this point any thing that can run in-kernel concurrently with the write exclusion is a kernel bug. Those places will need to grab the read side of the lock.
Jason
------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager Applications Manager provides deep performance insights into multiple tiers of your business applications. It resolves application problems quickly and reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z