|
|
383d26 |
From db0396e4d2663f41aaea944eaaf29141b20f5e1f Mon Sep 17 00:00:00 2001
|
|
|
383d26 |
From: Markus Armbruster <armbru@redhat.com>
|
|
|
383d26 |
Date: Fri, 31 Aug 2018 14:24:58 +0200
|
|
|
383d26 |
Subject: [PATCH 07/29] target/i386: sev: fix memory leaks
|
|
|
383d26 |
|
|
|
383d26 |
RH-Author: Markus Armbruster <armbru@redhat.com>
|
|
|
383d26 |
Message-id: <20180831142459.18567-2-armbru@redhat.com>
|
|
|
383d26 |
Patchwork-id: 81984
|
|
|
383d26 |
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 1/2] target/i386: sev: fix memory leaks
|
|
|
383d26 |
Bugzilla: 1624390
|
|
|
383d26 |
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
|
|
|
383d26 |
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
383d26 |
RH-Acked-by: Auger Eric <eric.auger@redhat.com>
|
|
|
383d26 |
|
|
|
383d26 |
From: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
383d26 |
|
|
|
383d26 |
Reported by Coverity.
|
|
|
383d26 |
|
|
|
383d26 |
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
383d26 |
(cherry picked from commit bf3175b49952628f96d72d1247d8bb3aa5c2466c)
|
|
|
383d26 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
383d26 |
---
|
|
|
383d26 |
target/i386/sev.c | 32 +++++++++++++++++---------------
|
|
|
383d26 |
1 file changed, 17 insertions(+), 15 deletions(-)
|
|
|
383d26 |
|
|
|
383d26 |
diff --git a/target/i386/sev.c b/target/i386/sev.c
|
|
|
383d26 |
index c011671..2395171 100644
|
|
|
383d26 |
--- a/target/i386/sev.c
|
|
|
383d26 |
+++ b/target/i386/sev.c
|
|
|
383d26 |
@@ -430,7 +430,8 @@ static int
|
|
|
383d26 |
sev_get_pdh_info(int fd, guchar **pdh, size_t *pdh_len, guchar **cert_chain,
|
|
|
383d26 |
size_t *cert_chain_len)
|
|
|
383d26 |
{
|
|
|
383d26 |
- guchar *pdh_data, *cert_chain_data;
|
|
|
383d26 |
+ guchar *pdh_data = NULL;
|
|
|
383d26 |
+ guchar *cert_chain_data = NULL;
|
|
|
383d26 |
struct sev_user_data_pdh_cert_export export = {};
|
|
|
383d26 |
int err, r;
|
|
|
383d26 |
|
|
|
383d26 |
@@ -471,8 +472,9 @@ e_free:
|
|
|
383d26 |
SevCapability *
|
|
|
383d26 |
sev_get_capabilities(void)
|
|
|
383d26 |
{
|
|
|
383d26 |
- SevCapability *cap;
|
|
|
383d26 |
- guchar *pdh_data, *cert_chain_data;
|
|
|
383d26 |
+ SevCapability *cap = NULL;
|
|
|
383d26 |
+ guchar *pdh_data = NULL;
|
|
|
383d26 |
+ guchar *cert_chain_data = NULL;
|
|
|
383d26 |
size_t pdh_len = 0, cert_chain_len = 0;
|
|
|
383d26 |
uint32_t ebx;
|
|
|
383d26 |
int fd;
|
|
|
383d26 |
@@ -486,7 +488,7 @@ sev_get_capabilities(void)
|
|
|
383d26 |
|
|
|
383d26 |
if (sev_get_pdh_info(fd, &pdh_data, &pdh_len,
|
|
|
383d26 |
&cert_chain_data, &cert_chain_len)) {
|
|
|
383d26 |
- return NULL;
|
|
|
383d26 |
+ goto out;
|
|
|
383d26 |
}
|
|
|
383d26 |
|
|
|
383d26 |
cap = g_new0(SevCapability, 1);
|
|
|
383d26 |
@@ -502,9 +504,9 @@ sev_get_capabilities(void)
|
|
|
383d26 |
*/
|
|
|
383d26 |
cap->reduced_phys_bits = 1;
|
|
|
383d26 |
|
|
|
383d26 |
+out:
|
|
|
383d26 |
g_free(pdh_data);
|
|
|
383d26 |
g_free(cert_chain_data);
|
|
|
383d26 |
-
|
|
|
383d26 |
close(fd);
|
|
|
383d26 |
return cap;
|
|
|
383d26 |
}
|
|
|
383d26 |
@@ -530,7 +532,7 @@ sev_launch_start(SEVState *s)
|
|
|
383d26 |
{
|
|
|
383d26 |
gsize sz;
|
|
|
383d26 |
int ret = 1;
|
|
|
383d26 |
- int fw_error;
|
|
|
383d26 |
+ int fw_error, rc;
|
|
|
383d26 |
QSevGuestInfo *sev = s->sev_info;
|
|
|
383d26 |
struct kvm_sev_launch_start *start;
|
|
|
383d26 |
guchar *session = NULL, *dh_cert = NULL;
|
|
|
383d26 |
@@ -543,7 +545,7 @@ sev_launch_start(SEVState *s)
|
|
|
383d26 |
&error_abort);
|
|
|
383d26 |
if (sev->session_file) {
|
|
|
383d26 |
if (sev_read_file_base64(sev->session_file, &session, &sz) < 0) {
|
|
|
383d26 |
- return 1;
|
|
|
383d26 |
+ goto out;
|
|
|
383d26 |
}
|
|
|
383d26 |
start->session_uaddr = (unsigned long)session;
|
|
|
383d26 |
start->session_len = sz;
|
|
|
383d26 |
@@ -551,18 +553,18 @@ sev_launch_start(SEVState *s)
|
|
|
383d26 |
|
|
|
383d26 |
if (sev->dh_cert_file) {
|
|
|
383d26 |
if (sev_read_file_base64(sev->dh_cert_file, &dh_cert, &sz) < 0) {
|
|
|
383d26 |
- return 1;
|
|
|
383d26 |
+ goto out;
|
|
|
383d26 |
}
|
|
|
383d26 |
start->dh_uaddr = (unsigned long)dh_cert;
|
|
|
383d26 |
start->dh_len = sz;
|
|
|
383d26 |
}
|
|
|
383d26 |
|
|
|
383d26 |
trace_kvm_sev_launch_start(start->policy, session, dh_cert);
|
|
|
383d26 |
- ret = sev_ioctl(s->sev_fd, KVM_SEV_LAUNCH_START, start, &fw_error);
|
|
|
383d26 |
- if (ret < 0) {
|
|
|
383d26 |
+ rc = sev_ioctl(s->sev_fd, KVM_SEV_LAUNCH_START, start, &fw_error);
|
|
|
383d26 |
+ if (rc < 0) {
|
|
|
383d26 |
error_report("%s: LAUNCH_START ret=%d fw_error=%d '%s'",
|
|
|
383d26 |
__func__, ret, fw_error, fw_error_to_str(fw_error));
|
|
|
383d26 |
- return 1;
|
|
|
383d26 |
+ goto out;
|
|
|
383d26 |
}
|
|
|
383d26 |
|
|
|
383d26 |
object_property_set_int(OBJECT(sev), start->handle, "handle",
|
|
|
383d26 |
@@ -570,12 +572,13 @@ sev_launch_start(SEVState *s)
|
|
|
383d26 |
sev_set_guest_state(SEV_STATE_LAUNCH_UPDATE);
|
|
|
383d26 |
s->handle = start->handle;
|
|
|
383d26 |
s->policy = start->policy;
|
|
|
383d26 |
+ ret = 0;
|
|
|
383d26 |
|
|
|
383d26 |
+out:
|
|
|
383d26 |
g_free(start);
|
|
|
383d26 |
g_free(session);
|
|
|
383d26 |
g_free(dh_cert);
|
|
|
383d26 |
-
|
|
|
383d26 |
- return 0;
|
|
|
383d26 |
+ return ret;
|
|
|
383d26 |
}
|
|
|
383d26 |
|
|
|
383d26 |
static int
|
|
|
383d26 |
@@ -712,7 +715,7 @@ sev_guest_init(const char *id)
|
|
|
383d26 |
uint32_t host_cbitpos;
|
|
|
383d26 |
struct sev_user_data_status status = {};
|
|
|
383d26 |
|
|
|
383d26 |
- s = g_new0(SEVState, 1);
|
|
|
383d26 |
+ sev_state = s = g_new0(SEVState, 1);
|
|
|
383d26 |
s->sev_info = lookup_sev_guest_info(id);
|
|
|
383d26 |
if (!s->sev_info) {
|
|
|
383d26 |
error_report("%s: '%s' is not a valid '%s' object",
|
|
|
383d26 |
@@ -720,7 +723,6 @@ sev_guest_init(const char *id)
|
|
|
383d26 |
goto err;
|
|
|
383d26 |
}
|
|
|
383d26 |
|
|
|
383d26 |
- sev_state = s;
|
|
|
383d26 |
s->state = SEV_STATE_UNINIT;
|
|
|
383d26 |
|
|
|
383d26 |
host_cpuid(0x8000001F, 0, NULL, &ebx, NULL, NULL);
|
|
|
383d26 |
--
|
|
|
383d26 |
1.8.3.1
|
|
|
383d26 |
|