From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751238AbeAWJ1q (ORCPT ); Tue, 23 Jan 2018 04:27:46 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52138 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750946AbeAWJ1o (ORCPT ); Tue, 23 Jan 2018 04:27:44 -0500 From: Jason Wang To: mst@redhat.com, jasowang@redhat.com, linux-kernel@vger.kernel.org Cc: virtualization@lists.linux-foundation.org, netdev@vger.kernel.org Subject: [PATCH net 2/2] vhost: do not try to access device IOTLB when not initialized Date: Tue, 23 Jan 2018 17:27:26 +0800 Message-Id: <1516699646-7321-2-git-send-email-jasowang@redhat.com> In-Reply-To: <1516699646-7321-1-git-send-email-jasowang@redhat.com> References: <1516699646-7321-1-git-send-email-jasowang@redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The code will try to access dev->iotlb when processing VHOST_IOTLB_INVALIDATE even if it was not initialized which may lead to NULL pointer dereference. Fixes this by check dev->iotlb before. Fixes: 6b1e6cc7855b0 ("vhost: new device IOTLB API") Signed-off-by: Jason Wang --- drivers/vhost/vhost.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 549771a..5727b18 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -1015,6 +1015,10 @@ static int vhost_process_iotlb_msg(struct vhost_dev *dev, vhost_iotlb_notify_vq(dev, msg); break; case VHOST_IOTLB_INVALIDATE: + if (!dev->iotlb) { + ret = -EFAULT; + break; + } vhost_vq_meta_reset(dev); vhost_del_umem_range(dev->iotlb, msg->iova, msg->iova + msg->size - 1); -- 2.7.4