mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] crypto: initialize error
@ 2023-01-10 16:18 Tom Rix
  2023-01-10 16:27 ` Peter Gonda
  0 siblings, 1 reply; 4+ messages in thread
From: Tom Rix @ 2023-01-10 16:18 UTC (permalink / raw)
  To: brijesh.singh, thomas.lendacky, john.allen, herbert, davem,
	nathan, ndesaulniers, rientjes, marcorr, pgonda
  Cc: linux-crypto, linux-kernel, llvm, 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
value.

Fixes: 3d725965f836 ("crypto: ccp - Add SEV_INIT_EX support")
Signed-off-by: Tom Rix <trix@redhat.com>
---
 drivers/crypto/ccp/sev-dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
index 56998bc579d6..643cccc06a0b 100644
--- a/drivers/crypto/ccp/sev-dev.c
+++ b/drivers/crypto/ccp/sev-dev.c
@@ -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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] crypto: initialize error
  2023-01-10 16:18 [PATCH] crypto: initialize error Tom Rix
@ 2023-01-10 16:27 ` Peter Gonda
  2023-01-10 16:48   ` Tom Rix
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Gonda @ 2023-01-10 16:27 UTC (permalink / raw)
  To: Tom Rix
  Cc: brijesh.singh, thomas.lendacky, john.allen, herbert, davem,
	nathan, ndesaulniers, rientjes, marcorr, linux-crypto,
	linux-kernel, llvm

On Tue, Jan 10, 2023 at 9:18 AM Tom Rix <trix@redhat.com> wrote:
>
> 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

> 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?

> Signed-off-by: Tom Rix <trix@redhat.com>
> ---
>  drivers/crypto/ccp/sev-dev.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
> index 56998bc579d6..643cccc06a0b 100644
> --- a/drivers/crypto/ccp/sev-dev.c
> +++ b/drivers/crypto/ccp/sev-dev.c
> @@ -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
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] crypto: initialize error
  2023-01-10 16:27 ` Peter Gonda
@ 2023-01-10 16:48   ` Tom Rix
  2023-01-10 16:53     ` Peter Gonda
  0 siblings, 1 reply; 4+ messages in thread
From: Tom Rix @ 2023-01-10 16:48 UTC (permalink / raw)
  To: Peter Gonda
  Cc: brijesh.singh, thomas.lendacky, john.allen, herbert, davem,
	nathan, ndesaulniers, rientjes, marcorr, linux-crypto,
	linux-kernel, llvm


On 1/10/23 8:27 AM, Peter Gonda wrote:
> On Tue, Jan 10, 2023 at 9:18 AM Tom Rix <trix@redhat.com> wrote:
>> 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
>
>> 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


> +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?
>
>> Signed-off-by: Tom Rix <trix@redhat.com>
>> ---
>>   drivers/crypto/ccp/sev-dev.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
>> index 56998bc579d6..643cccc06a0b 100644
>> --- a/drivers/crypto/ccp/sev-dev.c
>> +++ b/drivers/crypto/ccp/sev-dev.c
>> @@ -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
>>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] crypto: initialize error
  2023-01-10 16:48   ` Tom Rix
@ 2023-01-10 16:53     ` Peter Gonda
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Gonda @ 2023-01-10 16:53 UTC (permalink / raw)
  To: Tom Rix
  Cc: brijesh.singh, thomas.lendacky, john.allen, herbert, davem,
	nathan, ndesaulniers, rientjes, marcorr, linux-crypto,
	linux-kernel, llvm

On Tue, Jan 10, 2023 at 9:48 AM Tom Rix <trix@redhat.com> wrote:
>
>
> On 1/10/23 8:27 AM, Peter Gonda wrote:
> > On Tue, Jan 10, 2023 at 9:18 AM Tom Rix <trix@redhat.com> wrote:
> >> 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
> >
> >> 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.

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:

Reviewed-by: Peter Gonda <pgonda@google.com>

>
> Thanks
>
> Tom
>
>
> > +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?
> >
> >> Signed-off-by: Tom Rix <trix@redhat.com>
> >> ---
> >>   drivers/crypto/ccp/sev-dev.c | 2 +-
> >>   1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
> >> index 56998bc579d6..643cccc06a0b 100644
> >> --- a/drivers/crypto/ccp/sev-dev.c
> >> +++ b/drivers/crypto/ccp/sev-dev.c
> >> @@ -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
> >>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-01-10 16:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-10 16:18 [PATCH] crypto: initialize error Tom Rix
2023-01-10 16:27 ` Peter Gonda
2023-01-10 16:48   ` Tom Rix
2023-01-10 16:53     ` Peter Gonda

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®