From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796384306; b=ob8nb3ZqbR3NPw4fpEZFEhmYx9rLAuJ4cYpaewtQZvmdNe3r6tNc62WtpiWElgaXy0LM MzhMvNbsqaGQX3zp5LwaAmSBlFTr9iqhlbwguOc3aJ5k7uzKfO/h5mm5eI+dqMVUs9kox zwlJwX0r1YrgFWw10aWt0lrxKPYamI3JfSr7zRyg70Ibw9e4pZIYho7Tst0M76sMIAgTi AnG6sZHKOMM0V85IOLcAC/y2dfOFEonI080ZsCxUi/JpVFR53xIPGEaSL7mMGZ65287vQ lA2A1k8uru7djOmO6RuUw8Y1PDp1Qq04HlcDary8SaRp1NxAx6qXsiCJYFVne0RE+VQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384306; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=d6/96DEZEKMjZJjW9YoaddOS3W2dFhXl/31z9YFZhn0=; b=wPO+70CjJhu5VwFW631WtNEVT2yOn4mFpNXzfUAjDpExjarb90Oz+fVcD8K75/166IFR 1HAuVX5IKPyu11zuE+MhcYoNSOgq2C843L66WuHwDgSl1FcQTV6rgcnq7MC7m/EAhFrzG 8LfOdKZcq4OIa/ZPIS6GVw1rxyN7EIn1Ks700Wz8hcCO0T7/4eAyoeBSR5fS9AdUtdzXA zm4p1M35jF5kP/l+JRFeaVIP6DaAHMqxfq5jUxCk70RNEGQzfr8Vt7bLZDRbwIhzDso3R hqixI2JvmhjExQJ24gQnN8ouXxsVeRaXrslw1OvHefFEg6WYi0pK/r1YZ1lBEYtv9RA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=Utm2HL9N; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3445A606A322; Fri, 4 Dec 2026 11:38:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=Utm2HL9N Received: by smtp.kernel.org (Postfix) with ESMTPSA id A14AC1F000C2; Fri, 4 Dec 2026 11:38:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384306; bh=d6/96DEZEKMjZJjW9YoaddOS3W2dFhXl/31z9YFZhn0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Utm2HL9Niwu56wpzmZmLvwkP3KK4KFOeYS5B83G/4YXzM+iYezkr5rxBAoUDsNV3Q G29rduPOxXX4upxz7GkVPEE1ZLSGXduZE8oBtC0/wqMZ6xCAk4Ay/5ncUF8xEsawFH r5nxdVJ8X2z3gAPLM57i53o4uTND9mjmZVWHqwD8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Linfeng Sun , "Michael S. Tsirkin" , Sasha Levin Subject: [PATCH 6.6 0095/1167] vdpa_sim: serialize IOTLB updates with dataplane access Date: Fri, 4 Dec 2026 18:52:02 +0900 Message-ID: <20261204100704.573746314@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Linfeng Sun [ Upstream commit 8517ed4429a2eefd002dce00ea46e23e6714350b ] The simulator translates IOTLB entries into iovecs or bvecs under iommu_lock, then drops the lock before copying data. A concurrent DMA unmap can delete the mapping and release its pinned backing pages while the copy is still in progress, leading to a UAF in _copy_from_iter(). Use the existing simulator mutex to serialize DMA map changes with the full backend work function. Also make vhost-vdpa stop device access before unpinning the backing pages. Otherwise, waiting in the simulator DMA unmap callback happens after the pages have already been released and cannot protect their lifetime. Keep iommu_lock for the IOTLB table itself and avoid adding a second long-lived lock to the simulator. I found this bug myself, though the patch was written with AI assistance. Fixes: 2c53d0f64c06 ("vdpasim: vDPA device simulator") Assisted-by: OpenAI-Codex:GPT-5 Signed-off-by: Linfeng Sun Message-ID: <20260911-fix-vdpa-iotlb-lifetime-v3-1-8766d371748e@gmail.com> Signed-off-by: Michael S. Tsirkin Signed-off-by: Sasha Levin --- drivers/vdpa/vdpa_sim/vdpa_sim.c | 4 ++++ drivers/vhost/vdpa.c | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c index b7d24faa8af3e..f11e73123f403 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c @@ -671,6 +671,7 @@ static int vdpasim_dma_map(struct vdpa_device *vdpa, unsigned int asid, if (asid >= vdpasim->dev_attr.nas) return -EINVAL; + mutex_lock(&vdpasim->mutex); spin_lock(&vdpasim->iommu_lock); if (vdpasim->iommu_pt[asid]) { vhost_iotlb_reset(&vdpasim->iommu[asid]); @@ -679,6 +680,7 @@ static int vdpasim_dma_map(struct vdpa_device *vdpa, unsigned int asid, ret = vhost_iotlb_add_range_ctx(&vdpasim->iommu[asid], iova, iova + size - 1, pa, perm, opaque); spin_unlock(&vdpasim->iommu_lock); + mutex_unlock(&vdpasim->mutex); return ret; } @@ -691,6 +693,7 @@ static int vdpasim_dma_unmap(struct vdpa_device *vdpa, unsigned int asid, if (asid >= vdpasim->dev_attr.nas) return -EINVAL; + mutex_lock(&vdpasim->mutex); spin_lock(&vdpasim->iommu_lock); if (vdpasim->iommu_pt[asid]) { vhost_iotlb_reset(&vdpasim->iommu[asid]); @@ -698,6 +701,7 @@ static int vdpasim_dma_unmap(struct vdpa_device *vdpa, unsigned int asid, } vhost_iotlb_del_range(&vdpasim->iommu[asid], iova, iova + size - 1); spin_unlock(&vdpasim->iommu_lock); + mutex_unlock(&vdpasim->mutex); return 0; } diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index 72a60ab7465e4..f0d63e3b5f176 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -916,6 +916,8 @@ static void vhost_vdpa_pa_unmap(struct vhost_vdpa *v, struct vhost_iotlb *iotlb, unsigned long pfn, pinned; while ((map = vhost_iotlb_itree_first(iotlb, start, last)) != NULL) { + /* Stop device access before releasing the pinned pages. */ + vhost_vdpa_general_unmap(v, map, asid); pinned = PFN_DOWN(map->size); for (pfn = PFN_DOWN(map->addr); pinned > 0; pfn++, pinned--) { @@ -925,7 +927,6 @@ static void vhost_vdpa_pa_unmap(struct vhost_vdpa *v, struct vhost_iotlb *iotlb, unpin_user_page(page); } atomic64_sub(PFN_DOWN(map->size), &dev->mm->pinned_vm); - vhost_vdpa_general_unmap(v, map, asid); vhost_iotlb_map_free(iotlb, map); } } -- 2.53.0