1 Star 0 Fork 120

卫少坤/qemu_src

forked from src-openEuler/qemu 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
virtio-check-descriptor-numbers.patch 1.71 KB
一键复制 编辑 原始数据 按行查看 历史
Jiabo Feng 提交于 2024-04-07 10:21 . QEMU update to version 8.2.0-5
From b57e956ea522b487081d1c94aa2e4af6a3314d20 Mon Sep 17 00:00:00 2001
From: Jinhua Cao <caojinhua1@huawei.com>
Date: Thu, 10 Feb 2022 11:09:36 +0800
Subject: [PATCH] virtio: check descriptor numbers
Check if the vring num is normal in virtio_save(), and add LOG
the vm push the wrong viring num down through writing IO Port.
Signed-off-by: Jinhua Cao <caojinhua1@huawei.com>
---
hw/virtio/virtio.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index a9aa0c4f66..27ceab92be 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -2797,6 +2797,22 @@ static const VMStateDescription vmstate_virtio = {
}
};
+static void check_vring_avail_num(VirtIODevice *vdev, int index)
+{
+ uint16_t nheads;
+
+ /* Check it isn't doing strange things with descriptor numbers. */
+ nheads = vring_avail_idx(&vdev->vq[index]) - vdev->vq[index].last_avail_idx;
+ if (nheads > vdev->vq[index].vring.num) {
+ qemu_log("VQ %d size 0x%x Guest index 0x%x "
+ "inconsistent with Host index 0x%x: "
+ "delta 0x%x\n",
+ index, vdev->vq[index].vring.num,
+ vring_avail_idx(&vdev->vq[index]),
+ vdev->vq[index].last_avail_idx, nheads);
+ }
+}
+
int virtio_save(VirtIODevice *vdev, QEMUFile *f)
{
BusState *qbus = qdev_get_parent_bus(DEVICE(vdev));
@@ -2827,6 +2843,8 @@ int virtio_save(VirtIODevice *vdev, QEMUFile *f)
if (vdev->vq[i].vring.num == 0)
break;
+ check_vring_avail_num(vdev, i);
+
qemu_put_be32(f, vdev->vq[i].vring.num);
if (k->has_variable_vring_alignment) {
qemu_put_be32(f, vdev->vq[i].vring.align);
--
2.27.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/weishaokun/qemu_src.git
git@gitee.com:weishaokun/qemu_src.git
weishaokun
qemu_src
qemu_src
master

搜索帮助