Skip to contentSkip to conversation

viridian: make viridian_time_domain_freeze() safe to call...

PATCH In review Paul Durrant 3 participants 4 messages Aug 21, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 viridian: make viridian_time_domain_freeze() safe to call...

...on a partially destroyed domain.

viridian_time_domain_freeze() and viridian_time_vcpu_freeze() rely (respectively) on the dynamically allocated per-domain and per-vcpu viridian areas [1], which are freed during domain_relinquish_resources(). Because arch_domain_pause() can call viridian_domain_time_freeze() this can lead to host crashes if e.g. a XEN_DOMCTL_pausedomain is issued after domain_relinquish_resources() has run.

To prevent such crashes, this patch adds a check of is_dying into viridian_time_domain_freeze(), and viridian_time_domain_thaw() which is similarly vulnerable to indirection into freed memory.

NOTE: The patch also makes viridian_time_vcpu_freeze/thaw() static, since
they have no callers outside of the same source module.

[1] See commit e7a9b5e72f26 "viridian: separately allocate domain and vcpu structures".

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>

---
 xen/arch/x86/hvm/viridian/time.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
xen/arch/x86/hvm/viridian/time.c +4 -4
index ac087383c8..e80330a6ae 100644
@@ -296,7 +296,7 @@ void viridian_time_poll_timers(struct vcpu *v)
         poll_stimer(v, i);
 }
 
-void viridian_time_vcpu_freeze(struct vcpu *v)
+static void viridian_time_vcpu_freeze(struct vcpu *v)
 {
     struct viridian_vcpu *vv = v->arch.hvm.viridian;
     unsigned int i;
@@ -314,7 +314,7 @@ void viridian_time_vcpu_freeze(struct vcpu *v)
     }
 }
 
-void viridian_time_vcpu_thaw(struct vcpu *v)
+static void viridian_time_vcpu_thaw(struct vcpu *v)
 {
     struct viridian_vcpu *vv = v->arch.hvm.viridian;
     unsigned int i;
@@ -336,7 +336,7 @@ void viridian_time_domain_freeze(const struct domain *d)
 {
     struct vcpu *v;
 
-    if ( !is_viridian_domain(d) )
+    if ( d->is_dying || !is_viridian_domain(d) )
         return;
 
     for_each_vcpu ( d, v )
@@ -349,7 +349,7 @@ void viridian_time_domain_thaw(const struct domain *d)
 {
     struct vcpu *v;
 
-    if ( !is_viridian_domain(d) )
+    if ( d->is_dying || !is_viridian_domain(d) )
         return;
 
     time_ref_count_thaw(d);
Signature · 7 lines
2.20.1.2.gb21ebb671


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · Paul Durrant

...on a partially destroyed domain.

viridian_time_domain_freeze() and viridian_time_vcpu_freeze() rely (respectively) on the dynamically allocated per-domain and per-vcpu viridian areas [1], which are freed during domain_relinquish_resources(). Because arch_domain_pause() can call viridian_domain_time_freeze() this can lead to host crashes if e.g. a XEN_DOMCTL_pausedomain is issued after domain_relinquish_resources() has run.

To prevent such crashes, this patch adds a check of is_dying into viridian_time_domain_freeze(), and viridian_time_domain_thaw() which is similarly vulnerable to indirection into freed memory.

Quoted 7 lines

NOTE: The patch also makes viridian_time_vcpu_freeze/thaw() static, since
they have no callers outside of the same source module.

[1] See commit e7a9b5e72f26 "viridian: separately allocate domain and vcpu structures".

Note you could also drop the viridian_ prefix to the now static functions.

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#2 lore raw
Quoted 28 lines

-----Original Message-----
From: Roger Pau Monne <[email protected]>
Sent: 21 August 2019 09:52
To: Paul Durrant <[email protected]>
Cc: [email protected]; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>; Wei Liu <[email protected]>
Subject: Re: [PATCH] viridian: make viridian_time_domain_freeze() safe to call...

Quoted 19 lines · Paul Durrant

...on a partially destroyed domain.

viridian_time_domain_freeze() and viridian_time_vcpu_freeze() rely (respectively) on the dynamically allocated per-domain and per-vcpu viridian areas [1], which are freed during domain_relinquish_resources(). Because arch_domain_pause() can call viridian_domain_time_freeze() this can lead to host crashes if e.g. a XEN_DOMCTL_pausedomain is issued after domain_relinquish_resources() has run.

To prevent such crashes, this patch adds a check of is_dying into viridian_time_domain_freeze(), and viridian_time_domain_thaw() which is similarly vulnerable to indirection into freed memory.

NOTE: The patch also makes viridian_time_vcpu_freeze/thaw() static, since
they have no callers outside of the same source module.

[1] See commit e7a9b5e72f26 "viridian: separately allocate domain and vcpu structures".

Quoted 7 lines
Quoted 1 line

Note you could also drop the viridian_ prefix to the now static functions.

Yeah, they could be dropped. May be a friendly committer could do it? :-)

Paul

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw
Quoted 28 lines · Paul Durrant
Quoted 28 lines

-----Original Message-----
From: Roger Pau Monne <[email protected]>
Sent: 21 August 2019 09:52
To: Paul Durrant <[email protected]>
Cc: [email protected]; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>; Wei Liu <[email protected]>
Subject: Re: [PATCH] viridian: make viridian_time_domain_freeze() safe to call...

Quoted 19 lines · Paul Durrant

...on a partially destroyed domain.

viridian_time_domain_freeze() and viridian_time_vcpu_freeze() rely (respectively) on the dynamically allocated per-domain and per-vcpu viridian areas [1], which are freed during domain_relinquish_resources(). Because arch_domain_pause() can call viridian_domain_time_freeze() this can lead to host crashes if e.g. a XEN_DOMCTL_pausedomain is issued after domain_relinquish_resources() has run.

To prevent such crashes, this patch adds a check of is_dying into viridian_time_domain_freeze(), and viridian_time_domain_thaw() which is similarly vulnerable to indirection into freed memory.

NOTE: The patch also makes viridian_time_vcpu_freeze/thaw() static, since
they have no callers outside of the same source module.

[1] See commit e7a9b5e72f26 "viridian: separately allocate domain and vcpu structures".

Quoted 7 lines
Quoted 6 lines
Quoted 1 line

Note you could also drop the viridian_ prefix to the now static functions.

Yeah, they could be dropped. May be a friendly committer could do it? :-)

Done.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel