There is still a bit of an issue after the last set of changes made by
mlarkin@.  The changed get_input_data() interface takes a pointer to a
uint32_t as an argument, but only modifies the bytes that correspond
to the access size.  That means that if we read the value into an
uint32_t that is allocated on the stack, because if the access size is
less than 4 bytes, we end up with stack garbage in the variable.  This
is a problem in the mc146818 emulation code.

The result is that seabios (sometimes) detects the wrong memory size
and subsequently triggers the following kernel printf:

  unknown memory type 1 for GPA 0x207bffd0

Not sure what happens with the VM at that point.  It seems to be
hanging.

Diff below fixes the issue.  As far as I can see the i8253 and i8259
emulation code isn't affected as the uint32_t stack variable gets
converted into a uint8_t before being used.  But perhaps we should
initialize the stack variables there as well to prevent further
accidents.

ok?


Index: mc146818.c
===================================================================
RCS file: /cvs/src/usr.sbin/vmd/mc146818.c,v
retrieving revision 1.10
diff -u -p -r1.10 mc146818.c
--- mc146818.c  25 Mar 2017 22:36:53 -0000      1.10
+++ mc146818.c  26 Mar 2017 14:26:10 -0000
@@ -249,7 +249,7 @@ vcpu_exit_mc146818(struct vm_run_params 
        union vm_exit *vei = vrp->vrp_exit;
        uint16_t port = vei->vei.vei_port;
        uint8_t dir = vei->vei.vei_dir;
-       uint32_t data;
+       uint32_t data = 0;
 
        get_input_data(vei, &data);
 

Reply via email to