From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 53D4E471B7; Thu, 8 Jan 2026 14:50:24 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1BD3E40684; Thu, 8 Jan 2026 14:50:13 +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 6E39B4066B for ; Thu, 8 Jan 2026 14:50:11 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1767880210; 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: in-reply-to:in-reply-to:references:references; bh=pqe3vY4k4iMN2XDPPjCsUjWa+wTNFrbUveruxAS03SA=; b=SLydNQNNbg500sdIJV8yJEa/b0RLJ6JrfurLHeV2y56grpi4leEKjKQm1pPOOGKFYa6pY6 bDfIXLGCgZdKnCA3Ri9zvjRWoo4CAqPAJMWJXCUn6GaIFAf/DyA6bbz2gVLyAOyYLVDe3f BzHqj3nGLEMcpB250gmNMjcbw7qg6g0= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-517-19K85BxJN1GdtKPg3_o52A-1; Thu, 08 Jan 2026 08:50:09 -0500 X-MC-Unique: 19K85BxJN1GdtKPg3_o52A-1 X-Mimecast-MFC-AGG-ID: 19K85BxJN1GdtKPg3_o52A_1767880208 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 92CF11956071; Thu, 8 Jan 2026 13:50:08 +0000 (UTC) Received: from max-p1.redhat.com (unknown [10.45.242.13]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 73E941801A46; Thu, 8 Jan 2026 13:50:06 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, chenbox@nvidia.com, david.marchand@redhat.com Cc: Maxime Coquelin , stable@dpdk.org Subject: [PATCH 3/3] vhost: fix mmap error check in VDUSE IOTLB miss handler Date: Thu, 8 Jan 2026 14:49:51 +0100 Message-ID: <20260108134951.3857110-4-maxime.coquelin@redhat.com> In-Reply-To: <20260108134951.3857110-1-maxime.coquelin@redhat.com> References: <20260108134951.3857110-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 11WSXxbykKmnGAmtByrgIxEZbXV7iMqtHzwLqq960nU_1767880208 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true 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 The mmap() function returns MAP_FAILED on failure, not NULL. The current check for !mmap_addr will never detect mmap failures. When mmap fails but the error is not detected, an invalid address (-1) is inserted into the IOTLB cache via vhost_user_iotlb_cache_insert(). Subsequent attempts to access this address will cause memory corruption or crash. Fix by checking for MAP_FAILED instead of NULL. Also add strerror to the error message for easier debugging. Fixes: f27d5206c598 ("vhost: add VDUSE callback for IOTLB miss") Cc: stable@dpdk.org Signed-off-by: Maxime Coquelin --- lib/vhost/vduse.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/vhost/vduse.c b/lib/vhost/vduse.c index 897dee9f1b..0b5d158fee 100644 --- a/lib/vhost/vduse.c +++ b/lib/vhost/vduse.c @@ -86,9 +86,10 @@ vduse_iotlb_miss(struct virtio_net *dev, uint64_t iova, uint8_t perm __rte_unuse size = entry.last - entry.start + 1; mmap_addr = mmap(0, size + entry.offset, entry.perm, MAP_SHARED, fd, 0); - if (!mmap_addr) { + if (mmap_addr == MAP_FAILED) { VHOST_CONFIG_LOG(dev->ifname, ERR, - "Failed to mmap IOTLB entry for 0x%" PRIx64, iova); + "Failed to mmap IOTLB entry for 0x%" PRIx64 ": %s", + iova, strerror(errno)); ret = -1; goto close_fd; } -- 2.52.0