!168 merge linux-6.6-next into linux-6.6-next
vhost: reset the vring metadata cache on vring reconfiguration
Created-by: Space12138 Commit-by: Jun Yang Merged-by: cz20260325 Description: Mainline: de845981da67a6b049080c87e605130b0c30adc5 From: v7.2-rc7 Severity: Moderate
task: 671153
commit de845981da67a6b049080c87e605130b0c30adc5 upstream.
vq->meta_iotlb[] caches the vhost_iotlb_map that backs each vring metadata region, and iotlb_access_ok() returns early on a cache hit, taking the hit as proof that the region has already been validated:
if (vhost_vq_meta_fetch(vq, addr, len, type)) return true;The cache is reset on VHOST_IOTLB_UPDATE and VHOST_IOTLB_INVALIDATE, on device IOTLB (re)initialisation and on vq reset, but not when VHOST_SET_VRING_ADDR replaces vq->desc, vq->avail and vq->used, nor when VHOST_SET_VRING_NUM changes the region sizes.
With a device IOTLB attached both ioctls are accepted while the vq is live, and neither validates the addresses at ioctl time: vq_access_ok() and vq_log_used_access_ok() return true early because the addresses are GIOVAs, deferring validation to prefetch time. Once the cache has been populated that deferred validation no longer runs – vq_meta_prefetch() hits the stale entry and returns true – and vhost_vq_meta_fetch() keeps translating through the old mapping as
map->addr + addr - map->startfor an address the mapping no longer covers. vhost_copy_to_user() and vhost_copy_from_user() consume the result with __copy_to_user() and __copy_from_user(), which do not check it either, so a subsequent used ring update or descriptor fetch accesses memory outside the region the IOTLB actually maps.
Reset the metadata cache whenever the vring is reconfigured, so the new addresses are pushed back through iotlb_access_ok()’s slow path.
Fixes: f88949138058 (“vhost: introduce O(1) vq metadata cache”) Cc: stable@vger.kernel.org Assisted-by: tencentos-corvus-ai:kimi-k3 Signed-off-by: Jun Yang junvyyang@tencent.com Message-ID: 20260803014823.68623-1-juny24602@gmail.com Signed-off-by: Michael S. Tsirkin mst@redhat.com Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org
(backported from commit cf363a7a02ce132ef1f58084fdb13e1a3b7da7e7)
K2CI-Arch: None Signed-off-by: k2ci kernel-bot@kylinos.cn Change-Id: If3ef358d32da5ee053efa641f4849ae7f2345405 Reviewed-on: https://code.kylinos.cn:443/c/institute/kernel/klinux/+/276875 Reviewed-by: 刘云 liuyun01@kylinos.cn
See merge request: openkylin/linux!168
版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9
京公网安备 11010802047560号
Linux kernel
There are several guides for kernel developers and users. These guides can be rendered in a number of formats, like HTML and PDF. Please read Documentation/admin-guide/README.rst first.
In order to build the documentation, use
make htmldocsormake pdfdocs. The formatted documentation can also be read online at:There are various text files in the Documentation/ subdirectory, several of them using the Restructured Text markup notation.
Please read the Documentation/process/changes.rst file, as it contains the requirements for building and running the kernel, and information about the problems which may result by upgrading your kernel.