From patchwork Thu Mar 9 11:36:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 124894 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9838341E25; Thu, 9 Mar 2023 12:36:39 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2FC2340ED7; Thu, 9 Mar 2023 12:36:39 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id 1638A400D7 for ; Thu, 9 Mar 2023 12:36:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678361797; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=d3aFANNIs/G+pJR8W2FZm1DU4s3mnuaP3nQZqCuvZvo=; b=QTPMo5a6GJUsb5WeHABtRJmdrHu1hOwiAfxFd7ogpTKExivEBQCnSOeFFDLIwVixrACnpZ 4LtcE0Y9sRDQSQxCxyZ0sgFRx18b91wP8+4roRmPW1bQtUoui4wYToCVvy5mO7HJrzhYvd yY0Fd2sSMsHNV3GMiW2JvenLsP/+u3o= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-75-p88khRkfNC625G8wvz6rzQ-1; Thu, 09 Mar 2023 06:36:36 -0500 X-MC-Unique: p88khRkfNC625G8wvz6rzQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C087880D181; Thu, 9 Mar 2023 11:36:35 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9FAA3440E0; Thu, 9 Mar 2023 11:36:34 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, mkp@redhat.com, chenbo.xia@intel.com, david.marchand@redhat.com Cc: Maxime Coquelin Subject: [PATCH] vhost: fix possible null pointer dereference Date: Thu, 9 Mar 2023 12:36:31 +0100 Message-Id: <20230309113631.300351-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org When handling VHOST_USER_SET_MEM_TABLE request ending up in changing existing memory map, a device's memory pointer may ends up being dereference while being NULL in IOTLB cache flush function. Coverity issue: 383646 Fixes: dea092d0addb ("vhost: fix madvise arguments alignment") Signed-off-by: Maxime Coquelin Reviewed-by: Chenbo Xia --- lib/vhost/vhost_user.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c index 9e361082dc..23a6a4e2bd 100644 --- a/lib/vhost/vhost_user.c +++ b/lib/vhost/vhost_user.c @@ -1355,16 +1355,16 @@ vhost_user_set_mem_table(struct virtio_net **pdev, async_notify = true; } + /* Flush IOTLB cache as previous HVAs are now invalid */ + if (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM)) + for (i = 0; i < dev->nr_vring; i++) + vhost_user_iotlb_flush_all(dev, dev->virtqueue[i]); + free_mem_region(dev); rte_free(dev->mem); dev->mem = NULL; } - /* Flush IOTLB cache as previous HVAs are now invalid */ - if (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM)) - for (i = 0; i < dev->nr_vring; i++) - vhost_user_iotlb_flush_all(dev, dev->virtqueue[i]); - /* * If VQ 0 has already been allocated, try to allocate on the same * NUMA node. It can be reallocated later in numa_realloc().