Skip to contentSkip to conversation

snp: fix coverity reported issues

PATCH Applied Pankaj Gupta 3 participants 6 messages Jun 7, 2024 – Jun 11, 2024

lore
Share & tools
lore
#0 lore raw

cover snp: fix coverity reported issues

Pankaj Gupta (3):
i386/sev: fix unreachable code coverity issue i386/sev: Move SEV_COMMON null check before dereferencing i386/sev: Return when sev_common is null

 target/i386/sev.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/3 i386/sev: fix unreachable code coverity issue

Set 'finish->id_block_en' when block_size read.

coverity #1546887

Fixes 7b34df4426 ("i386/sev: Introduce 'sev-snp-guest' object")
---
 target/i386/sev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
target/i386/sev.c +2 -1
index 004c667ac1..7c9df621de 100644
@@ -2165,6 +2165,7 @@ sev_snp_guest_set_id_block(Object *obj, const char *value, Error **errp)
     struct kvm_sev_snp_launch_finish *finish = &sev_snp_guest->kvm_finish_conf;
     gsize len;
 
+    finish->id_block_en = 0;
     g_free(sev_snp_guest->id_block);
     g_free((guchar *)finish->id_block_uaddr);
 
@@ -2184,7 +2185,7 @@ sev_snp_guest_set_id_block(Object *obj, const char *value, Error **errp)
         return;
     }
 
-    finish->id_block_en = (len) ? 1 : 0;
+    finish->id_block_en = 1;
 }
 
 static char *
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH 1/3] i386/sev: fix unreachable code coverity issue

Quoted 5 lines · Pankaj Gupta

Set 'finish->id_block_en' when block_size read.

coverity #1546887

Fixes 7b34df4426 ("i386/sev: Introduce 'sev-snp-guest' object")

Please make that

Fixes Coverity CID 1546887
Fixes 7b34df4426 ("i386/sev: Introduce 'sev-snp-guest' object")
Quoted 1 line
#3 lore raw

PATCH 2/3 i386/sev: Move SEV_COMMON null check before dereferencing

In reply to Pankaj Gupta

coverity #1546886

Fixes 9861405a8f ("i386/sev: Invoke launch_updata_data() for SEV class")
---
 target/i386/sev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
target/i386/sev.c +2 -1
index 7c9df621de..f18432f58e 100644
@@ -1529,11 +1529,12 @@ int
 sev_encrypt_flash(hwaddr gpa, uint8_t *ptr, uint64_t len, Error **errp)
 {
     SevCommonState *sev_common = SEV_COMMON(MACHINE(qdev_get_machine())->cgs);
-    SevCommonStateClass *klass = SEV_COMMON_GET_CLASS(sev_common);
+    SevCommonStateClass *klass;
 
     if (!sev_common) {
         return 0;
     }
+    klass = SEV_COMMON_GET_CLASS(sev_common);
 
     /* if SEV is in update state then encrypt the data else do nothing */
     if (sev_check_state(sev_common, SEV_STATE_LAUNCH_UPDATE)) {
Signature · 1 line
2.34.1
#4 lore raw

PATCH 3/3 i386/sev: Return when sev_common is null

In reply to Pankaj Gupta

coverity #1546885

Fixes 16dcf200dc ("i386/sev: Introduce "sev-common" type to encapsulate common SEV state")
---
 target/i386/sev.c | 1 +
 1 file changed, 1 insertion(+)
target/i386/sev.c +1 -0
index f18432f58e..c40562dce3 100644
@@ -587,6 +587,7 @@ static SevCapability *sev_get_capabilities(Error **errp)
     sev_common = SEV_COMMON(MACHINE(qdev_get_machine())->cgs);
     if (!sev_common) {
         error_setg(errp, "SEV is not configured");
+        return NULL;
     }
 
     sev_device = object_property_get_str(OBJECT(sev_common), "sev-device",
Signature · 1 line
2.34.1