From: Alon Levy <alevy@redhat.com>
To: qemu-devel@nongnu.org
Cc: kraxel@redhat.com
Subject: [Qemu-devel] [PATCH 1/2] hw/qxl: extract verify_surface_cmd from qxl_track_command
Date: Tue, 20 Nov 2012 11:19:00 +0200 [thread overview]
Message-ID: <1353403141-32070-1-git-send-email-alevy@redhat.com> (raw)
Signed-off-by: Alon Levy <alevy@redhat.com>
---
hw/qxl.c | 48 +++++++++++++++++++++++++++++-------------------
1 file changed, 29 insertions(+), 19 deletions(-)
diff --git a/hw/qxl.c b/hw/qxl.c
index 1482389..af5f68e 100644
--- a/hw/qxl.c
+++ b/hw/qxl.c
@@ -430,6 +430,34 @@ static void qxl_ring_set_dirty(PCIQXLDevice *qxl)
qxl_set_dirty(&qxl->vga.vram, addr, end);
}
+static int verify_surface_cmd(PCIQXLDevice *qxl, QXLSurfaceCmd *cmd)
+{
+ uint32_t id = le32_to_cpu(cmd->surface_id);
+
+ if (id >= qxl->ssd.num_surfaces) {
+ qxl_set_guest_bug(qxl, "QXL_CMD_SURFACE id %d >= %d", id,
+ qxl->ssd.num_surfaces);
+ return 1;
+ }
+ if (cmd->type == QXL_SURFACE_CMD_CREATE &&
+ (cmd->u.surface_create.stride & 0x03) != 0) {
+ qxl_set_guest_bug(qxl, "QXL_CMD_SURFACE stride = %d %% 4 != 0\n",
+ cmd->u.surface_create.stride);
+ return 1;
+ }
+ if (cmd->type == QXL_SURFACE_CMD_CREATE) {
+ intptr_t surface_offset = (intptr_t)qxl_phys2virt(qxl,
+ cmd->u.surface_create.data,
+ MEMSLOT_GROUP_GUEST);
+ if (!surface_offset) {
+ qxl_set_guest_bug(qxl, "QXL_CMD_SURFACE invalid data: %ld\n",
+ cmd->u.surface_create.data);
+ return 1;
+ }
+ }
+ return 0;
+}
+
/*
* keep track of some command state, for savevm/loadvm.
* called from spice server thread context only
@@ -446,27 +474,9 @@ static int qxl_track_command(PCIQXLDevice *qxl, struct QXLCommandExt *ext)
}
uint32_t id = le32_to_cpu(cmd->surface_id);
- if (id >= qxl->ssd.num_surfaces) {
- qxl_set_guest_bug(qxl, "QXL_CMD_SURFACE id %d >= %d", id,
- qxl->ssd.num_surfaces);
+ if (!verify_surface_cmd(qxl, cmd)) {
return 1;
}
- if (cmd->type == QXL_SURFACE_CMD_CREATE &&
- (cmd->u.surface_create.stride & 0x03) != 0) {
- qxl_set_guest_bug(qxl, "QXL_CMD_SURFACE stride = %d %% 4 != 0\n",
- cmd->u.surface_create.stride);
- return 1;
- }
- if (cmd->type == QXL_SURFACE_CMD_CREATE) {
- intptr_t surface_offset = (intptr_t)qxl_phys2virt(qxl,
- cmd->u.surface_create.data,
- MEMSLOT_GROUP_GUEST);
- if (!surface_offset) {
- qxl_set_guest_bug(qxl, "QXL_CMD_SURFACE invalid data: %ld\n",
- cmd->u.surface_create.data);
- return 1;
- }
- }
qemu_mutex_lock(&qxl->track_lock);
if (cmd->type == QXL_SURFACE_CMD_CREATE) {
qxl->guest_surfaces.cmds[id] = ext->cmd.data;
--
1.8.0
next reply other threads:[~2012-11-20 9:19 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-20 9:19 Alon Levy [this message]
2012-11-20 9:19 ` [Qemu-devel] [PATCH 2/2] qxl/verify_surface_cmd: check format != 0 (buggy drivers can do that) Alon Levy
2012-11-20 10:31 ` [Qemu-devel] [PATCH 1/2] hw/qxl: extract verify_surface_cmd from qxl_track_command Gerd Hoffmann
2012-11-20 11:19 ` Alon Levy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1353403141-32070-1-git-send-email-alevy@redhat.com \
--to=alevy@redhat.com \
--cc=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.