Skip to contentSkip to conversation

x86/vMsi-x: check whether the msixtbl_list has been initialized or not when accessing it

PATCH In review Chao Gao 2 participants 3 messages Jul 29, 2016 – Jul 30, 2016

lore
Share & tools
lore

Chao Gao

author
#0 lore raw

PATCH 1/1 x86/vMsi-x: check whether the msixtbl_list has been initialized or not when accessing it

MSI-x tables' initialization had been detered in the commit 74c6dc2d0ac4dcab0c6243cdf6ed550c1532b798. If an assigned device does not support MSI-x, the msixtbl_list won't be initialized. Howerver, both of following paths
XEN_DOMCTL_bind_pt_irq
pt_irq_create_bind
msixtbl_pt_register
and
XEN_DOMCTL_unbind_pt_irq
pt_irq_destroy_bind
msixtbl_pt_unregister
do not check this case and will cause Xen panic consequently.

---
 xen/arch/x86/hvm/vmsi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/x86/hvm/vmsi.c +2 -2
index e418b98..e0d710b 100644
@@ -449,7 +449,7 @@ int msixtbl_pt_register(struct domain *d, struct pirq *pirq, uint64_t gtable)
     ASSERT(pcidevs_locked());
     ASSERT(spin_is_locked(&d->event_lock));
 
-    if ( !has_vlapic(d) )
+    if ( !has_vlapic(d) || !d->arch.hvm_domain.msixtbl_list.next )
         return -ENODEV;
 
     /*
@@ -519,7 +519,7 @@ void msixtbl_pt_unregister(struct domain *d, struct pirq *pirq)
     ASSERT(pcidevs_locked());
     ASSERT(spin_is_locked(&d->event_lock));
 
-    if ( !has_vlapic(d) )
+    if ( !has_vlapic(d) || !d->arch.hvm_domain.msixtbl_list.next )
         return;
 
     irq_desc = pirq_spin_lock_irq_desc(pirq, NULL);
Signature · 7 lines
1.8.3.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw
Quoted 12 lines · Chao Gao

MSI-x tables' initialization had been detered in the commit 74c6dc2d0ac4dcab0c6243cdf6ed550c1532b798. If an assigned device does not support MSI-x, the msixtbl_list won't be initialized. Howerver, both of following paths
XEN_DOMCTL_bind_pt_irq
pt_irq_create_bind
msixtbl_pt_register
and
XEN_DOMCTL_unbind_pt_irq
pt_irq_destroy_bind
msixtbl_pt_unregister
do not check this case and will cause Xen panic consequently.

Quoted 1 line

This issue was already reported and I provided a fix in

https://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;h=db0eee0a071e2e3e18e79d21a9b1d6724edeeeb3

However, looking at your patch, I forgot to fix the msixtbl_pt_register() path, so your patch is still necessary.

Please rebase this patch onto the staging branch which has the aformentioned fix in, at which point it can be accepted. Just one note.

Quoted 9 lines
---
 xen/arch/x86/hvm/vmsi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/x86/hvm/vmsi.c +0 -0
index e418b98..e0d710b 100644

xen/arch/x86/hvm/vmsi.c int msixtbl_pt_register(struct domain *d, struct pirq *pirq, uint64_t gtable) · line 452

Quoted 5 lines
xen/arch/x86/hvm/vmsi.c +1 -1
@@ -449,7 +449,7 @@ int msixtbl_pt_register(struct domain *d, struct pirq *pirq, uint64_t gtable)
     ASSERT(pcidevs_locked());
     ASSERT(spin_is_locked(&d->event_lock));
 
-    if ( !has_vlapic(d) )
+    if ( !has_vlapic(d) || !d->arch.hvm_domain.msixtbl_list.next )

You can drop the vlapic() check, as it is redundant with whether msixtbl is enabled or not.

~Andrew

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

author
#2 lore raw
Quoted 13 lines · Andrew Cooper
Quoted 12 lines · Chao Gao

MSI-x tables' initialization had been detered in the commit 74c6dc2d0ac4dcab0c6243cdf6ed550c1532b798. If an assigned device does not support MSI-x, the msixtbl_list won't be initialized. Howerver, both of following paths
XEN_DOMCTL_bind_pt_irq
pt_irq_create_bind
msixtbl_pt_register
and
XEN_DOMCTL_unbind_pt_irq
pt_irq_destroy_bind
msixtbl_pt_unregister
do not check this case and will cause Xen panic consequently.

Quoted 5 lines
Quoted 1 line

This issue was already reported and I provided a fix in

https://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;h=db0eee0a071e2e3e18e79d21a9b1d6724edeeeb3

I'm sorry for the mistake.

Quoted 2 lines

However, looking at your patch, I forgot to fix the msixtbl_pt_register() path, so your patch is still necessary.

Actually, the msixtbl_pt_register() path never causes a panic unless wrong hypercall paramters are given. Specially, we assign a msi capable but not msi-x capable device to guest, but some errors(malwares, etc.) lead to calling XEN_DOMCTL_bind_pt_irq without a clear gtable.

Quoted 2 lines

Please rebase this patch onto the staging branch which has the aformentioned fix in, at which point it can be accepted. Just one note.

Thanks for your advice.

Quoted 12 lines
Quoted 12 lines
---
 xen/arch/x86/hvm/vmsi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/x86/hvm/vmsi.c +0 -0
index e418b98..e0d710b 100644
@@ -449,7 +449,7 @@ int msixtbl_pt_register(struct domain *d, struct pirq *pirq, uint64_t gtable)
     ASSERT(pcidevs_locked());
     ASSERT(spin_is_locked(&d->event_lock));
 
Quoted 7 lines

xen/arch/x86/hvm/vmsi.c int msixtbl_pt_register(struct domain *d, struct pirq *pirq, uint64_t gtable) · line 452

Quoted 2 lines
xen/arch/x86/hvm/vmsi.c +1 -1
-    if ( !has_vlapic(d) )
+    if ( !has_vlapic(d) || !d->arch.hvm_domain.msixtbl_list.next )

You can drop the vlapic() check, as it is redundant with whether msixtbl is enabled or not.

~Andrew

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