* [PATCH v2] x86/sev: Initialize ctxt variable and zero fi
@ 2024-11-18 22:58 Ragavendra
2024-11-19 14:23 ` Tom Lendacky
0 siblings, 1 reply; 6+ messages in thread
From: Ragavendra @ 2024-11-18 22:58 UTC (permalink / raw)
To: tglx, mingo, bp, dave.hansen, hpa, thomas.lendacky, ardb,
tzimmermann, bhelgaas
Cc: x86, linux-kernel, Ragavendra
Updating the ctxt value to {} in the svsm_perform_ghcb_protocol as
it was not initialized. Updating memory to zero for the ctxt->fi
variable in verify_exception_info when ES_EXCEPTION is returned.
Fixes: 34ff65901735 x86/sev: Use kernel provided SVSM Calling Areas
Signed-off-by: Ragavendra Nagraj <ragavendra.bn@gmail.com>
---
arch/x86/coco/sev/shared.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/arch/x86/coco/sev/shared.c b/arch/x86/coco/sev/shared.c
index 71de53194089..5e0f6fbf4dd2 100644
--- a/arch/x86/coco/sev/shared.c
+++ b/arch/x86/coco/sev/shared.c
@@ -239,6 +239,8 @@ static enum es_result verify_exception_info(struct ghcb *ghcb, struct es_em_ctxt
if ((info & SVM_EVTINJ_VALID) &&
((v == X86_TRAP_GP) || (v == X86_TRAP_UD)) &&
((info & SVM_EVTINJ_TYPE_MASK) == SVM_EVTINJ_TYPE_EXEPT)) {
+ memset(&ctxt->fi, 0, sizeof(ctxt->fi));
+
ctxt->fi.vector = v;
if (info & SVM_EVTINJ_VALID_ERR)
@@ -335,7 +337,7 @@ static int svsm_perform_msr_protocol(struct svsm_call *call)
static int svsm_perform_ghcb_protocol(struct ghcb *ghcb, struct svsm_call *call)
{
- struct es_em_ctxt ctxt;
+ struct es_em_ctxt ctxt = {};
u8 pending = 0;
vc_ghcb_invalidate(ghcb);
--
2.46.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2] x86/sev: Initialize ctxt variable and zero fi
2024-11-18 22:58 [PATCH v2] x86/sev: Initialize ctxt variable and zero fi Ragavendra
@ 2024-11-19 14:23 ` Tom Lendacky
2024-11-19 17:35 ` Ragavendra B.N.
0 siblings, 1 reply; 6+ messages in thread
From: Tom Lendacky @ 2024-11-19 14:23 UTC (permalink / raw)
To: Ragavendra, tglx, mingo, bp, dave.hansen, hpa, ardb, tzimmermann,
bhelgaas
Cc: x86, linux-kernel
On 11/18/24 16:58, Ragavendra wrote:
> Updating the ctxt value to {} in the svsm_perform_ghcb_protocol as
> it was not initialized. Updating memory to zero for the ctxt->fi
> variable in verify_exception_info when ES_EXCEPTION is returned.
>
> Fixes: 34ff65901735 x86/sev: Use kernel provided SVSM Calling Areas
> Signed-off-by: Ragavendra Nagraj <ragavendra.bn@gmail.com>
> ---
> arch/x86/coco/sev/shared.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/coco/sev/shared.c b/arch/x86/coco/sev/shared.c
> index 71de53194089..5e0f6fbf4dd2 100644
> --- a/arch/x86/coco/sev/shared.c
> +++ b/arch/x86/coco/sev/shared.c
> @@ -239,6 +239,8 @@ static enum es_result verify_exception_info(struct ghcb *ghcb, struct es_em_ctxt
> if ((info & SVM_EVTINJ_VALID) &&
> ((v == X86_TRAP_GP) || (v == X86_TRAP_UD)) &&
> ((info & SVM_EVTINJ_TYPE_MASK) == SVM_EVTINJ_TYPE_EXEPT)) {
> + memset(&ctxt->fi, 0, sizeof(ctxt->fi));
> +
> ctxt->fi.vector = v;
>
> if (info & SVM_EVTINJ_VALID_ERR)
> @@ -335,7 +337,7 @@ static int svsm_perform_msr_protocol(struct svsm_call *call)
>
> static int svsm_perform_ghcb_protocol(struct ghcb *ghcb, struct svsm_call *call)
> {
> - struct es_em_ctxt ctxt;
> + struct es_em_ctxt ctxt = {};
This isn't necessary if you are doing the memset.
Thanks,
Tom
> u8 pending = 0;
>
> vc_ghcb_invalidate(ghcb);
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] x86/sev: Initialize ctxt variable and zero fi
2024-11-19 14:23 ` Tom Lendacky
@ 2024-11-19 17:35 ` Ragavendra B.N.
2024-11-19 17:51 ` Tom Lendacky
0 siblings, 1 reply; 6+ messages in thread
From: Ragavendra B.N. @ 2024-11-19 17:35 UTC (permalink / raw)
To: Tom Lendacky
Cc: tglx, mingo, bp, dave.hansen, hpa, ardb, tzimmermann, bhelgaas,
x86, linux-kernel
On Tue, Nov 19, 2024 at 08:23:14AM -0600, Tom Lendacky wrote:
> On 11/18/24 16:58, Ragavendra wrote:
> > Updating the ctxt value to {} in the svsm_perform_ghcb_protocol as
> > it was not initialized. Updating memory to zero for the ctxt->fi
> > variable in verify_exception_info when ES_EXCEPTION is returned.
> >
> > Fixes: 34ff65901735 x86/sev: Use kernel provided SVSM Calling Areas
> > Signed-off-by: Ragavendra Nagraj <ragavendra.bn@gmail.com>
> > ---
> > arch/x86/coco/sev/shared.c | 4 +++-
> > 1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/arch/x86/coco/sev/shared.c b/arch/x86/coco/sev/shared.c
> > index 71de53194089..5e0f6fbf4dd2 100644
> > --- a/arch/x86/coco/sev/shared.c
> > +++ b/arch/x86/coco/sev/shared.c
> > @@ -239,6 +239,8 @@ static enum es_result verify_exception_info(struct ghcb *ghcb, struct es_em_ctxt
> > if ((info & SVM_EVTINJ_VALID) &&
> > ((v == X86_TRAP_GP) || (v == X86_TRAP_UD)) &&
> > ((info & SVM_EVTINJ_TYPE_MASK) == SVM_EVTINJ_TYPE_EXEPT)) {
> > + memset(&ctxt->fi, 0, sizeof(ctxt->fi));
> > +
> > ctxt->fi.vector = v;
> >
> > if (info & SVM_EVTINJ_VALID_ERR)
> > @@ -335,7 +337,7 @@ static int svsm_perform_msr_protocol(struct svsm_call *call)
> >
> > static int svsm_perform_ghcb_protocol(struct ghcb *ghcb, struct svsm_call *call)
> > {
> > - struct es_em_ctxt ctxt;
> > + struct es_em_ctxt ctxt = {};
>
> This isn't necessary if you are doing the memset.
>
> Thanks,
> Tom
>
> > u8 pending = 0;
> >
> > vc_ghcb_invalidate(ghcb);
I can go ahead and undo that, I fear that Coverity can catch it. If no harm I can leave it.
--
Thanks & regards,
Ragavendra N
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] x86/sev: Initialize ctxt variable and zero fi
2024-11-19 17:35 ` Ragavendra B.N.
@ 2024-11-19 17:51 ` Tom Lendacky
2024-11-19 18:08 ` Ragavendra B.N.
0 siblings, 1 reply; 6+ messages in thread
From: Tom Lendacky @ 2024-11-19 17:51 UTC (permalink / raw)
To: Ragavendra B.N.
Cc: tglx, mingo, bp, dave.hansen, hpa, ardb, tzimmermann, bhelgaas,
x86, linux-kernel
On 11/19/24 11:35, Ragavendra B.N. wrote:
> On Tue, Nov 19, 2024 at 08:23:14AM -0600, Tom Lendacky wrote:
>> On 11/18/24 16:58, Ragavendra wrote:
>>> Updating the ctxt value to {} in the svsm_perform_ghcb_protocol as
>>> it was not initialized. Updating memory to zero for the ctxt->fi
>>> variable in verify_exception_info when ES_EXCEPTION is returned.
>>>
>>> Fixes: 34ff65901735 x86/sev: Use kernel provided SVSM Calling Areas
>>> Signed-off-by: Ragavendra Nagraj <ragavendra.bn@gmail.com>
>>> ---
>>> arch/x86/coco/sev/shared.c | 4 +++-
>>> 1 file changed, 3 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/arch/x86/coco/sev/shared.c b/arch/x86/coco/sev/shared.c
>>> index 71de53194089..5e0f6fbf4dd2 100644
>>> --- a/arch/x86/coco/sev/shared.c
>>> +++ b/arch/x86/coco/sev/shared.c
>>> @@ -239,6 +239,8 @@ static enum es_result verify_exception_info(struct ghcb *ghcb, struct es_em_ctxt
>>> if ((info & SVM_EVTINJ_VALID) &&
>>> ((v == X86_TRAP_GP) || (v == X86_TRAP_UD)) &&
>>> ((info & SVM_EVTINJ_TYPE_MASK) == SVM_EVTINJ_TYPE_EXEPT)) {
>>> + memset(&ctxt->fi, 0, sizeof(ctxt->fi));
>>> +
>>> ctxt->fi.vector = v;
>>>
>>> if (info & SVM_EVTINJ_VALID_ERR)
>>> @@ -335,7 +337,7 @@ static int svsm_perform_msr_protocol(struct svsm_call *call)
>>>
>>> static int svsm_perform_ghcb_protocol(struct ghcb *ghcb, struct svsm_call *call)
>>> {
>>> - struct es_em_ctxt ctxt;
>>> + struct es_em_ctxt ctxt = {};
>>
>> This isn't necessary if you are doing the memset.
>>
>> Thanks,
>> Tom
>>
>>> u8 pending = 0;
>>>
>>> vc_ghcb_invalidate(ghcb);
>
> I can go ahead and undo that, I fear that Coverity can catch it. If no harm I can leave it.
Well, can you remove the line and run Coverity and see if it still
thinks there's an issue?
If it sees an issue, then it could be that Coverity can't follow the
flow completely in this case. Doing the memset is enough, as far as I
can see.
Thanks,
Tom
>
>
> --
> Thanks & regards,
> Ragavendra N
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] x86/sev: Initialize ctxt variable and zero fi
2024-11-19 17:51 ` Tom Lendacky
@ 2024-11-19 18:08 ` Ragavendra B.N.
2024-11-19 19:11 ` Tom Lendacky
0 siblings, 1 reply; 6+ messages in thread
From: Ragavendra B.N. @ 2024-11-19 18:08 UTC (permalink / raw)
To: Tom Lendacky
Cc: tglx, mingo, bp, dave.hansen, hpa, ardb, tzimmermann, bhelgaas,
x86, linux-kernel
On Tue, Nov 19, 2024 at 11:51:27AM -0600, Tom Lendacky wrote:
> On 11/19/24 11:35, Ragavendra B.N. wrote:
> > On Tue, Nov 19, 2024 at 08:23:14AM -0600, Tom Lendacky wrote:
> >> On 11/18/24 16:58, Ragavendra wrote:
> >>> Updating the ctxt value to {} in the svsm_perform_ghcb_protocol as
> >>> it was not initialized. Updating memory to zero for the ctxt->fi
> >>> variable in verify_exception_info when ES_EXCEPTION is returned.
> >>>
> >>> Fixes: 34ff65901735 x86/sev: Use kernel provided SVSM Calling Areas
> >>> Signed-off-by: Ragavendra Nagraj <ragavendra.bn@gmail.com>
> >>> ---
> >>> arch/x86/coco/sev/shared.c | 4 +++-
> >>> 1 file changed, 3 insertions(+), 1 deletion(-)
> >>>
> >>> diff --git a/arch/x86/coco/sev/shared.c b/arch/x86/coco/sev/shared.c
> >>> index 71de53194089..5e0f6fbf4dd2 100644
> >>> --- a/arch/x86/coco/sev/shared.c
> >>> +++ b/arch/x86/coco/sev/shared.c
> >>> @@ -239,6 +239,8 @@ static enum es_result verify_exception_info(struct ghcb *ghcb, struct es_em_ctxt
> >>> if ((info & SVM_EVTINJ_VALID) &&
> >>> ((v == X86_TRAP_GP) || (v == X86_TRAP_UD)) &&
> >>> ((info & SVM_EVTINJ_TYPE_MASK) == SVM_EVTINJ_TYPE_EXEPT)) {
> >>> + memset(&ctxt->fi, 0, sizeof(ctxt->fi));
> >>> +
> >>> ctxt->fi.vector = v;
> >>>
> >>> if (info & SVM_EVTINJ_VALID_ERR)
> >>> @@ -335,7 +337,7 @@ static int svsm_perform_msr_protocol(struct svsm_call *call)
> >>>
> >>> static int svsm_perform_ghcb_protocol(struct ghcb *ghcb, struct svsm_call *call)
> >>> {
> >>> - struct es_em_ctxt ctxt;
> >>> + struct es_em_ctxt ctxt = {};
> >>
> >> This isn't necessary if you are doing the memset.
> >>
> >> Thanks,
> >> Tom
> >>
> >>> u8 pending = 0;
> >>>
> >>> vc_ghcb_invalidate(ghcb);
> >
> > I can go ahead and undo that, I fear that Coverity can catch it. If no harm I can leave it.
>
> Well, can you remove the line and run Coverity and see if it still
> thinks there's an issue?
>
> If it sees an issue, then it could be that Coverity can't follow the
> flow completely in this case. Doing the memset is enough, as far as I
> can see.
>
> Thanks,
> Tom
>
> >
> >
> > --
> > Thanks & regards,
> > Ragavendra N
Sure Tom, I have updated the change and sent the new patch. Please let me know if everything looks fine,
Regards,
Ragavendra N
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] x86/sev: Initialize ctxt variable and zero fi
2024-11-19 18:08 ` Ragavendra B.N.
@ 2024-11-19 19:11 ` Tom Lendacky
0 siblings, 0 replies; 6+ messages in thread
From: Tom Lendacky @ 2024-11-19 19:11 UTC (permalink / raw)
To: Ragavendra B.N.
Cc: tglx, mingo, bp, dave.hansen, hpa, ardb, tzimmermann, bhelgaas,
x86, linux-kernel
On 11/19/24 12:08, Ragavendra B.N. wrote:
> On Tue, Nov 19, 2024 at 11:51:27AM -0600, Tom Lendacky wrote:
>> On 11/19/24 11:35, Ragavendra B.N. wrote:
>>> On Tue, Nov 19, 2024 at 08:23:14AM -0600, Tom Lendacky wrote:
>>>> On 11/18/24 16:58, Ragavendra wrote:
>>>>> Updating the ctxt value to {} in the svsm_perform_ghcb_protocol as
>>>>> it was not initialized. Updating memory to zero for the ctxt->fi
>>>>> variable in verify_exception_info when ES_EXCEPTION is returned.
>>>>>
>>>>> Fixes: 34ff65901735 x86/sev: Use kernel provided SVSM Calling Areas
>>>>> Signed-off-by: Ragavendra Nagraj <ragavendra.bn@gmail.com>
>>>>> ---
>>>>> arch/x86/coco/sev/shared.c | 4 +++-
>>>>> 1 file changed, 3 insertions(+), 1 deletion(-)
>>>>>
>>>>> diff --git a/arch/x86/coco/sev/shared.c b/arch/x86/coco/sev/shared.c
>>>>> index 71de53194089..5e0f6fbf4dd2 100644
>>>>> --- a/arch/x86/coco/sev/shared.c
>>>>> +++ b/arch/x86/coco/sev/shared.c
>>>>> @@ -239,6 +239,8 @@ static enum es_result verify_exception_info(struct ghcb *ghcb, struct es_em_ctxt
>>>>> if ((info & SVM_EVTINJ_VALID) &&
>>>>> ((v == X86_TRAP_GP) || (v == X86_TRAP_UD)) &&
>>>>> ((info & SVM_EVTINJ_TYPE_MASK) == SVM_EVTINJ_TYPE_EXEPT)) {
>>>>> + memset(&ctxt->fi, 0, sizeof(ctxt->fi));
>>>>> +
>>>>> ctxt->fi.vector = v;
>>>>>
>>>>> if (info & SVM_EVTINJ_VALID_ERR)
>>>>> @@ -335,7 +337,7 @@ static int svsm_perform_msr_protocol(struct svsm_call *call)
>>>>>
>>>>> static int svsm_perform_ghcb_protocol(struct ghcb *ghcb, struct svsm_call *call)
>>>>> {
>>>>> - struct es_em_ctxt ctxt;
>>>>> + struct es_em_ctxt ctxt = {};
>>>>
>>>> This isn't necessary if you are doing the memset.
>>>>
>>>> Thanks,
>>>> Tom
>>>>
>>>>> u8 pending = 0;
>>>>>
>>>>> vc_ghcb_invalidate(ghcb);
>>>
>>> I can go ahead and undo that, I fear that Coverity can catch it. If no harm I can leave it.
>>
>> Well, can you remove the line and run Coverity and see if it still
>> thinks there's an issue?
>>
>> If it sees an issue, then it could be that Coverity can't follow the
>> flow completely in this case. Doing the memset is enough, as far as I
>> can see.
>>
>> Thanks,
>> Tom
>>
>>>
>>>
>>> --
>>> Thanks & regards,
>>> Ragavendra N
>
> Sure Tom, I have updated the change and sent the new patch. Please let me know if everything looks fine,
So does that mean you ran it through Coverity and everything was ok?
Thanks,
Tom
>
>
> Regards,
> Ragavendra N
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-11-19 19:11 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-18 22:58 [PATCH v2] x86/sev: Initialize ctxt variable and zero fi Ragavendra
2024-11-19 14:23 ` Tom Lendacky
2024-11-19 17:35 ` Ragavendra B.N.
2024-11-19 17:51 ` Tom Lendacky
2024-11-19 18:08 ` Ragavendra B.N.
2024-11-19 19:11 ` Tom Lendacky
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox