xen/pt: Unlock d->event_lock on error paths
PATCH 1/2 xen/pt: Unlock d->event_lock on error paths
Introduced by c/s fba00494268 "x86/pt: enable binding of GSIs to a PVH Dom0"
Spotted by Coverity.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
--- xen/drivers/passthrough/io.c | 6 ++++++ 1 file changed, 6 insertions(+)
xen/drivers/passthrough/io.c +6 -0
@@ -490,7 +490,11 @@ int pt_irq_create_bind(/* MSI_TRANSLATE is not supported for the hardware domain. */ if ( pt_irq_bind->irq_type !=PT_IRQ_TYPE_PCI || pirq >=hvm_domain_irq (d)->nr_gsis ) + { +spin_unlock (&d->event_lock); +return -EINVAL ; + } guest_gsi = pirq; }
@@ -523,6 +527,8 @@ int pt_irq_create_bind(if ( mask <0 || trigger_mode <0 ) { +spin_unlock (&d->event_lock); +ASSERT_UNREACHABLE ();return -EINVAL ; }
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 2/2 xen/pt: Avoid NULL dereference in hvm_pirq_eoi()
Coverity warns that pirq_dpci unconditionally dereferences a NULL pointer. This warning appears to be triggered by pirq_dpci() which is a hidden ternary expression. In reality, it appears that both callers pass a non-NULL pirq parameter, so the code is ok in practice.
Rearange the logic to fail-safe, which should quiesce Coverity.
Clean up bool_t => bool and trailing whitespace for hvm_domain_use_pirq() while auditing this area.
No (intended) functional change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
--- xen/arch/x86/irq.c | 5 ++--- xen/drivers/passthrough/io.c | 10 +++++++++- xen/include/asm-x86/irq.h | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-)
xen/arch/x86/irq.c +2 -3
@@ -2530,10 +2530,9 @@ void arch_evtchn_bind_pirq(struct domain *d, int pirq)spin_unlock_irqrestore (&desc->lock, flags); } -bool_t hvm_domain_use_pirq (const struct domain *d,const struct pirq *pirq) +bool hvm_domain_use_pirq (const struct domain *d,const struct pirq *pirq) { -return is_hvm_domain (d) && pirq && - pirq->arch.hvm.emuirq !=IRQ_UNBOUND ; +return is_hvm_domain (d) && pirq && pirq->arch.hvm.emuirq !=IRQ_UNBOUND ; } static int allocate_pirq(struct domain *d, int index, int pirq, int irq,
xen/drivers/passthrough/io.c +9 -1
@@ -912,7 +912,15 @@ static void hvm_dirq_assist(struct domain *d, struct hvm_pirq_dpci *pirq_dpci)static void hvm_pirq_eoi (struct pirq *pirq,const union vioapic_redir_entry *ent) { -struct hvm_pirq_dpci *pirq_dpci =pirq_dpci (pirq); +struct hvm_pirq_dpci *pirq_dpci; + +if ( !pirq ) + { +ASSERT_UNREACHABLE (); +return ; + } + + pirq_dpci =pirq_dpci (pirq);/* * No need to get vector lock for timer
xen/include/asm-x86/irq.h +1 -1
@@ -145,7 +145,7 @@ int get_free_pirqs(struct domain *, unsigned int nr);void free_domain_pirqs (struct domain *d);int map_domain_emuirq_pirq (struct domain *d,int pirq,int irq);int unmap_domain_pirq_emuirq (struct domain *d,int pirq); -bool_t hvm_domain_use_pirq (const struct domain *,const struct pirq *); +bool hvm_domain_use_pirq (const struct domain *,const struct pirq *);/* Reset irq affinities to match the given CPU mask. */ void fixup_irqs (const cpumask_t *mask,bool_t verbose);
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 2/2] xen/pt: Avoid NULL dereference in hvm_pirq_eoi()
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Andrew Cooper <[email protected]> 06/27/17 7:48 PM >>>
Coverity warns that
pirq_dpciunconditionally dereferences a NULL pointer. This warning appears to be triggered bypirq_dpci()which is a hidden ternary expression. In reality, it appears that both callers pass a non-NULL pirq parameter, so the code is ok in practice.
Quoted 8 lines
Rearange the logic to fail-safe, which should quiesce Coverity.
Clean up
bool_t=> bool and trailing whitespace forhvm_domain_use_pirq()while auditing this area.No (intended) functional change.
Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 2/2] xen/pt: Avoid NULL dereference in hvm_pirq_eoi()
In reply to Andrew CooperQuoted 5 lines · Andrew Cooper
Coverity warns that
pirq_dpciunconditionally dereferences a NULL pointer. This warning appears to be triggered bypirq_dpci()which is a hidden ternary expression. In reality, it appears that both callers pass a non-NULL pirq parameter, so the code is ok in practice.
Quoted 8 lines
Rearange the logic to fail-safe, which should quiesce Coverity.
Clean up
bool_t=> bool and trailing whitespace forhvm_domain_use_pirq()while auditing this area.No (intended) functional change.
Signed-off-by Andrew Cooper <[email protected]>
hvm_gsi_eoi obviously passes a non-NULL pirq (there's a check just before calling hvm_pirq_eoi.
The same applies to __hvm_dpci_eoi, which is also only called from hvm_dpci_eoi (although there's no explicit check anywhere in that case) that iterates over the list of pirqs bound to specific guest GSI, and having a NULL there would cause havoc.
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Andrew Cooper <[email protected]> 06/27/17 7:48 PM >>>
Introduced by c/s
fba00494268"x86/pt: enable binding of GSIs to a PVH Dom0"Spotted by Coverity.
Signed-off-by Andrew Cooper <[email protected]>
And I'm sorry for not having noticed while reviewing the original patch.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 5 lines · Andrew Cooper
Introduced by c/s
fba00494268"x86/pt: enable binding of GSIs to a PVH Dom0"Spotted by Coverity.
Signed-off-by Andrew Cooper <[email protected]>
Thanks!
None of those paths should be used in any case.
Quoted 25 lines
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>--- xen/drivers/passthrough/io.c | 6 ++++++ 1 file changed, 6 insertions(+)xen/drivers/passthrough/io.c +4
-0@@ -490,7 +490,11 @@ int pt_irq_create_bind(/* MSI_TRANSLATE is not supported for the hardware domain. */ if ( pt_irq_bind->irq_type !=PT_IRQ_TYPE_PCI || pirq >=hvm_domain_irq (d)->nr_gsis ) + { +spin_unlock (&d->event_lock); +return -EINVAL ; + } guest_gsi = pirq; }
xen/drivers/passthrough/io.c int pt_irq_create_bind( · line 533
Quoted 7 lines
xen/drivers/passthrough/io.c +2
-0@@ -523,6 +527,8 @@ int pt_irq_create_bind(if ( mask <0 || trigger_mode <0 ) { +spin_unlock (&d->event_lock); +ASSERT_UNREACHABLE ();return -EINVAL ;
You seem to have added extra newlines between the unlock and the return, is this intentional? I'm asking because it's not done in the other error paths.
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel