Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932126AbdHVBWc (ORCPT ); Mon, 21 Aug 2017 21:22:32 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:4974 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754409AbdHVBWb (ORCPT ); Mon, 21 Aug 2017 21:22:31 -0400 From: nixiaoming To: , CC: , , Subject: [PATCH] virt/lib avoids oops by adding parameter checking Date: Tue, 22 Aug 2017 09:07:53 +0800 Message-ID: <20170822010753.102857-1-nixiaoming@huawei.com> X-Mailer: git-send-email 2.11.0.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.187.180] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020201.599B8755.0008,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: f9fc0af77c9a4a4c13fb95fc26b98781 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1766 Lines: 59 The error parameter passed through the external interface causes the system oops. So it is necessary to increase the parameter check for all EXPORT_SYMBOL_GPL example: int irq_bypass_register_producer(struct irq_bypass_producer *producer) { if (!producer->token) /* oops if producer == null */ return -einval; } EXPORT_SYMBOL_GPL(irq_bypass_register_producer); Signed-off-by: nixiaoming --- virt/lib/irqbypass.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/virt/lib/irqbypass.c b/virt/lib/irqbypass.c index 6d2fcd6..2bb99e8 100644 --- a/virt/lib/irqbypass.c +++ b/virt/lib/irqbypass.c @@ -89,7 +89,7 @@ int irq_bypass_register_producer(struct irq_bypass_producer *producer) struct irq_bypass_producer *tmp; struct irq_bypass_consumer *consumer; - if (!producer->token) + if (!producer || !producer->token) return -EINVAL; might_sleep(); @@ -139,7 +139,7 @@ void irq_bypass_unregister_producer(struct irq_bypass_producer *producer) struct irq_bypass_producer *tmp; struct irq_bypass_consumer *consumer; - if (!producer->token) + if (!producer || !producer->token) return; might_sleep(); @@ -183,7 +183,7 @@ int irq_bypass_register_consumer(struct irq_bypass_consumer *consumer) struct irq_bypass_consumer *tmp; struct irq_bypass_producer *producer; - if (!consumer->token || + if (!consumer || !consumer->token || !consumer->add_producer || !consumer->del_producer) return -EINVAL; @@ -234,7 +234,7 @@ void irq_bypass_unregister_consumer(struct irq_bypass_consumer *consumer) struct irq_bypass_consumer *tmp; struct irq_bypass_producer *producer; - if (!consumer->token) + if (!consumer || !consumer->token) return; might_sleep(); -- 2.11.0.1