lkml.org 
[lkml]   [2021]   [Dec]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH v2] tpm: fix potential NULL pointer access in tpm_del_char_device
From
Date

Hi Stefan,


On 22.12.21 at 05:53, Stefan Berger wrote:

>>
>>   drivers/char/tpm/tpm-chip.c | 16 +++++++++++-----
>>   1 file changed, 11 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
>> index ddaeceb7e109..7960da490e72 100644
>> --- a/drivers/char/tpm/tpm-chip.c
>> +++ b/drivers/char/tpm/tpm-chip.c
>> @@ -474,13 +474,19 @@ 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) {
>> -        if (!tpm_chip_start(chip)) {
>> -            tpm2_shutdown(chip, TPM2_SU_CLEAR);
>> -            tpm_chip_stop(chip);
>> +    /* Check if chip->ops is still valid: In case that the controller
>> +     * drivers shutdown handler unregisters the controller in its
>> +     * shutdown handler we are called twice and chip->ops to NULL.
>> +     */
>> +    if (chip->ops) {
>> +        if (chip->flags & TPM_CHIP_FLAG_TPM2) {
>> +            if (!tpm_chip_start(chip)) {
>> +                tpm2_shutdown(chip, TPM2_SU_CLEAR);
>> +                tpm_chip_stop(chip);
>> +            }
>>           }
>> +        chip->ops = NULL;
>>       }
>> -    chip->ops = NULL;
>>       up_write(&chip->ops_sem);
>>   }
>>  
>> base-commit: a7904a538933c525096ca2ccde1e60d0ee62c08e
>
>
> Fixes: 39d0099f9439 ("powerpc/pseries: Add shutdown() to vio_driver and vio_bus")
>
> Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
>
> Tested-by: Stefan Berger <stefanb@linux.ibm.com>
>
>

Thanks a lot for testing this.

Best regards,
Lino

\
 
 \ /
  Last update: 2021-12-22 07:57    [W:0.056 / U:0.072 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site