If there is existing launch update data and kernel hashes data, they need to be freed when initialization code is executed. This is important for resettable confidential guests where the initialization happens once every reset.
Signed-off-by: Ani Sinha <[email protected]> --- target/i386/sev.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/target/i386/sev.c b/target/i386/sev.c index 1212acfaa1..83b9bfb2ae 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -1791,6 +1791,7 @@ static int sev_common_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) uint32_t host_cbitpos; static bool notifiers_added; struct sev_user_data_status status = {}; + SevLaunchUpdateData *data, *next_elm; SevCommonState *sev_common = SEV_COMMON(cgs); SevCommonStateClass *klass = SEV_COMMON_GET_CLASS(cgs); X86ConfidentialGuestClass *x86_klass = @@ -1798,6 +1799,11 @@ static int sev_common_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) sev_common->state = SEV_STATE_UNINIT; + /* free existing launch update data if any */ + QTAILQ_FOREACH_SAFE(data, &launch_update, next, next_elm) { + g_free(data); + } + host_cpuid(0x8000001F, 0, NULL, &ebx, NULL, NULL); host_cbitpos = ebx & 0x3f; @@ -1989,6 +1995,8 @@ static int sev_snp_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) { MachineState *ms = MACHINE(qdev_get_machine()); X86MachineState *x86ms = X86_MACHINE(ms); + SevCommonState *sev_common = SEV_COMMON(cgs); + SevSnpGuestState *sev_snp_guest = SEV_SNP_GUEST(sev_common); if (x86ms->smm == ON_OFF_AUTO_AUTO) { x86ms->smm = ON_OFF_AUTO_OFF; @@ -1997,6 +2005,10 @@ static int sev_snp_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) return -1; } + /* free existing kernel hashes data if any */ + g_free(sev_snp_guest->kernel_hashes_data); + sev_snp_guest->kernel_hashes_data = NULL; + return 0; } -- 2.42.0
