crypto: ccp: Sanitize sev_platform_init() error messages
Subsystems (6)
PATCH v2 1/1 crypto: ccp: Sanitize sev_platform_init() error messages
The following functions end up calling sev_platform_init() or __sev_platform_init_locked():
* sev_guest_init()
* sev_ioctl_do_pek_csr
* sev_ioctl_do_pdh_export()
* sev_ioctl_do_pek_import()
* sev_ioctl_do_pek_pdh_gen()
* sev_pci_init()
However, only sev_pci_init() prints out the failed command error code, and even there the error message does not specify, SEV which command failed.
Address this by printing out the SEV command errors inside __sev_platform_init_locked(), and differentiate between DF_FLUSH, INIT and INIT_EX commands. As a side-effect, @error can be removed from the parameter list.
This extra information is particularly useful if firmware loading and/or initialization is going to be made more robust, e.g. by allowing firmware loading to be postponed.
---
v2:
* Address David Rientjes's feedback:
https://lore.kernel.org/all/[email protected]/
* Remove @error.
* Remove "SEV_" prefix: it is obvious from context so no need to make klog line longer.
--- arch/x86/kvm/svm/sev.c | 2 +- drivers/crypto/ccp/sev-dev.c | 33 +++++++++++++++++---------------- include/linux/psp-sev.h | 4 +--- 3 files changed, 19 insertions(+), 20 deletions(-)
arch/x86/kvm/svm/sev.c +1 -1
@@ -254,7 +254,7 @@ static int sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp) goto e_no_asid; sev->asid = asid; - ret =sev_platform_init (&argp->error); + ret =sev_platform_init ();if (ret) goto e_free;
drivers/crypto/ccp/sev-dev.c +17 -16
@@ -440,7 +440,7 @@ static int __sev_init_ex_locked(int *error)return __sev_do_cmd_locked (SEV_CMD_INIT_EX , &data, error); } -static int __sev_platform_init_locked (int *error) +static int __sev_platform_init_locked (void ) {struct psp_device *psp = psp_master;struct sev_device *sev;
@@ -476,19 +476,21 @@ static int __sev_platform_init_locked(int *error)dev_err (sev->dev,"SEV: retrying INIT command because of SECURE_DATA_INVALID error. Retrying once to reset PSP SEV state." ); rc =init_function (&psp_ret); } -if (error) - *error = psp_ret; - -if (rc) +if (rc) { +dev_err (sev->dev,"SEV: %s failed error %#x" , + sev_init_ex_buffer ?"CMD_INIT_EX" :"CMD_INIT" , psp_ret);return rc; + } sev->state =SEV_STATE_INIT ;/* Prepare for first SEV guest launch after INIT */ wbinvd_on_all_cpus (); - rc =__sev_do_cmd_locked (SEV_CMD_DF_FLUSH ,NULL , error); -if (rc) + rc =__sev_do_cmd_locked (SEV_CMD_DF_FLUSH ,NULL , &psp_ret); +if (rc) { +dev_err (sev->dev,"SEV: CMD_DF_FLUSH failed error %#x" , psp_ret);return rc; + }dev_dbg (sev->dev,"SEV firmware initialized\n" );
@@ -498,12 +500,12 @@ static int __sev_platform_init_locked(int *error)return 0 ; } -int sev_platform_init (int *error) +int sev_platform_init (void ) {int rc;mutex_lock (&sev_cmd_mutex); - rc =__sev_platform_init_locked (error); + rc =__sev_platform_init_locked ();mutex_unlock (&sev_cmd_mutex);return rc;
@@ -610,7 +612,7 @@ static int sev_ioctl_do_pek_pdh_gen(int cmd, struct sev_issue_cmd *argp, bool wrreturn -EPERM ;if (sev->state ==SEV_STATE_UNINIT ) { - rc =__sev_platform_init_locked (&argp->error); + rc =__sev_platform_init_locked ();if (rc)return rc; }
@@ -653,7 +655,7 @@ static int sev_ioctl_do_pek_csr(struct sev_issue_cmd *argp, bool writable) cmd:if (sev->state ==SEV_STATE_UNINIT ) { - ret =__sev_platform_init_locked (&argp->error); + ret =__sev_platform_init_locked ();if (ret) goto e_free_blob; }
@@ -849,7 +851,7 @@ static int sev_ioctl_do_pek_import(struct sev_issue_cmd *argp, bool writable)/* If platform is not in INIT state then transition it to INIT */ if (sev->state !=SEV_STATE_INIT ) { - ret =__sev_platform_init_locked (&argp->error); + ret =__sev_platform_init_locked ();if (ret) goto e_free_oca; }
@@ -973,7 +975,7 @@ static int sev_ioctl_do_pdh_export(struct sev_issue_cmd *argp, bool writable)if (!writable)return -EPERM ; - ret =__sev_platform_init_locked (&argp->error); + ret =__sev_platform_init_locked ();if (ret)return ret; }
@@ -1335,10 +1337,9 @@ void sev_pci_init(void)return ;/* Initialize the platform */ - rc =sev_platform_init (&error); + rc =sev_platform_init ();if (rc) -dev_err (sev->dev,"SEV: failed to INIT error %#x, rc %d\n" , - error, rc); +dev_err (sev->dev,"SEV: failed to INIT rc %d\n" , rc);return ;
include/linux/psp-sev.h +1 -3
@@ -536,8 +536,6 @@ struct sev_data_attestation_report {/** * sev_platform_init - perform SEV INIT command * -* @error: SEV command return code -* * Returns: * 0 if the SEV successfully processed the command * -%ENODEV if the SEV device is not available
@@ -545,7 +543,7 @@ struct sev_data_attestation_report {* -%ETIMEDOUT if the SEV command timed out * -%EIO if the SEV returned a non-zero return code */ -int sev_platform_init (int *error); +int sev_platform_init (void );/** * sev_platform_status - perform SEV PLATFORM_STATUS command
Signature · 1 line
2.38.1
Quoted 18 lines · Jarkko Sakkinen
The following functions end up calling
sev_platform_init()or__sev_platform_init_locked():*
sev_guest_init()
*sev_ioctl_do_pek_csr
*sev_ioctl_do_pdh_export()
*sev_ioctl_do_pek_import()
*sev_ioctl_do_pek_pdh_gen()
*sev_pci_init()However, only
sev_pci_init()prints out the failed command error code, and even there the error message does not specify, SEV which command failed.Address this by printing out the SEV command errors inside
__sev_platform_init_locked(), and differentiate betweenDF_FLUSH, INIT andINIT_EXcommands. As a side-effect, @error can be removed from the parameter list.
Quoted 5 lines
This extra information is particularly useful if firmware loading and/or initialization is going to be made more robust, e.g. by allowing firmware loading to be postponed.
Signed-off-by Jarkko Sakkinen <[email protected]>
Tom Lendacky
maintainerQuoted 10 lines · Jarkko Sakkinen
The following functions end up calling
sev_platform_init()or__sev_platform_init_locked():*
sev_guest_init()
*sev_ioctl_do_pek_csr
*sev_ioctl_do_pdh_export()
*sev_ioctl_do_pek_import()
*sev_ioctl_do_pek_pdh_gen()
*sev_pci_init()
Quoted 2 lines
However, only
sev_pci_init()prints out the failed command error code, and even there the error message does not specify, SEV which command failed.
event there, the error message does not specify which SEV command failed.
Quoted 42 lines
Address this by printing out the SEV command errors inside
__sev_platform_init_locked(), and differentiate betweenDF_FLUSH, INIT andINIT_EXcommands. As a side-effect, @error can be removed from the parameter list.This extra information is particularly useful if firmware loading and/or initialization is going to be made more robust, e.g. by allowing firmware loading to be postponed.
Signed-off-by Jarkko Sakkinen <[email protected]>---
v2:
* Address David Rientjes's feedback:https://lore.kernel.org/all/[email protected]/ * Remove @error. * Remove "SEV_" prefix: it is obvious from context so no need to make klog line longer. --- arch/x86/kvm/svm/sev.c | 2 +- drivers/crypto/ccp/sev-dev.c | 33 +++++++++++++++++---------------- include/linux/psp-sev.h | 4 +--- 3 files changed, 19 insertions(+), 20 deletions(-)arch/x86/kvm/svm/sev.c +1
-1@@ -254,7 +254,7 @@ static int sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp) goto e_no_asid; sev->asid = asid; - ret =sev_platform_init (&argp->error); + ret =sev_platform_init ();if (ret) goto e_free;drivers/crypto/ccp/sev-dev.c +0
-0
drivers/crypto/ccp/sev-dev.c static int __sev_init_ex_locked(int *error) · line 443
Quoted 5 lines
drivers/crypto/ccp/sev-dev.c +1
-1@@ -440,7 +440,7 @@ static int __sev_init_ex_locked(int *error)return __sev_do_cmd_locked (SEV_CMD_INIT_EX , &data, error); } -static int __sev_platform_init_locked (int *error) +static int __sev_platform_init_locked (void )
Why is this being removed. Userspace may still want to see this. Some of the error pointers are from the ioctl() arguments...
Quoted 47 lines
drivers/crypto/ccp/sev-dev.c +10
-8{struct psp_device *psp = psp_master;struct sev_device *sev;@@ -476,19 +476,21 @@ static int __sev_platform_init_locked(int *error)dev_err (sev->dev,"SEV: retrying INIT command because of SECURE_DATA_INVALID error. Retrying once to reset PSP SEV state." ); rc =init_function (&psp_ret); } -if (error) - *error = psp_ret; - -if (rc) +if (rc) { +dev_err (sev->dev,"SEV: %s failed error %#x" , + sev_init_ex_buffer ?"CMD_INIT_EX" :"CMD_INIT" , psp_ret);return rc; + } sev->state =SEV_STATE_INIT ;/* Prepare for first SEV guest launch after INIT */ wbinvd_on_all_cpus (); - rc =__sev_do_cmd_locked (SEV_CMD_DF_FLUSH ,NULL , error); -if (rc) + rc =__sev_do_cmd_locked (SEV_CMD_DF_FLUSH ,NULL , &psp_ret); +if (rc) { +dev_err (sev->dev,"SEV: CMD_DF_FLUSH failed error %#x" , psp_ret);return rc; + }dev_dbg (sev->dev,"SEV firmware initialized\n" );@@ -498,12 +500,12 @@ static int __sev_platform_init_locked(int *error)return 0 ; } -int sev_platform_init (int *error) +int sev_platform_init (void ) {int rc;mutex_lock (&sev_cmd_mutex); - rc =__sev_platform_init_locked (error); + rc =__sev_platform_init_locked ();mutex_unlock (&sev_cmd_mutex);return rc;
drivers/crypto/ccp/sev-dev.c static int sev_ioctl_do_pek_pdh_gen(int cmd, struct sev_issue_cmd *argp, bool wr · line 615
Quoted 5 lines
drivers/crypto/ccp/sev-dev.c +1
-1@@ -610,7 +612,7 @@ static int sev_ioctl_do_pek_pdh_gen(int cmd, struct sev_issue_cmd *argp, bool wrreturn -EPERM ;if (sev->state ==SEV_STATE_UNINIT ) { - rc =__sev_platform_init_locked (&argp->error); + rc =__sev_platform_init_locked ();
... like here. So I don't think that should be removed.
Thanks,
Tom
Quoted 65 lines
drivers/crypto/ccp/sev-dev.c +5
-6if (rc)return rc; }@@ -653,7 +655,7 @@ static int sev_ioctl_do_pek_csr(struct sev_issue_cmd *argp, bool writable) cmd:if (sev->state ==SEV_STATE_UNINIT ) { - ret =__sev_platform_init_locked (&argp->error); + ret =__sev_platform_init_locked ();if (ret) goto e_free_blob; }@@ -849,7 +851,7 @@ static int sev_ioctl_do_pek_import(struct sev_issue_cmd *argp, bool writable)/* If platform is not in INIT state then transition it to INIT */ if (sev->state !=SEV_STATE_INIT ) { - ret =__sev_platform_init_locked (&argp->error); + ret =__sev_platform_init_locked ();if (ret) goto e_free_oca; }@@ -973,7 +975,7 @@ static int sev_ioctl_do_pdh_export(struct sev_issue_cmd *argp, bool writable)if (!writable)return -EPERM ; - ret =__sev_platform_init_locked (&argp->error); + ret =__sev_platform_init_locked ();if (ret)return ret; }@@ -1335,10 +1337,9 @@ void sev_pci_init(void)return ;/* Initialize the platform */ - rc =sev_platform_init (&error); + rc =sev_platform_init ();if (rc) -dev_err (sev->dev,"SEV: failed to INIT error %#x, rc %d\n" , - error, rc); +dev_err (sev->dev,"SEV: failed to INIT rc %d\n" , rc);return ;include/linux/psp-sev.h +1
-3@@ -536,8 +536,6 @@ struct sev_data_attestation_report {/** * sev_platform_init - perform SEV INIT command * -* @error: SEV command return code -* * Returns: * 0 if the SEV successfully processed the command * -%ENODEV if the SEV device is not available @@ -545,7 +543,7 @@ struct sev_data_attestation_report {* -%ETIMEDOUT if the SEV command timed out * -%EIO if the SEV returned a non-zero return code */ -int sev_platform_init (int *error); +int sev_platform_init (void );/** * sev_platform_status - perform SEV PLATFORM_STATUS command