linux/drivers/crypto
Borislav Petkov (AMD) 46834d90a9 crypto: ccp - Always pass in an error pointer to __sev_platform_shutdown_locked()
When

  9770b428b1 ("crypto: ccp - Move dev_info/err messages for SEV/SNP init and shutdown")

moved the error messages dumping so that they don't need to be issued by
the callers, it missed the case where __sev_firmware_shutdown() calls
__sev_platform_shutdown_locked() with a NULL argument which leads to
a NULL ptr deref on the shutdown path, during suspend to disk:

  #PF: supervisor read access in kernel mode
  #PF: error_code(0x0000) - not-present page
  PGD 0 P4D 0
  Oops: Oops: 0000 [#1] SMP NOPTI
  CPU: 0 UID: 0 PID: 983 Comm: hib.sh Not tainted 6.17.0-rc4+ #1 PREEMPT(voluntary)
  Hardware name: Supermicro Super Server/H12SSL-i, BIOS 2.5 09/08/2022
  RIP: 0010:__sev_platform_shutdown_locked.cold+0x0/0x21 [ccp]

That rIP is:

  00000000000006fd <__sev_platform_shutdown_locked.cold>:
   6fd:   8b 13                   mov    (%rbx),%edx
   6ff:   48 8b 7d 00             mov    0x0(%rbp),%rdi
   703:   89 c1                   mov    %eax,%ecx

  Code: 74 05 31 ff 41 89 3f 49 8b 3e 89 ea 48 c7 c6 a0 8e 54 a0 41 bf 92 ff ff ff e8 e5 2e 09 e1 c6 05 2a d4 38 00 01 e9 26 af ff ff <8b> 13 48 8b 7d 00 89 c1 48 c7 c6 18 90 54 a0 89 44 24 04 e8 c1 2e
  RSP: 0018:ffffc90005467d00 EFLAGS: 00010282
  RAX: 00000000ffffff92 RBX: 0000000000000000 RCX: 0000000000000000
  			     ^^^^^^^^^^^^^^^^
and %rbx is nice and clean.

  Call Trace:
   <TASK>
   __sev_firmware_shutdown.isra.0
   sev_dev_destroy
   psp_dev_destroy
   sp_destroy
   pci_device_shutdown
   device_shutdown
   kernel_power_off
   hibernate.cold
   state_store
   kernfs_fop_write_iter
   vfs_write
   ksys_write
   do_syscall_64
   entry_SYSCALL_64_after_hwframe

Pass in a pointer to the function-local error var in the caller.

With that addressed, suspending the ccp shows the error properly at
least:

  ccp 0000:47:00.1: sev command 0x2 timed out, disabling PSP
  ccp 0000:47:00.1: SEV: failed to SHUTDOWN error 0x0, rc -110
  SEV-SNP: Leaking PFN range 0x146800-0x146a00
  SEV-SNP: PFN 0x146800 unassigned, dumping non-zero entries in 2M PFN region: [0x146800 - 0x146a00]
  ...
  ccp 0000:47:00.1: SEV-SNP firmware shutdown failed, rc -16, error 0x0
  ACPI: PM: Preparing to enter system sleep state S5
  kvm: exiting hardware virtualization
  reboot: Power down

Btw, this driver is crying to be cleaned up to pass in a proper I/O
struct which can be used to store information between the different
functions, otherwise stuff like that will happen in the future again.

Fixes: 9770b428b1 ("crypto: ccp - Move dev_info/err messages for SEV/SNP init and shutdown")
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Cc: <stable@kernel.org>
Reviewed-by: Ashish Kalra <ashish.kalra@amd.com>
Acked-by: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2025-09-13 12:07:44 +08:00
..
allwinner crypto: sun8i-ce - use helpers to get hash block and digest sizes 2025-06-13 17:26:16 +08:00
amcc crypto: crypto4xx - Remove ahash-related code 2025-05-12 13:32:52 +08:00
amlogic crypto: drivers - Switch back to struct platform_driver::remove() 2024-10-19 08:44:30 +08:00
aspeed crypto: aspeed - Fix hash fallback path typo 2025-06-26 12:56:26 +08:00
axis treewide, timers: Rename from_timer() to timer_container_of() 2025-06-08 09:07:37 +02:00
bcm crypto: bcm - set memory to zero only once 2025-02-22 15:56:03 +08:00
caam crypto: engine - remove request batching support 2025-07-18 20:52:00 +10:00
cavium crypto: cavium/zip - Remove driver 2025-04-07 13:22:25 +08:00
ccp crypto: ccp - Always pass in an error pointer to __sev_platform_shutdown_locked() 2025-09-13 12:07:44 +08:00
ccree crypto: drivers - Remove redundant pm_runtime_mark_last_busy() calls 2025-07-18 20:51:59 +10:00
chelsio crypto: chelsio - Use crypto_shash_export_core 2025-06-26 12:55:22 +08:00
gemini crypto: drivers - Switch back to struct platform_driver::remove() 2024-10-19 08:44:30 +08:00
hisilicon crypto: hisilicon/hpre - fix dma unmap sequence 2025-07-27 22:41:45 +10:00
inside-secure This update includes the following changes: 2025-07-31 09:45:28 -07:00
intel This update includes the following changes: 2025-07-31 09:45:28 -07:00
marvell This update includes the following changes: 2025-07-31 09:45:28 -07:00
nx crypto: nx - Use API partial block handling 2025-04-23 15:52:47 +08:00
qce crypto: qce - revert "use __free() for a buffer that's always freed" 2024-12-21 22:46:24 +08:00
rockchip crypto: rk3288 - use API helpers to setup fallback request 2025-04-16 15:16:21 +08:00
starfive crypto: sha256 - Wrap library and add HMAC support 2025-07-04 10:23:11 -07:00
stm32 This update includes the following changes: 2025-07-31 09:45:28 -07:00
tegra crypto: tegra - use API helpers to setup fallback request 2025-04-16 15:16:21 +08:00
virtio crypto: engine - remove request batching support 2025-07-18 20:52:00 +10:00
xilinx crypto: zynqmp-sha - Fix partial block implementation 2025-05-05 18:20:46 +08:00
Kconfig crypto: s390 - New s390 specific protected key hash phmac 2025-06-26 18:52:33 +08:00
Makefile crypto: cavium - Move cpt and nitrox rules into cavium Makefile 2025-04-07 13:22:25 +08:00
atmel-aes-regs.h
atmel-aes.c crypto: atmel - add support for AES and SHA IPs available on sama7d65 SoC 2025-06-23 16:59:38 +08:00
atmel-authenc.h
atmel-ecc.c crypto: atmel - Drop explicit initialization of struct i2c_device_id::driver_data to 0 2024-10-05 13:22:05 +08:00
atmel-i2c.c crypto: atmel-sha204a - add reading from otp zone 2024-05-10 17:15:25 +08:00
atmel-i2c.h crypto: atmel-sha204a - add reading from otp zone 2024-05-10 17:15:25 +08:00
atmel-sha-regs.h
atmel-sha.c crypto: atmel - add support for AES and SHA IPs available on sama7d65 SoC 2025-06-23 16:59:38 +08:00
atmel-sha204a.c crypto: atmel-sha204a - Set hwrng quality to lowest possible 2025-04-23 09:32:57 +08:00
atmel-tdes-regs.h
atmel-tdes.c crypto: atmel - add CRYPTO_ALG_KERN_DRIVER_ONLY flag 2025-04-16 15:16:21 +08:00
exynos-rng.c crypto: drivers - Switch back to struct platform_driver::remove() 2024-10-19 08:44:30 +08:00
geode-aes.c module: Convert symbol namespace to string literal 2024-12-02 11:34:44 -08:00
geode-aes.h
hifn_795x.c crypto: hifn_795x - Remove unused hifn_*_command structs 2024-05-31 17:34:56 +08:00
img-hash.c This update includes the following changes: 2025-07-31 09:45:28 -07:00
mxs-dcp.c crypto: mxs-dcp - Only set OTP_KEY bit for OTP key 2025-03-08 16:22:23 +08:00
omap-aes-gcm.c crypto: drivers - Remove redundant pm_runtime_mark_last_busy() calls 2025-07-18 20:51:59 +10:00
omap-aes.c crypto: drivers - Remove redundant pm_runtime_mark_last_busy() calls 2025-07-18 20:51:59 +10:00
omap-aes.h crypto: omap - switch from scatter_walk to plain offset 2025-01-14 11:38:32 +08:00
omap-crypto.c
omap-crypto.h
omap-des.c crypto: drivers - Remove redundant pm_runtime_mark_last_busy() calls 2025-07-18 20:51:59 +10:00
omap-sham.c crypto: drivers - Remove redundant pm_runtime_mark_last_busy() calls 2025-07-18 20:51:59 +10:00
padlock-aes.c
padlock-sha.c crypto: padlock-sha - Use core import and export for fallback 2025-05-05 18:20:46 +08:00
qcom-rng.c crypto: drivers - Switch back to struct platform_driver::remove() 2024-10-19 08:44:30 +08:00
s5p-sss.c crypto: s5p-sss - Add missing header inclusions 2025-04-16 15:16:21 +08:00
sa2ul.c crypto: sa2ul - Use proper helpers to setup request 2025-04-07 13:22:26 +08:00
sa2ul.h
sahara.c crypto: drivers - Switch back to struct platform_driver::remove() 2024-10-19 08:44:30 +08:00
talitos.c crypto: drivers - Switch back to struct platform_driver::remove() 2024-10-19 08:44:30 +08:00
talitos.h