All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2] virtio-serial: fix heap-over-flow
@ 2018-03-28 13:34 linzhecheng
  2018-04-04  9:53 ` Stefan Hajnoczi
  0 siblings, 1 reply; 3+ messages in thread
From: linzhecheng @ 2018-03-28 13:34 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, mst, amit.shah, wangxinxin.wang, linzhecheng

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>

diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
index 9470bd7be7..d2dd8ab502 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;
-- 
2.12.2.windows.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH v2] virtio-serial: fix heap-over-flow
  2018-03-28 13:34 [Qemu-devel] [PATCH v2] virtio-serial: fix heap-over-flow linzhecheng
@ 2018-04-04  9:53 ` Stefan Hajnoczi
  2018-04-04 14:22   ` Michael S. Tsirkin
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Hajnoczi @ 2018-04-04  9:53 UTC (permalink / raw)
  To: pbonzini, mst; +Cc: qemu-devel, amit.shah, wangxinxin.wang, linzhecheng

[-- Attachment #1: Type: text/plain, Size: 553 bytes --]

On Wed, Mar 28, 2018 at 09:34:35PM +0800, linzhecheng wrote:
> 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>

Michael or Paolo: Please merge for QEMU 2.12

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH v2] virtio-serial: fix heap-over-flow
  2018-04-04  9:53 ` Stefan Hajnoczi
@ 2018-04-04 14:22   ` Michael S. Tsirkin
  0 siblings, 0 replies; 3+ messages in thread
From: Michael S. Tsirkin @ 2018-04-04 14:22 UTC (permalink / raw)
  To: Stefan Hajnoczi
  Cc: pbonzini, qemu-devel, amit.shah, wangxinxin.wang, linzhecheng

On Wed, Apr 04, 2018 at 10:53:22AM +0100, Stefan Hajnoczi wrote:
> On Wed, Mar 28, 2018 at 09:34:35PM +0800, linzhecheng wrote:
> > 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>
> 
> Michael or Paolo: Please merge for QEMU 2.12
> 
> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>


Reviewed-by: Michael S. Tsirkin <mst@redhat.com>

Will merge.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-04-04 14:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-28 13:34 [Qemu-devel] [PATCH v2] virtio-serial: fix heap-over-flow linzhecheng
2018-04-04  9:53 ` Stefan Hajnoczi
2018-04-04 14:22   ` Michael S. Tsirkin

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.