qemu-e2k/include
Carlos López f0d634ea19 virtio: refresh vring region cache after updating a virtqueue size
When a virtqueue size is changed by the guest via
virtio_queue_set_num(), its region cache is not automatically updated.
If the size was increased, this could lead to accessing the cache out
of bounds. For example, in vring_get_used_event():

    static inline uint16_t vring_get_used_event(VirtQueue *vq)
    {
        return vring_avail_ring(vq, vq->vring.num);
    }

    static inline uint16_t vring_avail_ring(VirtQueue *vq, int i)
    {
        VRingMemoryRegionCaches *caches = vring_get_region_caches(vq);
        hwaddr pa = offsetof(VRingAvail, ring[i]);

        if (!caches) {
            return 0;
        }

        return virtio_lduw_phys_cached(vq->vdev, &caches->avail, pa);
    }

vq->vring.num will be greater than caches->avail.len, which will
trigger a failed assertion down the call path of
virtio_lduw_phys_cached().

Fix this by calling virtio_init_region_cache() after
virtio_queue_set_num() if we are not already calling
virtio_queue_set_rings(). In the legacy path this is already done by
virtio_queue_update_rings().

Signed-off-by: Carlos López <clopez@suse.de>
Message-Id: <20230317002749.27379-1-clopez@suse.de>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
Acked-by: Halil Pasic <pasic@linux.ibm.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2023-04-21 03:08:21 -04:00
..
authz
block block, block-backend: write some hot coroutine wrappers by hand 2023-04-11 16:46:49 +02:00
chardev
crypto replace TABs with spaces 2023-03-20 12:43:50 +01:00
disas replace TABs with spaces 2023-03-20 12:43:50 +01:00
exec include/exec: Change reserved_va semantics to last byte 2023-03-28 15:23:10 -07:00
fpu
gdbstub gdbstub: Remove gdb_do_syscallv 2023-03-07 20:44:09 +00:00
hw virtio: refresh vring region cache after updating a virtqueue size 2023-04-21 03:08:21 -04:00
io io: Add support for MSG_PEEK for socket channel 2023-02-06 19:22:56 +01:00
libdecnumber
migration migration: Rename res_{postcopy,precopy}_only 2023-02-15 20:04:30 +01:00
monitor hmp: add cryptodev info command 2023-03-07 12:38:59 -05:00
net net/eth: Introduce EthL4HdrProto 2023-03-10 15:35:38 +08:00
qapi error: add global &error_warn destination 2023-03-13 15:23:37 +04:00
qemu util: import GTree as QTree 2023-03-28 15:23:10 -07:00
qom
scsi coroutine: Clean up superfluous inclusion of qemu/coroutine.h 2023-01-19 10:18:28 +01:00
semihosting
standard-headers linux-headers: Update to v6.2-rc8 2023-02-16 12:13:46 -07:00
sysemu block, block-backend: write some hot coroutine wrappers by hand 2023-04-11 16:46:49 +02:00
tcg tcg: Drop tcg_const_* 2023-03-13 07:03:39 -07:00
ui ui: introduce egl_init() 2023-03-13 23:48:45 +04:00
user *: Add missing includes of qemu/plugin.h 2023-03-22 15:06:57 +00:00
elf.h replace TABs with spaces 2023-03-20 12:43:50 +01:00
glib-compat.h
qemu-io.h
qemu-main.h