Skip to contentSkip to conversation

x86/hvm/viridian: zero and check vcpu context __pad field

PATCH Superseded Paul Durrant 2 participants 3 messages Mar 30, 2016

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 x86/hvm/viridian: zero and check vcpu context __pad field

Commit 57844631 "save APIC assist vector" added an extra field to the viridian vcpu context save record. This field was only a uint8_t and so an extra __pad field was also added to pad up to the next 64-bit boundary.

This patch makes sure that __pad field is zeroed on save and checked for zero on restore. This prevents a potential leak of information from the stack and a compatibility check against future use of the space occupied by the __pad field.

This patch also adds a memset to make sure that the viridian domain context is fully zeroed. This is not strictly necessary but helps make the code more robust if fields are added to that struct in future.

Cc Keir Fraser <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>

---

v2:
- drop is_zero() helper an use memcmp against zero_page instead.
- add memset to viridian_save_domain_ctxt() to reduce potential for information leakage in future.

---
 xen/arch/x86/hvm/viridian.c | 7 +++++++
 1 file changed, 7 insertions(+)
xen/arch/x86/hvm/viridian.c +7 -0
index 5c76c1a..165f58e 100644
@@ -785,6 +785,8 @@ static int viridian_save_domain_ctxt(struct domain *d, hvm_domain_context_t *h)
     if ( !is_viridian_domain(d) )
         return 0;
 
+    memset(&ctxt, 0, sizeof(ctxt));
+
     ctxt.time_ref_count = d->arch.hvm_domain.viridian.time_ref_count.val;
     ctxt.hypercall_gpa  = d->arch.hvm_domain.viridian.hypercall_gpa.raw;
     ctxt.guest_os_id    = d->arch.hvm_domain.viridian.guest_os_id.raw;
@@ -824,6 +826,8 @@ static int viridian_save_vcpu_ctxt(struct domain *d, hvm_domain_context_t *h)
     for_each_vcpu( d, v ) {
         struct hvm_viridian_vcpu_context ctxt;
 
+        memset(&ctxt, 0, sizeof(ctxt));
+
         ctxt.apic_assist_msr = v->arch.hvm_vcpu.viridian.apic_assist.msr.raw;
         ctxt.apic_assist_vector = v->arch.hvm_vcpu.viridian.apic_assist.vector;
 
@@ -851,6 +855,9 @@ static int viridian_load_vcpu_ctxt(struct domain *d, hvm_domain_context_t *h)
     if ( hvm_load_entry_zeroextend(VIRIDIAN_VCPU, h, &ctxt) != 0 )
         return -EINVAL;
 
+    if ( memcmp(&ctxt._pad, zero_page, sizeof(ctxt._pad)) )
+        return -EINVAL;
+
     v->arch.hvm_vcpu.viridian.apic_assist.msr.raw = ctxt.apic_assist_msr;
     if ( v->arch.hvm_vcpu.viridian.apic_assist.msr.fields.enabled )
         initialize_apic_assist(v);
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#1 lore raw

Sorry. Disregard this. I posted too early; it's missing an extern for zero_page.

Paul

Quoted 72 lines

-----Original Message-----
From: Paul Durrant [mailto:[email protected]]
Sent: 30 March 2016 12:25
To: [email protected]
Cc: Paul Durrant; Keir (Xen.org); Jan Beulich; Andrew Cooper
Subject: [PATCH v2] x86/hvm/viridian: zero and check vcpu context __pad field

Commit 57844631 "save APIC assist vector" added an extra field to the viridian vcpu context save record. This field was only a uint8_t and so an extra __pad field was also added to pad up to the next 64-bit boundary.

This patch makes sure that __pad field is zeroed on save and checked for zero on restore. This prevents a potential leak of information from the stack and a compatibility check against future use of the space occupied by the __pad field.

This patch also adds a memset to make sure that the viridian domain context is fully zeroed. This is not strictly necessary but helps make the code more robust if fields are added to that struct in future.

Cc Keir Fraser <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>

---

v2:
- drop is_zero() helper an use memcmp against zero_page instead.
- add memset to viridian_save_domain_ctxt() to reduce potential for information leakage in future.

---
 xen/arch/x86/hvm/viridian.c | 7 +++++++
 1 file changed, 7 insertions(+)
xen/arch/x86/hvm/viridian.c +2 -0
index 5c76c1a..165f58e 100644
@@ -785,6 +785,8 @@ static int viridian_save_domain_ctxt(struct domain
 *d, hvm_domain_context_t *h)
     if ( !is_viridian_domain(d) )
         return 0;
 
+    memset(&ctxt, 0, sizeof(ctxt));
+
     ctxt.time_ref_count = d->arch.hvm_domain.viridian.time_ref_count.val;
     ctxt.hypercall_gpa  = d->arch.hvm_domain.viridian.hypercall_gpa.raw;
     ctxt.guest_os_id    = d->arch.hvm_domain.viridian.guest_os_id.raw;
xen/arch/x86/hvm/viridian.c +5 -0
@@ -824,6 +826,8 @@ static int viridian_save_vcpu_ctxt(struct domain *d,
 hvm_domain_context_t *h)
     for_each_vcpu( d, v ) {
         struct hvm_viridian_vcpu_context ctxt;
 
+        memset(&ctxt, 0, sizeof(ctxt));
+
         ctxt.apic_assist_msr = v->arch.hvm_vcpu.viridian.apic_assist.msr.raw;
         ctxt.apic_assist_vector = v->arch.hvm_vcpu.viridian.apic_assist.vector;
@@ -851,6 +855,9 @@ static int viridian_load_vcpu_ctxt(struct domain *d,
 hvm_domain_context_t *h)
     if ( hvm_load_entry_zeroextend(VIRIDIAN_VCPU, h, &ctxt) != 0 )
         return -EINVAL;
 
+    if ( memcmp(&ctxt._pad, zero_page, sizeof(ctxt._pad)) )
+        return -EINVAL;
+
     v->arch.hvm_vcpu.viridian.apic_assist.msr.raw = ctxt.apic_assist_msr;
     if ( v->arch.hvm_vcpu.viridian.apic_assist.msr.fields.enabled )
         initialize_apic_assist(v);
Quoted 2 lines

--
2.1.4

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#2 lore raw
In reply to Paul Durrant

xen/arch/x86/hvm/viridian.c static int viridian_load_vcpu_ctxt(struct domain *d, hvm_domain_context_t *h) · line 859

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 30.03.16 at 13:25, <[email protected]> wrote:
xen/arch/x86/hvm/viridian.c +2 -0
@@ -851,6 +855,9 @@ static int viridian_load_vcpu_ctxt(struct domain *d, hvm_domain_context_t *h)
     if ( hvm_load_entry_zeroextend(VIRIDIAN_VCPU, h, &ctxt) != 0 )
         return -EINVAL;
 
+    if ( memcmp(&ctxt._pad, zero_page, sizeof(ctxt._pad)) )
+        return -EINVAL;

Does this build? Right now zero_page[] is static in x86/mm.c afaict...

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel