virtio-serial: fix heap-over-flow
PATCH v2 1/1 virtio-serial: fix heap-over-flow
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.
hw/char/virtio-serial-bus.c +5 -2
@@ -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 ;
Signature · 1 line
2.12.2.windows.2
Quoted 7 lines · linzhecheng
Check device having the feature of
VIRTIO_CONSOLE_F_EMERG_WRITEbefore getconfig->emerg_wr. It is neccessary becausesizeof(virtio_console_config)is 8 byte if VirtIOSerial doesn't have the feature ofVIRTIO_CONSOLE_F_EMERG_WRITE(see virtio_serial_device_realize), read/writeemerg_wrwill lead to heap-over-flow.Signed-off-by linzhecheng <[email protected]>
Michael or Paolo: Please merge for QEMU 2.12
Michael S. Tsirkin
Reviewed-byQuoted 7 lines · Stefan Hajnoczi
Quoted 6 lines · linzhecheng
Check device having the feature of
VIRTIO_CONSOLE_F_EMERG_WRITEbefore getconfig->emerg_wr. It is neccessary becausesizeof(virtio_console_config)is 8 byte if VirtIOSerial doesn't have the feature ofVIRTIO_CONSOLE_F_EMERG_WRITE(see virtio_serial_device_realize), read/writeemerg_wrwill lead to heap-over-flow.
Quoted 5 lines
Quoted 1 line
Signed-off-by linzhecheng <[email protected]>Michael or Paolo: Please merge for QEMU 2.12
Reviewed-by Stefan Hajnoczi <[email protected]>
Will merge.