Skip to contentSkip to conversation

x86/hvm: Fix rcu_unlock_domain call bypass

PATCH In review Adrian Pop 3 participants 4 messages Nov 14, 2017

lore
Share & tools
lore

Adrian Pop

author
#0 lore raw

PATCH 1/1 x86/hvm: Fix rcu_unlock_domain call bypass

rcu_lock_current_domain is called at the beginning of do_altp2m_op, but the altp2m_vcpu_enable_notify subop handler might skip calling rcu_unlock_domain, possibly hanging the domain altogether.

---
 xen/arch/x86/hvm/hvm.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/hvm.c +7 -1
index 205b4cb685..0af498a312 100644
@@ -4534,12 +4534,18 @@ static int do_altp2m_op(
 
         if ( a.u.enable_notify.pad || a.domain != DOMID_SELF ||
              a.u.enable_notify.vcpu_id != curr->vcpu_id )
+        {
             rc = -EINVAL;
+            break;
+        }
 
         if ( !gfn_eq(vcpu_altp2m(curr).veinfo_gfn, INVALID_GFN) ||
              mfn_eq(get_gfn_query_unlocked(curr->domain,
                     a.u.enable_notify.gfn, &p2mt), INVALID_MFN) )
-            return -EINVAL;
+        {
+            rc = -EINVAL;
+            break;
+        }
 
         vcpu_altp2m(curr).veinfo_gfn = _gfn(a.u.enable_notify.gfn);
         altp2m_vcpu_update_vmfunc_ve(curr);
Signature · 7 lines
2.15.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Adrian Pop

rcu_lock_current_domain is called at the beginning of do_altp2m_op, but the altp2m_vcpu_enable_notify subop handler might skip calling rcu_unlock_domain, possibly hanging the domain altogether.

CC'ing Julien.  This is 4.10 material IMO; it would be a security issue if rcu_lock_current_domain() wasn't a nop in Xen.  Debug builds are also liable to hit an assertion pertaining to the preempt_count() (which again, is only ever read in debug builds).

Quoted 18 lines
---
 xen/arch/x86/hvm/hvm.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/hvm.c +3 -0
index 205b4cb685..0af498a312 100644
@@ -4534,12 +4534,18 @@ static int do_altp2m_op(
 
         if ( a.u.enable_notify.pad || a.domain != DOMID_SELF ||
              a.u.enable_notify.vcpu_id != curr->vcpu_id )
+        {
             rc = -EINVAL;
+            break;
+        }
 
         if ( !gfn_eq(vcpu_altp2m(curr).veinfo_gfn, INVALID_GFN) ||

xen/arch/x86/hvm/hvm.c static int do_altp2m_op( · line 4551

Quoted 10 lines
xen/arch/x86/hvm/hvm.c +4 -1
              mfn_eq(get_gfn_query_unlocked(curr->domain,
                     a.u.enable_notify.gfn, &p2mt), INVALID_MFN) )
-            return -EINVAL;
+        {
+            rc = -EINVAL;
+            break;
+        }
 
         vcpu_altp2m(curr).veinfo_gfn = _gfn(a.u.enable_notify.gfn);
         altp2m_vcpu_update_vmfunc_ve(curr);

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

#2 lore raw
In reply to Adrian Pop
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 14.11.17 at 16:11, <[email protected]> wrote:

rcu_lock_current_domain is called at the beginning of do_altp2m_op, but the altp2m_vcpu_enable_notify subop handler might skip calling rcu_unlock_domain, possibly hanging the domain altogether.

I fully agree with the change, but the description needs improvement. For one, why would the domain be hanging with

static inline struct domain *rcu_lock_current_domain(void)

{
    return /*rcu_lock_domain*/(current->domain);
}

? And even if the lock function invocation wasn't commented out, all it does is preempt_disable(). That may cause an assertion to trigger in debug builds, but that's not a domain hang. Plus ...

xen/arch/x86/hvm/hvm.c static int do_altp2m_op( · line 4540

Quoted 10 lines
xen/arch/x86/hvm/hvm.c +3 -0
@@ -4534,12 +4534,18 @@ static int do_altp2m_op(
 
         if ( a.u.enable_notify.pad || a.domain != DOMID_SELF ||
              a.u.enable_notify.vcpu_id != curr->vcpu_id )
+        {
             rc = -EINVAL;
+            break;
+        }

... you also change flow here, which is a second bug you address, but you fail to mention it.

Jan

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

author
#3 lore raw

Hello,

Quoted 9 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 14.11.17 at 16:11, <[email protected]> wrote:

rcu_lock_current_domain is called at the beginning of do_altp2m_op, but the altp2m_vcpu_enable_notify subop handler might skip calling rcu_unlock_domain, possibly hanging the domain altogether.

I fully agree with the change, but the description needs improvement. For one, why would the domain be hanging with

static inline struct domain *rcu_lock_current_domain(void)

Quoted 8 lines
{
    return /*rcu_lock_domain*/(current->domain);
}

? And even if the lock function invocation wasn't commented out, all it does is preempt_disable(). That may cause an assertion to trigger in debug builds, but that's not a domain hang. Plus ...

Sorry, I was indeed referring to the preempt_count() assertion, only using poor wording. I had tested something else using rcu_lock_domain_by_id() instead of rcu_lock_current_domain() which triggered the assertion.

Quoted 5 lines
Quoted 5 lines
xen/arch/x86/hvm/hvm.c +0 -0
@@ -4534,12 +4534,18 @@ static int do_altp2m_op(
 
Quoted 9 lines

xen/arch/x86/hvm/hvm.c static int do_altp2m_op( · line 4540

Quoted 6 lines
xen/arch/x86/hvm/hvm.c +3 -0
         if ( a.u.enable_notify.pad || a.domain != DOMID_SELF ||
              a.u.enable_notify.vcpu_id != curr->vcpu_id )
+        {
             rc = -EINVAL;
+            break;
+        }

... you also change flow here, which is a second bug you address, but you fail to mention it.

OK.

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