From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 917F236C9D0 for ; Fri, 7 Aug 2026 02:27:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786069630; cv=none; b=fH2wHmInnYpOKaOLEcpuuamypNGg9ggqWMmfGzghKhk/6irn0NKmGyJ6WMInveKmfG6XwT+/VSDrRfb0SAOK31XF/e57aoEa4N1GOxu0DTfQqz5qVSCrh+1JGXBykUXn4eof1V86b8cAHNSLWctkVYPzxCSwV4IkXDoG+Q17UAs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786069630; c=relaxed/simple; bh=0sIHYHXmj4kfkFzJUw5iipjWTE9r6gD6R63u5QZ378E=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Dd2kr1dIlRDet+MhLwWoTRFkx+wMJL4RaHnZ/bqHfz3z5gheu4V/fdkH7bwC+usYNpFBclQzMflyJeWvIbeS4EyXjufIbbz695tHcMSESUgRfUSDfzq5MNVsGh6nzdJhHFn9VUZE867ucbL9ucGzhRmCBWA2LexE2hwGoue6wig= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=EFxONSwv; arc=none smtp.client-ip=209.85.214.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EFxONSwv" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2ceaf8a1265so42448835ad.2 for ; Thu, 06 Aug 2026 19:27:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786069629; x=1786674429; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=Rt72B6lVkq2wOx7y/7/IbB63EiyH3V4VoZfX5qtaWOk=; b=EFxONSwv41DNxoIUBAuQH3qxgcFTC2ucmMRVeMwjw5MtegTuoXDUEr8NCDrND7lgb0 CElXma4F2GYcUlApwXh5WGdiHXonlq1Pl3d4S9XmN4hvgNUokwgajYibn7lzN4lBLAKB tMDYz4rBE8JYflGovSosd1xzptUEr91ejHKCJP4NK0Ib4lop89yLC9zLxRmSa9n8UN9+ 9RPS3So+fwTNOEfWCyPpXAgXEoahbBrSoj3D+BmJwsBXRjod2mZDWyNz5rGic58NGunW mmnGgQ90jSgVc/P/F7vH571VlTyBcjciGpZ3s9aXm1H17Exs60R7aRohFRpdpHzlMF/m lkqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786069629; x=1786674429; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Rt72B6lVkq2wOx7y/7/IbB63EiyH3V4VoZfX5qtaWOk=; b=VvAkQvzTkpkKQj2usuYw5ogCFXN6+FuI6rsp9Nj43yY1oH3JmfQPQv/1CZRSL/QN4C kLvEmM+3sCsMwRFkFq69s7mUmFNKY7GHw35HGuA66FDfsY3VL9Wv/yYwv8XsihOylOfA XEBkQ+V2Q6P7boimAs7paOCS9TPmEtZA24+YDUVYEqWy1ZfbNx3Ccp8W6P0V//G5YBJq pr1tyNlsOowbPpt1kTKXXULSQ5oem2ghf0ZjuUPrGEn095Djyfilw4271fNbqDG7SXDG AtmyXGkOvVBwiy+VJ3MKpTyIB3GMw+KvhpcPX8e2oMir9/NYUWn3webHEMtHMPXNKAQz lzcA== X-Forwarded-Encrypted: i=1; AHgh+RplHyQmgIVWkbRHeIz9mS24XgbBpWoaYJnRRPEX+npBNJaxSkXrsuYTVemzfVBZEFWiUc9PlyKfPylJE9w=@vger.kernel.org X-Gm-Message-State: AOJu0YyfmJ4nD6X6ghPWRo+0yiGBozTU60FQNfU5RfIIOFzqV545lpVy XDZ9cncw4nm5HK7gXWpFVA/+JIb12aaotKlN7gsMwheQeFesKnaLIrTv X-Gm-Gg: AR+sD13ZTidKzCRzlHUOITHKpIZvdPjSXoT5BDQIHW1qWmGqtVCpBs5rKvnx7DSyYor PjXDGK5Q9zASakEfvBd3TcSDLpN1owgT8HhX97Tm/4aUOp9w3XpldccmxJhq0M0X2aroPGa/dm1 G9OMfC98x4DmFFJlW1dG3lmvR6Y7KL3LWUD9AHheifTzFct1gSTEN9CGsy2WXZSDJ0kWVI0HodM KSAiBl7k8hQOKhbtnmo2FG6+BmNZde9WxD4VFJVe67sRyOI2cfMcrBVv/FIRauMp7GeunV9ve8/ S4ny03SsD/9F35ulxUSpANP9s13VU7Rt2y9AwIs3RDRR3+lnVHKrgF+BKtqF6kVROXb+Z9fDn9O CJnBm9jGaXycttmDxmoSZEWu3nftMi2MxLK0jf3GshmWdY/ZFA1PKA4TiFaASPWMnU5DLIBRC9T 8bxrT0oSQmDLb5nGQe/DWC52gz7UTQ1iTT1Co4ei2F6BeTPfoI6uheQkxrx0Ic41MCeSVm8rUi1 NN5yqMH6HOx7198Beh9Il/kZFmaQrizKZ+Sj5t71oJqTluXvIP4q2Y= X-Received: by 2002:a05:6a21:a04:b0:3bf:9aa9:b2a4 with SMTP id adf61e73a8af0-3cb85ef91f7mr24553793637.20.1786069628776; Thu, 06 Aug 2026 19:27:08 -0700 (PDT) Received: from EAIT-H54D9Q2FJQ.eait.uq.edu.au ([130.102.10.60]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-315beb88413sm1843082eec.18.2026.08.06.19.27.04 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 06 Aug 2026 19:27:08 -0700 (PDT) From: Yu Zhang To: "Michael S . Tsirkin" , Jason Wang , Xuan Zhuo , =?UTF-8?q?Eugenio=20P=C3=A9rez?= Cc: virtualization@lists.linux.dev, kvm@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Yu Zhang Subject: [PATCH] vduse: reject non-coherent iotlb entries in the coherent fault path Date: Fri, 7 Aug 2026 12:26:57 +1000 Message-ID: <20260807022657.11318-1-yuz08559@gmail.com> X-Mailer: git-send-email 2.55.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit vduse_domain_get_coherent_page() turns an iotlb entry into a struct page with pfn_to_page((map->addr + iova - map->start) >> PAGE_SHIFT) and takes a reference on it, with no check that map->addr is a physical address. That assumption only holds for entries created by the domain's own coherent allocator (vduse_domain_alloc_coherent(), which stores virt_to_phys()). VDUSE registers its vdpa device with use_va=true, so for a use_va device vhost_vdpa_va_map() passes a userspace virtual address as the map address, and vduse_domain_set_map() copies those entries verbatim into the same domain->iotlb. Both kinds of entry share one tree, and the mmap fault handler only splits them by iova < bounce_size, so a use_va entry placed above bounce_size lands in the coherent path. A userspace daemon can exploit this: bind the device to virtio_vdpa so the coherent allocator mints an entry whose backing file is the domain's anon inode, obtain the domain fd with VDUSE_IOTLB_GET_FD2, rebind to vhost_vdpa without deleting the vdpa device (vdpa_dev_del() only calls _vdpa_unregister_device(), so the domain and the fd survive), install a VHOST_IOTLB_UPDATE over the same iova with an arbitrary uaddr, then fault the domain mapping. The kernel computes pfn = uaddr >> PAGE_SHIFT from the userspace value and hands the daemon a struct page for a pfn of its choosing -- an out-of-bounds vmemmap access for a wild value: BUG: unable to handle page fault for address: ffffea8000000008 RIP: vduse_domain_mmap_fault+0x100/0x330 or, for a value that resolves to a valid pfn, a read/write window onto an arbitrary physical page (confirmed: a write through the domain mapping lands on a page selected purely by the fabricated pfn). Coherent entries are always registered with domain->file as their backing file, while entries installed through a vhost IOTLB message carry the mapped vma's file (vhost_vdpa_va_map() stores get_file(vma->vm_file)). Reject any entry whose file is not domain->file before calling pfn_to_page(); the fault then returns VM_FAULT_SIGBUS. Legitimate coherent mappings are unaffected. Fixes: 8c773d53fb7b ("vduse: Implement an MMU-based software IOTLB") Signed-off-by: Yu Zhang --- drivers/vdpa/vdpa_user/iova_domain.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/vdpa/vdpa_user/iova_domain.c b/drivers/vdpa/vdpa_user/iova_domain.c index 4dc76c0..847f010 100644 --- a/drivers/vdpa/vdpa_user/iova_domain.c +++ b/drivers/vdpa/vdpa_user/iova_domain.c @@ -221,6 +221,7 @@ vduse_domain_get_coherent_page(struct vduse_iova_domain *domain, u64 iova) u64 start = iova & PAGE_MASK; u64 last = start + PAGE_SIZE - 1; struct vhost_iotlb_map *map; + struct vdpa_map_file *map_file; struct page *page = NULL; spin_lock(&domain->iotlb_lock); @@ -228,6 +229,17 @@ vduse_domain_get_coherent_page(struct vduse_iova_domain *domain, u64 iova) if (!map) goto out; + /* + * Only coherent allocations made by this domain are backed by a real + * struct page here: their map->addr is a physical address and their + * backing file is the domain's own anon inode. Entries installed via a + * vhost IOTLB message on a use_va device instead carry a userspace + * virtual address in map->addr, and must never be fed to pfn_to_page(). + */ + map_file = (struct vdpa_map_file *)map->opaque; + if (map_file->file != domain->file) + goto out; + page = pfn_to_page((map->addr + iova - map->start) >> PAGE_SHIFT); get_page(page); out: -- 2.43.0