Skip to contentSkip to conversation

i386/tdx: Fix the UAF issue in tdx_fetch_cpuid()

PATCH In review Xiaoyao Li 2 participants 3 messages Mar 24 x86 trust domain extensions (TDX)

lore
Share & tools
lore

Xiaoyao Li

author
#0 lore raw

PATCH 1/1 i386/tdx: Fix the UAF issue in tdx_fetch_cpuid()

Fix the UAF issue by reading the returned size before freeing the fetch_cpuid structure.

---
 target/i386/kvm/tdx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/kvm/tdx.c +1 -1
index 4cae99c281ac..e578110df4da 100644
@@ -847,8 +847,8 @@ static struct kvm_cpuid2 *tdx_fetch_cpuid(CPUState *cpu, int *ret)
         fetch_cpuid->nent = size;
         r = tdx_vcpu_ioctl(cpu, KVM_TDX_GET_CPUID, 0, fetch_cpuid, &local_err);
         if (r == -E2BIG) {
-            g_free(fetch_cpuid);
             size = fetch_cpuid->nent;
+            g_free(fetch_cpuid);
         }
     } while (r == -E2BIG);
 
Signature · 1 line
2.43.0
#1 lore raw
Quoted 4 lines · Xiaoyao Li

Fix the UAF issue by reading the returned size before freeing the fetch_cpuid structure.

Fixes e3d1a4a6d1d ("i386/tdx: Fetch and validate CPUID of TD guest")
Quoted 20 lines
---
  target/i386/kvm/tdx.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/kvm/tdx.c +1 -1
index 4cae99c281ac..e578110df4da 100644
@@ -847,8 +847,8 @@ static struct kvm_cpuid2 *tdx_fetch_cpuid(CPUState *cpu, int *ret)
          fetch_cpuid->nent = size;
          r = tdx_vcpu_ioctl(cpu, KVM_TDX_GET_CPUID, 0, fetch_cpuid, &local_err);
          if (r == -E2BIG) {
-            g_free(fetch_cpuid);
              size = fetch_cpuid->nent;
+            g_free(fetch_cpuid);
          }
      } while (r == -E2BIG);
 
author
#2 lore raw
Quoted 7 lines · Philippe Mathieu-Daudé
Quoted 4 lines · Xiaoyao Li

Fix the UAF issue by reading the returned size before freeing the fetch_cpuid structure.

Fixes e3d1a4a6d1d ("i386/tdx: Fetch and validate CPUID of TD guest")

Oh, I missed this.

Thanks for providing it!

Quoted 21 lines
Quoted 20 lines

---
  target/i386/kvm/tdx.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/kvm/tdx.c +1 -1
index 4cae99c281ac..e578110df4da 100644
@@ -847,8 +847,8 @@ static struct kvm_cpuid2 *tdx_fetch_cpuid(CPUState 
 *cpu, int *ret)
           fetch_cpuid->nent = size;
           r = tdx_vcpu_ioctl(cpu, KVM_TDX_GET_CPUID, 0, fetch_cpuid, &local_err);
           if (r == -E2BIG) {
-            g_free(fetch_cpuid);
               size = fetch_cpuid->nent;
+            g_free(fetch_cpuid);
           }
       } while (r == -E2BIG);