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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 17 Aug 2022 12:23:23 +0000 (14:23 +0200)
commitf831d2882c843d44100016aeb4332e9c4b560805
tree048018b55e564cb9f892fb41f38b4443cb238102
parent8f458e34a804325bf490a49755653b3a61aa73d9
crypto: ccp - During shutdown, check SEV data pointer before using

[ Upstream commit 1b05ece0c931536c0a38a9385e243a7962e933f6 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/crypto/ccp/sev-dev.c