]> git.baikalelectronics.ru Git - kernel.git/commitdiff
crypto: ccp - During shutdown, check SEV data pointer before using
authorTom Lendacky <thomas.lendacky@amd.com>
Thu, 16 Jun 2022 15:26:18 +0000 (10:26 -0500)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 24 Jun 2022 09:12:29 +0000 (17:12 +0800)
On shutdown, each CCP device instance performs shutdown processing.
However, __sev_platform_shutdown_locked() uses the controlling psp
structure to obtain the pointer to the sev_device structure. However,
during driver initialization, it is possible that an error can be received
from the firmware that results in the sev_data pointer being cleared from
the controlling psp structure. The __sev_platform_shutdown_locked()
function does not check for this situation and will segfault.

While not common, this scenario should be accounted for. Add a check for a
NULL sev_device structure before attempting to use it.

Fixes: 9ad48cb6c76c ("crypto: ccp - shutdown SEV firmware on kexec")
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/ccp/sev-dev.c

index 0c92d940ac4ef71e843542113b59c7ba32df3dc7..9f588c9728f8b20e9f63ca284ee1e37993ff31ed 100644 (file)
@@ -503,7 +503,7 @@ static int __sev_platform_shutdown_locked(int *error)
        struct sev_device *sev = psp_master->sev_data;
        int ret;
 
-       if (sev->state == SEV_STATE_UNINIT)
+       if (!sev || sev->state == SEV_STATE_UNINIT)
                return 0;
 
        ret = __sev_do_cmd_locked(SEV_CMD_SHUTDOWN, NULL, error);