Skip to contentSkip to conversation

crypto: initialize error

PATCH Superseded Tom Rix 2 participants 4 messages Jan 10, 2023

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Tom Rix

author
#0 lore raw

PATCH 1/1 crypto: initialize error

clang static analysis reports this problem drivers/crypto/ccp/sev-dev.c:1347:3: warning: 3rd function call
argument is an uninitialized value [core.CallAndMessage]

    dev_err(sev->dev, "SEV: failed to INIT error %#x, rc %d\n",
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

__sev_platform_init_locked() can return without setting the error parameter, causing the dev_err() to report a gargage value.

Fixes 3d725965f836 ("crypto: ccp - Add SEV_INIT_EX support")
---
 drivers/crypto/ccp/sev-dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/ccp/sev-dev.c +1 -1
index 56998bc579d6..643cccc06a0b 100644
@@ -1307,7 +1307,7 @@ EXPORT_SYMBOL_GPL(sev_issue_cmd_external_user);
 void sev_pci_init(void)
 {
 	struct sev_device *sev = psp_master->sev_data;
-	int error, rc;
+	int error = 0, rc;
 
 	if (!sev)
 		return;
Signature · 1 line
2.27.0
#1 lore raw
Quoted 9 lines · Tom Rix

clang static analysis reports this problem drivers/crypto/ccp/sev-dev.c:1347:3: warning: 3rd function call
argument is an uninitialized value [core.CallAndMessage]

    dev_err(sev->dev, "SEV: failed to INIT error %#x, rc %d\n",
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

__sev_platform_init_locked() can return without setting the error parameter, causing the dev_err() to report a gargage

garbage

Quoted 3 lines

value.

Fixes 3d725965f836 ("crypto: ccp - Add SEV_INIT_EX support")

Should this be: 'Fixes: 200664d5237f ("crypto: ccp: Add Secure Encrypted Virtualization (SEV) command support")'

Since in that patch an uninitialized error can be printed?

+void psp_pci_init(void)
+{

+       struct sev_user_data_status *status;
+       struct sp_device *sp;
+       int error, rc;

+
+ sp = sp_get_psp_master_device();
+ if (!sp)
+ return;
+
+ psp_master = sp->psp_data;
+

+       /* Initialize the platform */
+       rc = sev_platform_init(&error);
+       if (rc) {

+ dev_err(sp->dev, "SEV: failed to INIT error %#x\n", error);
+ goto err;
+ }

...

+static int __sev_platform_init_locked(int *error) +{
+ struct psp_device *psp = psp_master;
+ int rc = 0;
+
+ if (!psp)
+ return -ENODEV;
+
+ if (psp->sev_state == SEV_STATE_INIT)
+ return 0;

So if !psp an uninitialized error is printed?

Quoted 21 lines
---
 drivers/crypto/ccp/sev-dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/ccp/sev-dev.c +1 -2
index 56998bc579d6..643cccc06a0b 100644
@@ -1307,7 +1307,7 @@ EXPORT_SYMBOL_GPL(sev_issue_cmd_external_user);
 void sev_pci_init(void)
 {
        struct sev_device *sev = psp_master->sev_data;
-       int error, rc;
+       int error = 0, rc;
 
        if (!sev)
                return;
--

2.27.0

author
#2 lore raw
Quoted 10 lines · Peter Gonda
Quoted 8 lines · Tom Rix

clang static analysis reports this problem drivers/crypto/ccp/sev-dev.c:1347:3: warning: 3rd function call
argument is an uninitialized value [core.CallAndMessage]

     dev_err(sev->dev, "SEV: failed to INIT error %#x, rc %d\n",
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

__sev_platform_init_locked() can return without setting the error parameter, causing the dev_err() to report a gargage

garbage

ok

Quoted 8 lines
Quoted 4 lines

value.

Fixes 3d725965f836 ("crypto: ccp - Add SEV_INIT_EX support")

Should this be: 'Fixes: 200664d5237f ("crypto: ccp: Add Secure Encrypted Virtualization (SEV) command support")'

Since in that patch an uninitialized error can be printed?

It was a bit of a toss up on who is at fault. This is fine, i'll change this as well.

Thanks

Tom

Quoted 57 lines
(quoted diff) +28 -0
+void psp_pci_init(void)
+{
+       struct sev_user_data_status *status;
+       struct sp_device *sp;
+       int error, rc;
+
+       sp = sp_get_psp_master_device();
+       if (!sp)
+               return;
+
+       psp_master = sp->psp_data;
+
+       /* Initialize the platform */
+       rc = sev_platform_init(&error);
+       if (rc) {
+               dev_err(sp->dev, "SEV: failed to INIT error %#x\n", error);
+               goto err;
+       }
 
 
...
 
+static int __sev_platform_init_locked(int *error)
+{
+       struct psp_device *psp = psp_master;
+       int rc = 0;
+
+       if (!psp)
+               return -ENODEV;
+
+       if (psp->sev_state == SEV_STATE_INIT)
+               return 0;

So if !psp an uninitialized error is printed?

Quoted 21 lines
---
  drivers/crypto/ccp/sev-dev.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/ccp/sev-dev.c +1 -2
index 56998bc579d6..643cccc06a0b 100644
@@ -1307,7 +1307,7 @@ EXPORT_SYMBOL_GPL(sev_issue_cmd_external_user);
  void sev_pci_init(void)
  {
         struct sev_device *sev = psp_master->sev_data;
-       int error, rc;
+       int error = 0, rc;
 
         if (!sev)
                 return;
--

2.27.0

Reviewed-by
#3 lore raw
Quoted 17 lines · Tom Rix
Quoted 10 lines · Peter Gonda
Quoted 8 lines · Tom Rix

clang static analysis reports this problem drivers/crypto/ccp/sev-dev.c:1347:3: warning: 3rd function call
argument is an uninitialized value [core.CallAndMessage]

     dev_err(sev->dev, "SEV: failed to INIT error %#x, rc %d\n",
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

__sev_platform_init_locked() can return without setting the error parameter, causing the dev_err() to report a gargage

garbage

ok

Quoted 3 lines
Quoted 3 lines

value.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Fixes 3d725965f836 ("crypto: ccp - Add SEV_INIT_EX support")

Should this be: 'Fixes: 200664d5237f ("crypto: ccp: Add Secure Encrypted Virtualization (SEV) command support")'

Since in that patch an uninitialized error can be printed?

It was a bit of a toss up on who is at fault. This is fine, i'll change this as well.

Ack. Not trying to play a blame game =]. Just thought this patch might as well be backported back to anyone using this function.

If you are sending another version you can add:

Quoted 64 lines

Thanks

Tom

Quoted 57 lines
(quoted diff) +28 -0
+void psp_pci_init(void)
+{
+       struct sev_user_data_status *status;
+       struct sp_device *sp;
+       int error, rc;
+
+       sp = sp_get_psp_master_device();
+       if (!sp)
+               return;
+
+       psp_master = sp->psp_data;
+
+       /* Initialize the platform */
+       rc = sev_platform_init(&error);
+       if (rc) {
+               dev_err(sp->dev, "SEV: failed to INIT error %#x\n", error);
+               goto err;
+       }
 
 
...
 
+static int __sev_platform_init_locked(int *error)
+{
+       struct psp_device *psp = psp_master;
+       int rc = 0;
+
+       if (!psp)
+               return -ENODEV;
+
+       if (psp->sev_state == SEV_STATE_INIT)
+               return 0;

So if !psp an uninitialized error is printed?

Quoted 21 lines
---
  drivers/crypto/ccp/sev-dev.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/ccp/sev-dev.c +1 -2
index 56998bc579d6..643cccc06a0b 100644
@@ -1307,7 +1307,7 @@ EXPORT_SYMBOL_GPL(sev_issue_cmd_external_user);
  void sev_pci_init(void)
  {
         struct sev_device *sev = psp_master->sev_data;
-       int error, rc;
+       int error = 0, rc;
 
         if (!sev)
                 return;
--

2.27.0