From patchwork Tue Jun 27 17:47:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 9812921 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 998D26020A for ; Tue, 27 Jun 2017 17:50:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D7CB28718 for ; Tue, 27 Jun 2017 17:50:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8223D28722; Tue, 27 Jun 2017 17:50:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1E65A28718 for ; Tue, 27 Jun 2017 17:50:51 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dPubR-0003MG-Mu; Tue, 27 Jun 2017 17:48:41 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dPubQ-0003Lb-I8 for xen-devel@lists.xen.org; Tue, 27 Jun 2017 17:48:40 +0000 Received: from [193.109.254.147] by server-5.bemta-6.messagelabs.com id 8C/65-03371-87A92595; Tue, 27 Jun 2017 17:48:40 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprHIsWRWlGSWpSXmKPExsXitHSDvW75rKB Ig8MvtS2WfFzM4sDocXT3b6YAxijWzLyk/IoE1ow/iy8zFjwWrThyYB1zA+MUoS5GTg4JAX+J yfN/MIPYbAL6ErtffGICsUUE1CVOd1xk7WLk4mAW6GWUuDhxNztIQljAVeLzraNsIDaLgKpE3 +m5rCA2r4CnxOP/15kghspJnD/+E2wop4CXxM91v8BsIaCaa38Os0DUC0qcnPkEzGYW0JRo3f 6bHcKWl2jeOhuqXk3iWv8l9gmMfLOQtMxC0jILScsCRuZVjBrFqUVlqUW6hkZ6SUWZ6RkluYm ZObqGBmZ6uanFxYnpqTmJScV6yfm5mxiB4cYABDsYL28MOMQoycGkJMp7qjMoUogvKT+lMiOx OCO+qDQntfgQowwHh5IE774ZQDnBotT01Iq0zBxg4MOkJTh4lER4xaYDpXmLCxJzizPTIVKnG BWlxHn/gPQJgCQySvPg2mDRdolRVkqYlxHoECGegtSi3MwSVPlXjOIcjErCvAdBpvBk5pXATX 8FtJgJaDHLvACQxSWJCCmpBsaETxY7r/TtOcKayb3tdq+WzDP3LE59RlmPAy1dJ3rvSxwMk9X axHVacJ/iUbv/7Uedos3yX8u071fM2W+6fMvSzmnCk66vXJDNLfDn08eIM+K/Dk/fEMcuIF8d +uaSxuVuq+/7LsU7vbyqeo23e+mTvf9WLXTKiN6u2Gp2UmX6ka25MjVGD6YrsRRnJBpqMRcVJ wIAMGiCnLECAAA= X-Env-Sender: prvs=344358ddb=Andrew.Cooper3@citrix.com X-Msg-Ref: server-6.tower-27.messagelabs.com!1498585717!109914420!2 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.4.19; banners=-,-,- X-VirusChecked: Checked Received: (qmail 31079 invoked from network); 27 Jun 2017 17:48:39 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-6.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 27 Jun 2017 17:48:39 -0000 X-IronPort-AV: E=Sophos;i="5.40,271,1496102400"; d="scan'208";a="438026171" From: Andrew Cooper To: Xen-devel Date: Tue, 27 Jun 2017 18:47:53 +0100 Message-ID: <1498585673-23268-2-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1498585673-23268-1-git-send-email-andrew.cooper3@citrix.com> References: <1498585673-23268-1-git-send-email-andrew.cooper3@citrix.com> MIME-Version: 1.0 Cc: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [Xen-devel] [PATCH 2/2] xen/pt: Avoid NULL dereference in hvm_pirq_eoi() X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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é --- CC: Jan Beulich CC: Roger Pau Monné --- 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(-) diff --git a/xen/arch/x86/irq.c b/xen/arch/x86/irq.c index 523d089..d9fea2c 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 25e3fb4..ffeaf70 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 182caa4..abb1f1c 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);