Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crypto: ccp - During shutdown, check SEV data pointer before using

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: 5441a07a127f ("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>

authored by

Tom Lendacky and committed by
Herbert Xu
1b05ece0 bffa1fc0

+1 -1
+1 -1
drivers/crypto/ccp/sev-dev.c
··· 503 503 struct sev_device *sev = psp_master->sev_data; 504 504 int ret; 505 505 506 - if (sev->state == SEV_STATE_UNINIT) 506 + if (!sev || sev->state == SEV_STATE_UNINIT) 507 507 return 0; 508 508 509 509 ret = __sev_do_cmd_locked(SEV_CMD_SHUTDOWN, NULL, error);