Skip to contentSkip to conversation

x86/sev: Initialize ctxt variable and zero fi

PATCH In review Ragavendra 2 participants 6 messages Nov 18, 2024 – Nov 19, 2024 x86

lore
Share & tools
lore

Ragavendra

author
#0 lore raw

PATCH v2 1/1 x86/sev: Initialize ctxt variable and zero fi

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
---
 arch/x86/coco/sev/shared.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/x86/coco/sev/shared.c +3 -1
index 71de53194089..5e0f6fbf4dd2 100644
@@ -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);
Signature · 1 line
2.46.1
#1 lore raw
Quoted 24 lines · 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
---
 arch/x86/coco/sev/shared.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/x86/coco/sev/shared.c +2 -0
index 71de53194089..5e0f6fbf4dd2 100644
@@ -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)

arch/x86/coco/sev/shared.c static int svsm_perform_msr_protocol(struct svsm_call *call) · line 340

Quoted 5 lines
arch/x86/coco/sev/shared.c +1 -1
@@ -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

Quoted 3 lines
arch/x86/coco/sev/shared.c +0 -0
 	u8 pending = 0;
 
 	vc_ghcb_invalidate(ghcb);
#2 lore raw
Quoted 33 lines · Tom Lendacky
Quoted 24 lines · 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
---
 arch/x86/coco/sev/shared.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/x86/coco/sev/shared.c +2 -0
index 71de53194089..5e0f6fbf4dd2 100644
@@ -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)

arch/x86/coco/sev/shared.c static int svsm_perform_msr_protocol(struct svsm_call *call) · line 340

Quoted 5 lines
arch/x86/coco/sev/shared.c +1 -1
@@ -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.

Quoted 6 lines

Thanks,
Tom

Quoted 3 lines
arch/x86/coco/sev/shared.c +0 -0
 	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

#3 lore raw
Quoted 34 lines · Ragavendra B.N.
Quoted 33 lines · Tom Lendacky
Quoted 24 lines · 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
---
 arch/x86/coco/sev/shared.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/x86/coco/sev/shared.c +2 -0
index 71de53194089..5e0f6fbf4dd2 100644
@@ -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)

arch/x86/coco/sev/shared.c static int svsm_perform_msr_protocol(struct svsm_call *call) · line 340

Quoted 5 lines
arch/x86/coco/sev/shared.c +1 -1
@@ -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.

Quoted 8 lines
Quoted 6 lines

Thanks,
Tom

Quoted 3 lines
arch/x86/coco/sev/shared.c +0 -0
 	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

Quoted 5 lines

--
Thanks & regards,
Ragavendra N

#4 lore raw
Quoted 47 lines · Tom Lendacky
Quoted 34 lines · Ragavendra B.N.
Quoted 33 lines · Tom Lendacky
Quoted 24 lines · 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
---
 arch/x86/coco/sev/shared.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/x86/coco/sev/shared.c +2 -0
index 71de53194089..5e0f6fbf4dd2 100644
@@ -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)

arch/x86/coco/sev/shared.c static int svsm_perform_msr_protocol(struct svsm_call *call) · line 340

Quoted 5 lines
arch/x86/coco/sev/shared.c +1 -1
@@ -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.

Quoted 8 lines
Quoted 6 lines

Thanks,
Tom

Quoted 3 lines
arch/x86/coco/sev/shared.c +0 -0
 	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?

Quoted 12 lines

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

Quoted 5 lines

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

#5 lore raw
Quoted 57 lines · Ragavendra B.N.
Quoted 56 lines · Tom Lendacky
Quoted 34 lines · Ragavendra B.N.
Quoted 33 lines · Tom Lendacky
Quoted 24 lines · 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
---
 arch/x86/coco/sev/shared.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/x86/coco/sev/shared.c +2 -0
index 71de53194089..5e0f6fbf4dd2 100644
@@ -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)

arch/x86/coco/sev/shared.c static int svsm_perform_msr_protocol(struct svsm_call *call) · line 340

Quoted 5 lines
arch/x86/coco/sev/shared.c +1 -1
@@ -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.

Quoted 8 lines
Quoted 6 lines

Thanks,
Tom

Quoted 3 lines
arch/x86/coco/sev/shared.c +0 -0
 	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

Quoted 2 lines
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines

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

Quoted 4 lines

Regards,
Ragavendra N