From: Andrew Cooper Date: Tue, 27 Jun 2017 17:45:03 +0000 (+0100) Subject: xen/pt: Avoid NULL dereference in hvm_pirq_eoi() X-Git-Tag: archive/raspbian/4.11.1-1+rpi1~1^2~66^2~1896 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=34c06658c100414edc7bbbf23e284019facc965e;p=xen.git 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. Signed-off-by: Andrew Cooper Acked-by: Jan Beulich Reviewed-by: Roger Pau Monné --- diff --git a/xen/arch/x86/irq.c b/xen/arch/x86/irq.c index 523d089006..d9fea2c638 100644 --- a/xen/arch/x86/irq.c +++ b/xen/arch/x86/irq.c @@ -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, diff --git a/xen/drivers/passthrough/io.c b/xen/drivers/passthrough/io.c index 25e3fb4078..ffeaf70be6 100644 --- a/xen/drivers/passthrough/io.c +++ b/xen/drivers/passthrough/io.c @@ -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 diff --git a/xen/include/asm-x86/irq.h b/xen/include/asm-x86/irq.h index 182caa44be..abb1f1ccda 100644 --- a/xen/include/asm-x86/irq.h +++ b/xen/include/asm-x86/irq.h @@ -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);