xen/pt: Avoid NULL dereference in hvm_pirq_eoi()
authorAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 27 Jun 2017 17:45:03 +0000 (18:45 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 28 Jun 2017 10:18:40 +0000 (11:18 +0100)
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.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
xen/arch/x86/irq.c
xen/drivers/passthrough/io.c
xen/include/asm-x86/irq.h

index 523d089006eb5ab79b19515af2f8621879aba711..d9fea2c638a8443333739594787ea83058361c11 100644 (file)
@@ -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,
index 25e3fb407861c4821532c71bd03215e92f3c2e92..ffeaf70be625d3d90e10dc99ef9f79cbb6acdc31 100644 (file)
@@ -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
index 182caa44be2fb1c6599f40e24276cb3bbcebd700..abb1f1ccdaed16957717394d802f98fcc1482fc0 100644 (file)
@@ -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);