qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	linzhecheng <linzhecheng@huawei.com>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Amit Shah <amit@kernel.org>, Paolo Bonzini <pbonzini@redhat.com>
Subject: [Qemu-devel] [PULL 5/5] virtio-serial: fix heap-over-flow
Date: Mon, 9 Apr 2018 17:42:09 +0300	[thread overview]
Message-ID: <1523284856-251254-6-git-send-email-mst@redhat.com> (raw)
In-Reply-To: <1523284856-251254-1-git-send-email-mst@redhat.com>

From: linzhecheng <linzhecheng@huawei.com>

Check device having the feature of VIRTIO_CONSOLE_F_EMERG_WRITE before
get config->emerg_wr. It is neccessary because sizeof(virtio_console_config)
is 8 byte if VirtIOSerial doesn't have the feature of
VIRTIO_CONSOLE_F_EMERG_WRITE(see virtio_serial_device_realize),
read/write emerg_wr will lead to heap-over-flow.

Signed-off-by: linzhecheng <linzhecheng@huawei.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/char/virtio-serial-bus.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
index 9470bd7..d2dd8ab 100644
--- a/hw/char/virtio-serial-bus.c
+++ b/hw/char/virtio-serial-bus.c
@@ -580,13 +580,16 @@ static void set_config(VirtIODevice *vdev, const uint8_t *config_data)
     VirtIOSerial *vser = VIRTIO_SERIAL(vdev);
     struct virtio_console_config *config =
         (struct virtio_console_config *)config_data;
-    uint8_t emerg_wr_lo = le32_to_cpu(config->emerg_wr);
     VirtIOSerialPort *port = find_first_connected_console(vser);
     VirtIOSerialPortClass *vsc;
+    uint8_t emerg_wr_lo;
 
-    if (!config->emerg_wr) {
+    if (!virtio_has_feature(vser->host_features,
+        VIRTIO_CONSOLE_F_EMERG_WRITE) || !config->emerg_wr) {
         return;
     }
+
+    emerg_wr_lo = le32_to_cpu(config->emerg_wr);
     /* Make sure we don't misdetect an emergency write when the guest
      * does a short config write after an emergency write. */
     config->emerg_wr = 0;
-- 
MST

  parent reply	other threads:[~2018-04-09 14:42 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-09 14:42 [Qemu-devel] [PULL 0/5] virtio,vhost: fixes Michael S. Tsirkin
2018-04-09 14:42 ` [Qemu-devel] [PULL 1/5] vhost-user-blk: set config ops before vhost-user init Michael S. Tsirkin
2018-04-09 14:42 ` [Qemu-devel] [PULL 2/5] vhost-user: back SET/GET_CONFIG requests with a protocol feature Michael S. Tsirkin
2018-04-09 14:42 ` [Qemu-devel] [PULL 3/5] contrib/libvhost-user: add the protocol feature used for SET/GET message Michael S. Tsirkin
2018-04-09 14:42 ` [Qemu-devel] [PULL 4/5] vhost: Allow adjoining regions Michael S. Tsirkin
2018-04-09 14:42 ` Michael S. Tsirkin [this message]
2018-04-09 16:28 ` [Qemu-devel] [PULL 0/5] virtio,vhost: fixes Peter Maydell

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=1523284856-251254-6-git-send-email-mst@redhat.com \
    --to=mst@redhat.com \
    --cc=amit@kernel.org \
    --cc=linzhecheng@huawei.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).