2007-08-26 19:48:12 +02:00
|
|
|
/*
|
|
|
|
* QEMU VMPort emulation
|
|
|
|
*
|
2011-12-02 10:30:41 +01:00
|
|
|
* Copyright (C) 2007 Hervé Poussineau
|
2007-08-26 19:48:12 +02:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
2020-03-12 17:54:16 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Guest code that interacts with this virtual device can be found
|
|
|
|
* in VMware open-vm-tools open-source project:
|
|
|
|
* https://github.com/vmware/open-vm-tools
|
|
|
|
*/
|
|
|
|
|
2016-01-26 19:17:17 +01:00
|
|
|
#include "qemu/osdep.h"
|
2013-02-05 17:06:20 +01:00
|
|
|
#include "hw/isa/isa.h"
|
2020-03-12 17:54:22 +01:00
|
|
|
#include "hw/i386/vmport.h"
|
2020-03-12 17:54:17 +01:00
|
|
|
#include "hw/qdev-properties.h"
|
2020-10-28 11:22:23 +01:00
|
|
|
#include "hw/boards.h"
|
2020-03-12 17:54:24 +01:00
|
|
|
#include "sysemu/sysemu.h"
|
2017-01-10 11:59:55 +01:00
|
|
|
#include "sysemu/hw_accel.h"
|
hw/i386/vmport: Allow QTest use without crashing
Trying libFuzzer on the vmport device, we get:
AddressSanitizer:DEADLYSIGNAL
=================================================================
==29476==ERROR: AddressSanitizer: SEGV on unknown address 0x000000008840 (pc 0x56448bec4d79 bp 0x7ffeec9741b0 sp 0x7ffeec9740e0 T0)
==29476==The signal is caused by a READ memory access.
#0 0x56448bec4d78 in vmport_ioport_read (qemu-fuzz-i386+0x1260d78)
#1 0x56448bb5f175 in memory_region_read_accessor (qemu-fuzz-i386+0xefb175)
#2 0x56448bb30c13 in access_with_adjusted_size (qemu-fuzz-i386+0xeccc13)
#3 0x56448bb2ea27 in memory_region_dispatch_read1 (qemu-fuzz-i386+0xecaa27)
#4 0x56448bb2e443 in memory_region_dispatch_read (qemu-fuzz-i386+0xeca443)
#5 0x56448b961ab1 in flatview_read_continue (qemu-fuzz-i386+0xcfdab1)
#6 0x56448b96336d in flatview_read (qemu-fuzz-i386+0xcff36d)
#7 0x56448b962ec4 in address_space_read_full (qemu-fuzz-i386+0xcfeec4)
This is easily reproducible using:
$ echo inb 0x5658 | qemu-system-i386 -M isapc,accel=qtest -qtest stdio
[I 1589796572.009763] OPENED
[R +0.008069] inb 0x5658
Segmentation fault (core dumped)
$ coredumpctl gdb -q
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x00005605b54d0f21 in vmport_ioport_read (opaque=0x5605b7531ce0, addr=0, size=4) at hw/i386/vmport.c:77
77 eax = env->regs[R_EAX];
(gdb) p cpu
$1 = (X86CPU *) 0x0
(gdb) bt
#0 0x00005605b54d0f21 in vmport_ioport_read (opaque=0x5605b7531ce0, addr=0, size=4) at hw/i386/vmport.c:77
#1 0x00005605b53db114 in memory_region_read_accessor (mr=0x5605b7531d80, addr=0, value=0x7ffc9d261a30, size=4, shift=0, mask=4294967295, attrs=...) at memory.c:434
#2 0x00005605b53db5d4 in access_with_adjusted_size (addr=0, value=0x7ffc9d261a30, size=1, access_size_min=4, access_size_max=4, access_fn=
0x5605b53db0d2 <memory_region_read_accessor>, mr=0x5605b7531d80, attrs=...) at memory.c:544
#3 0x00005605b53de156 in memory_region_dispatch_read1 (mr=0x5605b7531d80, addr=0, pval=0x7ffc9d261a30, size=1, attrs=...) at memory.c:1396
#4 0x00005605b53de228 in memory_region_dispatch_read (mr=0x5605b7531d80, addr=0, pval=0x7ffc9d261a30, op=MO_8, attrs=...) at memory.c:1424
#5 0x00005605b537c80a in flatview_read_continue (fv=0x5605b7650290, addr=22104, attrs=..., ptr=0x7ffc9d261b4b, len=1, addr1=0, l=1, mr=0x5605b7531d80) at exec.c:3200
#6 0x00005605b537c95d in flatview_read (fv=0x5605b7650290, addr=22104, attrs=..., buf=0x7ffc9d261b4b, len=1) at exec.c:3239
#7 0x00005605b537c9e6 in address_space_read_full (as=0x5605b5f74ac0 <address_space_io>, addr=22104, attrs=..., buf=0x7ffc9d261b4b, len=1) at exec.c:3252
#8 0x00005605b53d5a5d in address_space_read (len=1, buf=0x7ffc9d261b4b, attrs=..., addr=22104, as=0x5605b5f74ac0 <address_space_io>) at include/exec/memory.h:2401
#9 0x00005605b53d5a5d in cpu_inb (addr=22104) at ioport.c:88
X86CPU is NULL because QTest accelerator does not use CPU.
Fix by returning default values when QTest accelerator is used.
Reported-by: Clang AddressSanitizer
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2020-05-18 12:31:13 +02:00
|
|
|
#include "sysemu/qtest.h"
|
2017-12-21 22:11:03 +01:00
|
|
|
#include "qemu/log.h"
|
2017-12-15 04:43:55 +01:00
|
|
|
#include "trace.h"
|
2020-09-03 22:43:22 +02:00
|
|
|
#include "qom/object.h"
|
2008-08-19 21:13:06 +02:00
|
|
|
|
2007-08-26 19:48:12 +02:00
|
|
|
#define VMPORT_MAGIC 0x564D5868
|
|
|
|
|
2020-03-12 17:54:18 +01:00
|
|
|
/* Compatibility flags for migration */
|
2020-03-12 17:54:19 +01:00
|
|
|
#define VMPORT_COMPAT_READ_SET_EAX_BIT 0
|
|
|
|
#define VMPORT_COMPAT_SIGNAL_UNSUPPORTED_CMD_BIT 1
|
2020-03-12 17:54:21 +01:00
|
|
|
#define VMPORT_COMPAT_REPORT_VMX_TYPE_BIT 2
|
2020-03-12 17:54:24 +01:00
|
|
|
#define VMPORT_COMPAT_CMDS_V2_BIT 3
|
2020-03-12 17:54:19 +01:00
|
|
|
#define VMPORT_COMPAT_READ_SET_EAX \
|
2020-03-12 17:54:18 +01:00
|
|
|
(1 << VMPORT_COMPAT_READ_SET_EAX_BIT)
|
2020-03-12 17:54:19 +01:00
|
|
|
#define VMPORT_COMPAT_SIGNAL_UNSUPPORTED_CMD \
|
|
|
|
(1 << VMPORT_COMPAT_SIGNAL_UNSUPPORTED_CMD_BIT)
|
2020-03-12 17:54:21 +01:00
|
|
|
#define VMPORT_COMPAT_REPORT_VMX_TYPE \
|
|
|
|
(1 << VMPORT_COMPAT_REPORT_VMX_TYPE_BIT)
|
2020-03-12 17:54:24 +01:00
|
|
|
#define VMPORT_COMPAT_CMDS_V2 \
|
|
|
|
(1 << VMPORT_COMPAT_CMDS_V2_BIT)
|
2020-03-12 17:54:18 +01:00
|
|
|
|
2020-03-12 17:54:27 +01:00
|
|
|
/* vCPU features reported by CMD_GET_VCPU_INFO */
|
|
|
|
#define VCPU_INFO_SLC64_BIT 0
|
|
|
|
#define VCPU_INFO_SYNC_VTSCS_BIT 1
|
|
|
|
#define VCPU_INFO_HV_REPLAY_OK_BIT 2
|
|
|
|
#define VCPU_INFO_LEGACY_X2APIC_BIT 3
|
|
|
|
#define VCPU_INFO_RESERVED_BIT 31
|
|
|
|
|
2020-09-16 20:25:19 +02:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(VMPortState, VMPORT)
|
2013-04-27 22:18:54 +02:00
|
|
|
|
2020-09-03 22:43:22 +02:00
|
|
|
struct VMPortState {
|
2013-04-27 22:18:54 +02:00
|
|
|
ISADevice parent_obj;
|
|
|
|
|
2011-08-16 17:38:14 +02:00
|
|
|
MemoryRegion io;
|
2013-06-22 08:07:06 +02:00
|
|
|
VMPortReadFunc *func[VMPORT_ENTRIES];
|
2007-08-26 19:48:12 +02:00
|
|
|
void *opaque[VMPORT_ENTRIES];
|
2020-03-12 17:54:18 +01:00
|
|
|
|
2020-03-12 17:54:20 +01:00
|
|
|
uint32_t vmware_vmx_version;
|
2020-03-12 17:54:21 +01:00
|
|
|
uint8_t vmware_vmx_type;
|
2020-03-12 17:54:20 +01:00
|
|
|
|
2020-03-12 17:54:18 +01:00
|
|
|
uint32_t compat_flags;
|
2020-09-03 22:43:22 +02:00
|
|
|
};
|
2007-08-26 19:48:12 +02:00
|
|
|
|
2011-02-17 04:27:19 +01:00
|
|
|
static VMPortState *port_state;
|
2007-08-26 19:48:12 +02:00
|
|
|
|
2020-03-12 17:54:23 +01:00
|
|
|
void vmport_register(VMPortCommand command, VMPortReadFunc *func, void *opaque)
|
2007-08-26 19:48:12 +02:00
|
|
|
{
|
2020-03-12 17:54:23 +01:00
|
|
|
assert(command < VMPORT_ENTRIES);
|
2020-03-12 17:54:31 +01:00
|
|
|
assert(port_state);
|
|
|
|
|
2017-12-15 04:43:55 +01:00
|
|
|
trace_vmport_register(command, func, opaque);
|
2011-02-17 04:27:19 +01:00
|
|
|
port_state->func[command] = func;
|
|
|
|
port_state->opaque[command] = opaque;
|
2007-08-26 19:48:12 +02:00
|
|
|
}
|
|
|
|
|
2012-10-08 13:44:24 +02:00
|
|
|
static uint64_t vmport_ioport_read(void *opaque, hwaddr addr,
|
|
|
|
unsigned size)
|
2007-08-26 19:48:12 +02:00
|
|
|
{
|
|
|
|
VMPortState *s = opaque;
|
2013-05-27 05:17:50 +02:00
|
|
|
CPUState *cs = current_cpu;
|
|
|
|
X86CPU *cpu = X86_CPU(cs);
|
hw/i386/vmport: Allow QTest use without crashing
Trying libFuzzer on the vmport device, we get:
AddressSanitizer:DEADLYSIGNAL
=================================================================
==29476==ERROR: AddressSanitizer: SEGV on unknown address 0x000000008840 (pc 0x56448bec4d79 bp 0x7ffeec9741b0 sp 0x7ffeec9740e0 T0)
==29476==The signal is caused by a READ memory access.
#0 0x56448bec4d78 in vmport_ioport_read (qemu-fuzz-i386+0x1260d78)
#1 0x56448bb5f175 in memory_region_read_accessor (qemu-fuzz-i386+0xefb175)
#2 0x56448bb30c13 in access_with_adjusted_size (qemu-fuzz-i386+0xeccc13)
#3 0x56448bb2ea27 in memory_region_dispatch_read1 (qemu-fuzz-i386+0xecaa27)
#4 0x56448bb2e443 in memory_region_dispatch_read (qemu-fuzz-i386+0xeca443)
#5 0x56448b961ab1 in flatview_read_continue (qemu-fuzz-i386+0xcfdab1)
#6 0x56448b96336d in flatview_read (qemu-fuzz-i386+0xcff36d)
#7 0x56448b962ec4 in address_space_read_full (qemu-fuzz-i386+0xcfeec4)
This is easily reproducible using:
$ echo inb 0x5658 | qemu-system-i386 -M isapc,accel=qtest -qtest stdio
[I 1589796572.009763] OPENED
[R +0.008069] inb 0x5658
Segmentation fault (core dumped)
$ coredumpctl gdb -q
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x00005605b54d0f21 in vmport_ioport_read (opaque=0x5605b7531ce0, addr=0, size=4) at hw/i386/vmport.c:77
77 eax = env->regs[R_EAX];
(gdb) p cpu
$1 = (X86CPU *) 0x0
(gdb) bt
#0 0x00005605b54d0f21 in vmport_ioport_read (opaque=0x5605b7531ce0, addr=0, size=4) at hw/i386/vmport.c:77
#1 0x00005605b53db114 in memory_region_read_accessor (mr=0x5605b7531d80, addr=0, value=0x7ffc9d261a30, size=4, shift=0, mask=4294967295, attrs=...) at memory.c:434
#2 0x00005605b53db5d4 in access_with_adjusted_size (addr=0, value=0x7ffc9d261a30, size=1, access_size_min=4, access_size_max=4, access_fn=
0x5605b53db0d2 <memory_region_read_accessor>, mr=0x5605b7531d80, attrs=...) at memory.c:544
#3 0x00005605b53de156 in memory_region_dispatch_read1 (mr=0x5605b7531d80, addr=0, pval=0x7ffc9d261a30, size=1, attrs=...) at memory.c:1396
#4 0x00005605b53de228 in memory_region_dispatch_read (mr=0x5605b7531d80, addr=0, pval=0x7ffc9d261a30, op=MO_8, attrs=...) at memory.c:1424
#5 0x00005605b537c80a in flatview_read_continue (fv=0x5605b7650290, addr=22104, attrs=..., ptr=0x7ffc9d261b4b, len=1, addr1=0, l=1, mr=0x5605b7531d80) at exec.c:3200
#6 0x00005605b537c95d in flatview_read (fv=0x5605b7650290, addr=22104, attrs=..., buf=0x7ffc9d261b4b, len=1) at exec.c:3239
#7 0x00005605b537c9e6 in address_space_read_full (as=0x5605b5f74ac0 <address_space_io>, addr=22104, attrs=..., buf=0x7ffc9d261b4b, len=1) at exec.c:3252
#8 0x00005605b53d5a5d in address_space_read (len=1, buf=0x7ffc9d261b4b, attrs=..., addr=22104, as=0x5605b5f74ac0 <address_space_io>) at include/exec/memory.h:2401
#9 0x00005605b53d5a5d in cpu_inb (addr=22104) at ioport.c:88
X86CPU is NULL because QTest accelerator does not use CPU.
Fix by returning default values when QTest accelerator is used.
Reported-by: Clang AddressSanitizer
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2020-05-18 12:31:13 +02:00
|
|
|
CPUX86State *env;
|
2007-08-26 19:48:12 +02:00
|
|
|
unsigned char command;
|
2007-10-09 05:19:01 +02:00
|
|
|
uint32_t eax;
|
2007-08-26 19:48:12 +02:00
|
|
|
|
hw/i386/vmport: Allow QTest use without crashing
Trying libFuzzer on the vmport device, we get:
AddressSanitizer:DEADLYSIGNAL
=================================================================
==29476==ERROR: AddressSanitizer: SEGV on unknown address 0x000000008840 (pc 0x56448bec4d79 bp 0x7ffeec9741b0 sp 0x7ffeec9740e0 T0)
==29476==The signal is caused by a READ memory access.
#0 0x56448bec4d78 in vmport_ioport_read (qemu-fuzz-i386+0x1260d78)
#1 0x56448bb5f175 in memory_region_read_accessor (qemu-fuzz-i386+0xefb175)
#2 0x56448bb30c13 in access_with_adjusted_size (qemu-fuzz-i386+0xeccc13)
#3 0x56448bb2ea27 in memory_region_dispatch_read1 (qemu-fuzz-i386+0xecaa27)
#4 0x56448bb2e443 in memory_region_dispatch_read (qemu-fuzz-i386+0xeca443)
#5 0x56448b961ab1 in flatview_read_continue (qemu-fuzz-i386+0xcfdab1)
#6 0x56448b96336d in flatview_read (qemu-fuzz-i386+0xcff36d)
#7 0x56448b962ec4 in address_space_read_full (qemu-fuzz-i386+0xcfeec4)
This is easily reproducible using:
$ echo inb 0x5658 | qemu-system-i386 -M isapc,accel=qtest -qtest stdio
[I 1589796572.009763] OPENED
[R +0.008069] inb 0x5658
Segmentation fault (core dumped)
$ coredumpctl gdb -q
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x00005605b54d0f21 in vmport_ioport_read (opaque=0x5605b7531ce0, addr=0, size=4) at hw/i386/vmport.c:77
77 eax = env->regs[R_EAX];
(gdb) p cpu
$1 = (X86CPU *) 0x0
(gdb) bt
#0 0x00005605b54d0f21 in vmport_ioport_read (opaque=0x5605b7531ce0, addr=0, size=4) at hw/i386/vmport.c:77
#1 0x00005605b53db114 in memory_region_read_accessor (mr=0x5605b7531d80, addr=0, value=0x7ffc9d261a30, size=4, shift=0, mask=4294967295, attrs=...) at memory.c:434
#2 0x00005605b53db5d4 in access_with_adjusted_size (addr=0, value=0x7ffc9d261a30, size=1, access_size_min=4, access_size_max=4, access_fn=
0x5605b53db0d2 <memory_region_read_accessor>, mr=0x5605b7531d80, attrs=...) at memory.c:544
#3 0x00005605b53de156 in memory_region_dispatch_read1 (mr=0x5605b7531d80, addr=0, pval=0x7ffc9d261a30, size=1, attrs=...) at memory.c:1396
#4 0x00005605b53de228 in memory_region_dispatch_read (mr=0x5605b7531d80, addr=0, pval=0x7ffc9d261a30, op=MO_8, attrs=...) at memory.c:1424
#5 0x00005605b537c80a in flatview_read_continue (fv=0x5605b7650290, addr=22104, attrs=..., ptr=0x7ffc9d261b4b, len=1, addr1=0, l=1, mr=0x5605b7531d80) at exec.c:3200
#6 0x00005605b537c95d in flatview_read (fv=0x5605b7650290, addr=22104, attrs=..., buf=0x7ffc9d261b4b, len=1) at exec.c:3239
#7 0x00005605b537c9e6 in address_space_read_full (as=0x5605b5f74ac0 <address_space_io>, addr=22104, attrs=..., buf=0x7ffc9d261b4b, len=1) at exec.c:3252
#8 0x00005605b53d5a5d in address_space_read (len=1, buf=0x7ffc9d261b4b, attrs=..., addr=22104, as=0x5605b5f74ac0 <address_space_io>) at include/exec/memory.h:2401
#9 0x00005605b53d5a5d in cpu_inb (addr=22104) at ioport.c:88
X86CPU is NULL because QTest accelerator does not use CPU.
Fix by returning default values when QTest accelerator is used.
Reported-by: Clang AddressSanitizer
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2020-05-18 12:31:13 +02:00
|
|
|
if (qtest_enabled()) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
env = &cpu->env;
|
2013-05-27 05:17:50 +02:00
|
|
|
cpu_synchronize_state(cs);
|
2010-02-03 21:16:41 +01:00
|
|
|
|
2008-04-07 21:47:25 +02:00
|
|
|
eax = env->regs[R_EAX];
|
2017-10-17 18:44:24 +02:00
|
|
|
if (eax != VMPORT_MAGIC) {
|
2020-03-12 17:54:19 +01:00
|
|
|
goto err;
|
2017-10-17 18:44:24 +02:00
|
|
|
}
|
2007-08-26 19:48:12 +02:00
|
|
|
|
2008-04-07 21:47:25 +02:00
|
|
|
command = env->regs[R_ECX];
|
2017-12-15 04:43:55 +01:00
|
|
|
trace_vmport_command(command);
|
|
|
|
if (command >= VMPORT_ENTRIES || !s->func[command]) {
|
|
|
|
qemu_log_mask(LOG_UNIMP, "vmport: unknown command %x\n", command);
|
2020-03-12 17:54:19 +01:00
|
|
|
goto err;
|
2020-03-12 17:54:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
eax = s->func[command](s->opaque[command], addr);
|
2020-03-12 17:54:19 +01:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
err:
|
|
|
|
if (s->compat_flags & VMPORT_COMPAT_SIGNAL_UNSUPPORTED_CMD) {
|
|
|
|
eax = UINT32_MAX;
|
|
|
|
}
|
2020-03-12 17:54:18 +01:00
|
|
|
|
|
|
|
out:
|
|
|
|
/*
|
|
|
|
* The call above to cpu_synchronize_state() gets vCPU registers values
|
|
|
|
* to QEMU but also cause QEMU to write QEMU vCPU registers values to
|
|
|
|
* vCPU implementation (e.g. Accelerator such as KVM) just before
|
|
|
|
* resuming guest.
|
|
|
|
*
|
|
|
|
* Therefore, in order to make IOPort return value propagate to
|
|
|
|
* guest EAX, we need to explicitly update QEMU EAX register value.
|
|
|
|
*/
|
|
|
|
if (s->compat_flags & VMPORT_COMPAT_READ_SET_EAX) {
|
|
|
|
cpu->env.regs[R_EAX] = eax;
|
2007-08-26 19:48:12 +02:00
|
|
|
}
|
|
|
|
|
2020-03-12 17:54:18 +01:00
|
|
|
return eax;
|
2007-08-26 19:48:12 +02:00
|
|
|
}
|
|
|
|
|
2012-10-08 13:44:24 +02:00
|
|
|
static void vmport_ioport_write(void *opaque, hwaddr addr,
|
|
|
|
uint64_t val, unsigned size)
|
2008-07-28 20:58:02 +02:00
|
|
|
{
|
2013-05-27 05:17:50 +02:00
|
|
|
X86CPU *cpu = X86_CPU(current_cpu);
|
2008-07-28 20:58:02 +02:00
|
|
|
|
hw/i386/vmport: Allow QTest use without crashing
Trying libFuzzer on the vmport device, we get:
AddressSanitizer:DEADLYSIGNAL
=================================================================
==29476==ERROR: AddressSanitizer: SEGV on unknown address 0x000000008840 (pc 0x56448bec4d79 bp 0x7ffeec9741b0 sp 0x7ffeec9740e0 T0)
==29476==The signal is caused by a READ memory access.
#0 0x56448bec4d78 in vmport_ioport_read (qemu-fuzz-i386+0x1260d78)
#1 0x56448bb5f175 in memory_region_read_accessor (qemu-fuzz-i386+0xefb175)
#2 0x56448bb30c13 in access_with_adjusted_size (qemu-fuzz-i386+0xeccc13)
#3 0x56448bb2ea27 in memory_region_dispatch_read1 (qemu-fuzz-i386+0xecaa27)
#4 0x56448bb2e443 in memory_region_dispatch_read (qemu-fuzz-i386+0xeca443)
#5 0x56448b961ab1 in flatview_read_continue (qemu-fuzz-i386+0xcfdab1)
#6 0x56448b96336d in flatview_read (qemu-fuzz-i386+0xcff36d)
#7 0x56448b962ec4 in address_space_read_full (qemu-fuzz-i386+0xcfeec4)
This is easily reproducible using:
$ echo inb 0x5658 | qemu-system-i386 -M isapc,accel=qtest -qtest stdio
[I 1589796572.009763] OPENED
[R +0.008069] inb 0x5658
Segmentation fault (core dumped)
$ coredumpctl gdb -q
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x00005605b54d0f21 in vmport_ioport_read (opaque=0x5605b7531ce0, addr=0, size=4) at hw/i386/vmport.c:77
77 eax = env->regs[R_EAX];
(gdb) p cpu
$1 = (X86CPU *) 0x0
(gdb) bt
#0 0x00005605b54d0f21 in vmport_ioport_read (opaque=0x5605b7531ce0, addr=0, size=4) at hw/i386/vmport.c:77
#1 0x00005605b53db114 in memory_region_read_accessor (mr=0x5605b7531d80, addr=0, value=0x7ffc9d261a30, size=4, shift=0, mask=4294967295, attrs=...) at memory.c:434
#2 0x00005605b53db5d4 in access_with_adjusted_size (addr=0, value=0x7ffc9d261a30, size=1, access_size_min=4, access_size_max=4, access_fn=
0x5605b53db0d2 <memory_region_read_accessor>, mr=0x5605b7531d80, attrs=...) at memory.c:544
#3 0x00005605b53de156 in memory_region_dispatch_read1 (mr=0x5605b7531d80, addr=0, pval=0x7ffc9d261a30, size=1, attrs=...) at memory.c:1396
#4 0x00005605b53de228 in memory_region_dispatch_read (mr=0x5605b7531d80, addr=0, pval=0x7ffc9d261a30, op=MO_8, attrs=...) at memory.c:1424
#5 0x00005605b537c80a in flatview_read_continue (fv=0x5605b7650290, addr=22104, attrs=..., ptr=0x7ffc9d261b4b, len=1, addr1=0, l=1, mr=0x5605b7531d80) at exec.c:3200
#6 0x00005605b537c95d in flatview_read (fv=0x5605b7650290, addr=22104, attrs=..., buf=0x7ffc9d261b4b, len=1) at exec.c:3239
#7 0x00005605b537c9e6 in address_space_read_full (as=0x5605b5f74ac0 <address_space_io>, addr=22104, attrs=..., buf=0x7ffc9d261b4b, len=1) at exec.c:3252
#8 0x00005605b53d5a5d in address_space_read (len=1, buf=0x7ffc9d261b4b, attrs=..., addr=22104, as=0x5605b5f74ac0 <address_space_io>) at include/exec/memory.h:2401
#9 0x00005605b53d5a5d in cpu_inb (addr=22104) at ioport.c:88
X86CPU is NULL because QTest accelerator does not use CPU.
Fix by returning default values when QTest accelerator is used.
Reported-by: Clang AddressSanitizer
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2020-05-18 12:31:13 +02:00
|
|
|
if (qtest_enabled()) {
|
|
|
|
return;
|
|
|
|
}
|
2013-05-27 05:17:50 +02:00
|
|
|
cpu->env.regs[R_EAX] = vmport_ioport_read(opaque, addr, 4);
|
2008-07-28 20:58:02 +02:00
|
|
|
}
|
|
|
|
|
2007-08-26 19:48:12 +02:00
|
|
|
static uint32_t vmport_cmd_get_version(void *opaque, uint32_t addr)
|
|
|
|
{
|
2013-05-27 05:17:50 +02:00
|
|
|
X86CPU *cpu = X86_CPU(current_cpu);
|
|
|
|
|
hw/i386/vmport: Allow QTest use without crashing
Trying libFuzzer on the vmport device, we get:
AddressSanitizer:DEADLYSIGNAL
=================================================================
==29476==ERROR: AddressSanitizer: SEGV on unknown address 0x000000008840 (pc 0x56448bec4d79 bp 0x7ffeec9741b0 sp 0x7ffeec9740e0 T0)
==29476==The signal is caused by a READ memory access.
#0 0x56448bec4d78 in vmport_ioport_read (qemu-fuzz-i386+0x1260d78)
#1 0x56448bb5f175 in memory_region_read_accessor (qemu-fuzz-i386+0xefb175)
#2 0x56448bb30c13 in access_with_adjusted_size (qemu-fuzz-i386+0xeccc13)
#3 0x56448bb2ea27 in memory_region_dispatch_read1 (qemu-fuzz-i386+0xecaa27)
#4 0x56448bb2e443 in memory_region_dispatch_read (qemu-fuzz-i386+0xeca443)
#5 0x56448b961ab1 in flatview_read_continue (qemu-fuzz-i386+0xcfdab1)
#6 0x56448b96336d in flatview_read (qemu-fuzz-i386+0xcff36d)
#7 0x56448b962ec4 in address_space_read_full (qemu-fuzz-i386+0xcfeec4)
This is easily reproducible using:
$ echo inb 0x5658 | qemu-system-i386 -M isapc,accel=qtest -qtest stdio
[I 1589796572.009763] OPENED
[R +0.008069] inb 0x5658
Segmentation fault (core dumped)
$ coredumpctl gdb -q
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x00005605b54d0f21 in vmport_ioport_read (opaque=0x5605b7531ce0, addr=0, size=4) at hw/i386/vmport.c:77
77 eax = env->regs[R_EAX];
(gdb) p cpu
$1 = (X86CPU *) 0x0
(gdb) bt
#0 0x00005605b54d0f21 in vmport_ioport_read (opaque=0x5605b7531ce0, addr=0, size=4) at hw/i386/vmport.c:77
#1 0x00005605b53db114 in memory_region_read_accessor (mr=0x5605b7531d80, addr=0, value=0x7ffc9d261a30, size=4, shift=0, mask=4294967295, attrs=...) at memory.c:434
#2 0x00005605b53db5d4 in access_with_adjusted_size (addr=0, value=0x7ffc9d261a30, size=1, access_size_min=4, access_size_max=4, access_fn=
0x5605b53db0d2 <memory_region_read_accessor>, mr=0x5605b7531d80, attrs=...) at memory.c:544
#3 0x00005605b53de156 in memory_region_dispatch_read1 (mr=0x5605b7531d80, addr=0, pval=0x7ffc9d261a30, size=1, attrs=...) at memory.c:1396
#4 0x00005605b53de228 in memory_region_dispatch_read (mr=0x5605b7531d80, addr=0, pval=0x7ffc9d261a30, op=MO_8, attrs=...) at memory.c:1424
#5 0x00005605b537c80a in flatview_read_continue (fv=0x5605b7650290, addr=22104, attrs=..., ptr=0x7ffc9d261b4b, len=1, addr1=0, l=1, mr=0x5605b7531d80) at exec.c:3200
#6 0x00005605b537c95d in flatview_read (fv=0x5605b7650290, addr=22104, attrs=..., buf=0x7ffc9d261b4b, len=1) at exec.c:3239
#7 0x00005605b537c9e6 in address_space_read_full (as=0x5605b5f74ac0 <address_space_io>, addr=22104, attrs=..., buf=0x7ffc9d261b4b, len=1) at exec.c:3252
#8 0x00005605b53d5a5d in address_space_read (len=1, buf=0x7ffc9d261b4b, attrs=..., addr=22104, as=0x5605b5f74ac0 <address_space_io>) at include/exec/memory.h:2401
#9 0x00005605b53d5a5d in cpu_inb (addr=22104) at ioport.c:88
X86CPU is NULL because QTest accelerator does not use CPU.
Fix by returning default values when QTest accelerator is used.
Reported-by: Clang AddressSanitizer
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2020-05-18 12:31:13 +02:00
|
|
|
if (qtest_enabled()) {
|
|
|
|
return -1;
|
|
|
|
}
|
2013-05-27 05:17:50 +02:00
|
|
|
cpu->env.regs[R_EBX] = VMPORT_MAGIC;
|
2020-03-12 17:54:21 +01:00
|
|
|
if (port_state->compat_flags & VMPORT_COMPAT_REPORT_VMX_TYPE) {
|
|
|
|
cpu->env.regs[R_ECX] = port_state->vmware_vmx_type;
|
|
|
|
}
|
2020-03-12 17:54:20 +01:00
|
|
|
return port_state->vmware_vmx_version;
|
2007-08-26 19:48:12 +02:00
|
|
|
}
|
|
|
|
|
2020-03-12 17:54:24 +01:00
|
|
|
static uint32_t vmport_cmd_get_bios_uuid(void *opaque, uint32_t addr)
|
|
|
|
{
|
|
|
|
X86CPU *cpu = X86_CPU(current_cpu);
|
|
|
|
uint32_t *uuid_parts = (uint32_t *)(qemu_uuid.data);
|
|
|
|
|
|
|
|
cpu->env.regs[R_EAX] = le32_to_cpu(uuid_parts[0]);
|
|
|
|
cpu->env.regs[R_EBX] = le32_to_cpu(uuid_parts[1]);
|
|
|
|
cpu->env.regs[R_ECX] = le32_to_cpu(uuid_parts[2]);
|
|
|
|
cpu->env.regs[R_EDX] = le32_to_cpu(uuid_parts[3]);
|
|
|
|
return cpu->env.regs[R_EAX];
|
|
|
|
}
|
|
|
|
|
2007-08-26 19:48:12 +02:00
|
|
|
static uint32_t vmport_cmd_ram_size(void *opaque, uint32_t addr)
|
|
|
|
{
|
2013-05-27 05:17:50 +02:00
|
|
|
X86CPU *cpu = X86_CPU(current_cpu);
|
|
|
|
|
hw/i386/vmport: Allow QTest use without crashing
Trying libFuzzer on the vmport device, we get:
AddressSanitizer:DEADLYSIGNAL
=================================================================
==29476==ERROR: AddressSanitizer: SEGV on unknown address 0x000000008840 (pc 0x56448bec4d79 bp 0x7ffeec9741b0 sp 0x7ffeec9740e0 T0)
==29476==The signal is caused by a READ memory access.
#0 0x56448bec4d78 in vmport_ioport_read (qemu-fuzz-i386+0x1260d78)
#1 0x56448bb5f175 in memory_region_read_accessor (qemu-fuzz-i386+0xefb175)
#2 0x56448bb30c13 in access_with_adjusted_size (qemu-fuzz-i386+0xeccc13)
#3 0x56448bb2ea27 in memory_region_dispatch_read1 (qemu-fuzz-i386+0xecaa27)
#4 0x56448bb2e443 in memory_region_dispatch_read (qemu-fuzz-i386+0xeca443)
#5 0x56448b961ab1 in flatview_read_continue (qemu-fuzz-i386+0xcfdab1)
#6 0x56448b96336d in flatview_read (qemu-fuzz-i386+0xcff36d)
#7 0x56448b962ec4 in address_space_read_full (qemu-fuzz-i386+0xcfeec4)
This is easily reproducible using:
$ echo inb 0x5658 | qemu-system-i386 -M isapc,accel=qtest -qtest stdio
[I 1589796572.009763] OPENED
[R +0.008069] inb 0x5658
Segmentation fault (core dumped)
$ coredumpctl gdb -q
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x00005605b54d0f21 in vmport_ioport_read (opaque=0x5605b7531ce0, addr=0, size=4) at hw/i386/vmport.c:77
77 eax = env->regs[R_EAX];
(gdb) p cpu
$1 = (X86CPU *) 0x0
(gdb) bt
#0 0x00005605b54d0f21 in vmport_ioport_read (opaque=0x5605b7531ce0, addr=0, size=4) at hw/i386/vmport.c:77
#1 0x00005605b53db114 in memory_region_read_accessor (mr=0x5605b7531d80, addr=0, value=0x7ffc9d261a30, size=4, shift=0, mask=4294967295, attrs=...) at memory.c:434
#2 0x00005605b53db5d4 in access_with_adjusted_size (addr=0, value=0x7ffc9d261a30, size=1, access_size_min=4, access_size_max=4, access_fn=
0x5605b53db0d2 <memory_region_read_accessor>, mr=0x5605b7531d80, attrs=...) at memory.c:544
#3 0x00005605b53de156 in memory_region_dispatch_read1 (mr=0x5605b7531d80, addr=0, pval=0x7ffc9d261a30, size=1, attrs=...) at memory.c:1396
#4 0x00005605b53de228 in memory_region_dispatch_read (mr=0x5605b7531d80, addr=0, pval=0x7ffc9d261a30, op=MO_8, attrs=...) at memory.c:1424
#5 0x00005605b537c80a in flatview_read_continue (fv=0x5605b7650290, addr=22104, attrs=..., ptr=0x7ffc9d261b4b, len=1, addr1=0, l=1, mr=0x5605b7531d80) at exec.c:3200
#6 0x00005605b537c95d in flatview_read (fv=0x5605b7650290, addr=22104, attrs=..., buf=0x7ffc9d261b4b, len=1) at exec.c:3239
#7 0x00005605b537c9e6 in address_space_read_full (as=0x5605b5f74ac0 <address_space_io>, addr=22104, attrs=..., buf=0x7ffc9d261b4b, len=1) at exec.c:3252
#8 0x00005605b53d5a5d in address_space_read (len=1, buf=0x7ffc9d261b4b, attrs=..., addr=22104, as=0x5605b5f74ac0 <address_space_io>) at include/exec/memory.h:2401
#9 0x00005605b53d5a5d in cpu_inb (addr=22104) at ioport.c:88
X86CPU is NULL because QTest accelerator does not use CPU.
Fix by returning default values when QTest accelerator is used.
Reported-by: Clang AddressSanitizer
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2020-05-18 12:31:13 +02:00
|
|
|
if (qtest_enabled()) {
|
|
|
|
return -1;
|
|
|
|
}
|
2013-05-27 05:17:50 +02:00
|
|
|
cpu->env.regs[R_EBX] = 0x1177;
|
2020-10-28 11:22:23 +01:00
|
|
|
return current_machine->ram_size;
|
2007-08-26 19:48:12 +02:00
|
|
|
}
|
|
|
|
|
2020-03-12 17:54:30 +01:00
|
|
|
static uint32_t vmport_cmd_get_hz(void *opaque, uint32_t addr)
|
|
|
|
{
|
|
|
|
X86CPU *cpu = X86_CPU(current_cpu);
|
|
|
|
|
|
|
|
if (cpu->env.tsc_khz && cpu->env.apic_bus_freq) {
|
|
|
|
uint64_t tsc_freq = (uint64_t)cpu->env.tsc_khz * 1000;
|
|
|
|
|
|
|
|
cpu->env.regs[R_ECX] = cpu->env.apic_bus_freq;
|
|
|
|
cpu->env.regs[R_EBX] = (uint32_t)(tsc_freq >> 32);
|
|
|
|
cpu->env.regs[R_EAX] = (uint32_t)tsc_freq;
|
|
|
|
} else {
|
|
|
|
/* Signal cmd as not supported */
|
|
|
|
cpu->env.regs[R_EBX] = UINT32_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cpu->env.regs[R_EAX];
|
|
|
|
}
|
|
|
|
|
2020-03-12 17:54:27 +01:00
|
|
|
static uint32_t vmport_cmd_get_vcpu_info(void *opaque, uint32_t addr)
|
|
|
|
{
|
2020-03-12 17:54:28 +01:00
|
|
|
X86CPU *cpu = X86_CPU(current_cpu);
|
|
|
|
uint32_t ret = 0;
|
|
|
|
|
|
|
|
if (cpu->env.features[FEAT_1_ECX] & CPUID_EXT_X2APIC) {
|
|
|
|
ret |= 1 << VCPU_INFO_LEGACY_X2APIC_BIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2020-03-12 17:54:27 +01:00
|
|
|
}
|
|
|
|
|
2011-08-16 17:38:14 +02:00
|
|
|
static const MemoryRegionOps vmport_ops = {
|
2012-10-08 13:44:24 +02:00
|
|
|
.read = vmport_ioport_read,
|
|
|
|
.write = vmport_ioport_write,
|
|
|
|
.impl = {
|
|
|
|
.min_access_size = 4,
|
|
|
|
.max_access_size = 4,
|
|
|
|
},
|
|
|
|
.endianness = DEVICE_LITTLE_ENDIAN,
|
2011-08-16 17:38:14 +02:00
|
|
|
};
|
|
|
|
|
2012-11-25 02:37:14 +01:00
|
|
|
static void vmport_realizefn(DeviceState *dev, Error **errp)
|
2007-08-26 19:48:12 +02:00
|
|
|
{
|
2012-11-25 02:37:14 +01:00
|
|
|
ISADevice *isadev = ISA_DEVICE(dev);
|
2013-04-27 22:18:54 +02:00
|
|
|
VMPortState *s = VMPORT(dev);
|
2007-08-26 19:48:12 +02:00
|
|
|
|
2013-06-07 03:25:08 +02:00
|
|
|
memory_region_init_io(&s->io, OBJECT(s), &vmport_ops, s, "vmport", 1);
|
2012-11-25 02:37:14 +01:00
|
|
|
isa_register_ioport(isadev, &s->io, 0x5658);
|
2011-08-16 17:38:14 +02:00
|
|
|
|
2011-02-17 04:27:19 +01:00
|
|
|
port_state = s;
|
2020-03-12 17:54:24 +01:00
|
|
|
|
2007-08-26 19:48:12 +02:00
|
|
|
/* Register some generic port commands */
|
2008-04-07 21:47:25 +02:00
|
|
|
vmport_register(VMPORT_CMD_GETVERSION, vmport_cmd_get_version, NULL);
|
|
|
|
vmport_register(VMPORT_CMD_GETRAMSIZE, vmport_cmd_ram_size, NULL);
|
2020-03-12 17:54:24 +01:00
|
|
|
if (s->compat_flags & VMPORT_COMPAT_CMDS_V2) {
|
|
|
|
vmport_register(VMPORT_CMD_GETBIOSUUID, vmport_cmd_get_bios_uuid, NULL);
|
2020-03-12 17:54:30 +01:00
|
|
|
vmport_register(VMPORT_CMD_GETHZ, vmport_cmd_get_hz, NULL);
|
2020-03-12 17:54:27 +01:00
|
|
|
vmport_register(VMPORT_CMD_GET_VCPU_INFO, vmport_cmd_get_vcpu_info,
|
|
|
|
NULL);
|
2020-03-12 17:54:24 +01:00
|
|
|
}
|
2007-08-26 19:48:12 +02:00
|
|
|
}
|
2011-02-05 15:34:41 +01:00
|
|
|
|
2020-03-12 17:54:17 +01:00
|
|
|
static Property vmport_properties[] = {
|
2020-03-12 17:54:18 +01:00
|
|
|
/* Used to enforce compatibility for migration */
|
|
|
|
DEFINE_PROP_BIT("x-read-set-eax", VMPortState, compat_flags,
|
|
|
|
VMPORT_COMPAT_READ_SET_EAX_BIT, true),
|
2020-03-12 17:54:19 +01:00
|
|
|
DEFINE_PROP_BIT("x-signal-unsupported-cmd", VMPortState, compat_flags,
|
|
|
|
VMPORT_COMPAT_SIGNAL_UNSUPPORTED_CMD_BIT, true),
|
2020-03-12 17:54:21 +01:00
|
|
|
DEFINE_PROP_BIT("x-report-vmx-type", VMPortState, compat_flags,
|
|
|
|
VMPORT_COMPAT_REPORT_VMX_TYPE_BIT, true),
|
2020-03-12 17:54:24 +01:00
|
|
|
DEFINE_PROP_BIT("x-cmds-v2", VMPortState, compat_flags,
|
|
|
|
VMPORT_COMPAT_CMDS_V2_BIT, true),
|
2020-03-12 17:54:20 +01:00
|
|
|
|
|
|
|
/* Default value taken from open-vm-tools code VERSION_MAGIC definition */
|
|
|
|
DEFINE_PROP_UINT32("vmware-vmx-version", VMPortState,
|
|
|
|
vmware_vmx_version, 6),
|
2020-03-12 17:54:21 +01:00
|
|
|
/*
|
|
|
|
* Value determines which VMware product type host report itself to guest.
|
|
|
|
*
|
|
|
|
* Most guests are fine with exposing host as VMware ESX server.
|
|
|
|
* Some legacy/proprietary guests hard-code a given type.
|
|
|
|
*
|
|
|
|
* For a complete list of values, refer to enum VMXType at open-vm-tools
|
|
|
|
* project (Defined at lib/include/vm_vmx_type.h).
|
|
|
|
*
|
|
|
|
* Reasonable options:
|
|
|
|
* 0 - Unset
|
|
|
|
* 1 - VMware Express (deprecated)
|
|
|
|
* 2 - VMware ESX Server
|
|
|
|
* 3 - VMware Server (Deprecated)
|
|
|
|
* 4 - VMware Workstation
|
|
|
|
* 5 - ACE 1.x (Deprecated)
|
|
|
|
*/
|
|
|
|
DEFINE_PROP_UINT8("vmware-vmx-type", VMPortState, vmware_vmx_type, 2),
|
2020-03-12 17:54:20 +01:00
|
|
|
|
2020-03-12 17:54:17 +01:00
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
2011-12-04 18:52:49 +01:00
|
|
|
static void vmport_class_initfn(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-11-25 02:37:14 +01:00
|
|
|
|
|
|
|
dc->realize = vmport_realizefn;
|
2013-11-28 17:27:02 +01:00
|
|
|
/* Reason: realize sets global port_state */
|
2017-05-03 22:35:44 +02:00
|
|
|
dc->user_creatable = false;
|
2020-03-12 17:54:17 +01:00
|
|
|
device_class_set_props(dc, vmport_properties);
|
2011-12-04 18:52:49 +01:00
|
|
|
}
|
|
|
|
|
2013-01-10 16:19:07 +01:00
|
|
|
static const TypeInfo vmport_info = {
|
2013-04-27 22:18:54 +02:00
|
|
|
.name = TYPE_VMPORT,
|
2011-12-08 04:34:16 +01:00
|
|
|
.parent = TYPE_ISA_DEVICE,
|
|
|
|
.instance_size = sizeof(VMPortState),
|
|
|
|
.class_init = vmport_class_initfn,
|
2011-02-05 15:34:41 +01:00
|
|
|
};
|
|
|
|
|
2012-02-09 15:20:55 +01:00
|
|
|
static void vmport_register_types(void)
|
2011-02-05 15:34:41 +01:00
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
type_register_static(&vmport_info);
|
2011-02-05 15:34:41 +01:00
|
|
|
}
|
2012-02-09 15:20:55 +01:00
|
|
|
|
|
|
|
type_init(vmport_register_types)
|