Skip to contentSkip to conversation

vt82c686: avoid out-of-bounds read

PATCH In review Paolo Bonzini 3 participants 7 messages Dec 10, 2014 – Jan 12, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vt82c686: avoid out-of-bounds read

superio_ioport_readb can read the 256th element of the array. Coverity reports an out-of-bounds write in superio_ioport_writeb, but it does not show the corresponding out-of-bounds read because it cannot prove that it can happen. Fix the root cause of the problem (zhanghailang's patch instead fixes the logic in superio_ioport_writeb).

---
 hw/isa/vt82c686.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/isa/vt82c686.c +1 -1
index e0c235c..a43e26d 100644
@@ -36,7 +36,7 @@
 
 typedef struct SuperIOConfig
 {
-    uint8_t config[0xff];
+    uint8_t config[0x100];
     uint8_t index;
     uint8_t data;
 } SuperIOConfig;
Signature · 1 line
1.8.3.1
#1 lore raw

Hi paolo,

Will this change affects the migration?
I noticed that there is a member 'SuperIOConfig superio_conf' in VT82C686BState.

vt82c686 seems only to be used in mips64el target, Do we support migration for mips target?

Thanks,
zhanghailiang

Quoted 26 lines · Paolo Bonzini

superio_ioport_readb can read the 256th element of the array. Coverity reports an out-of-bounds write in superio_ioport_writeb, but it does not show the corresponding out-of-bounds read because it cannot prove that it can happen. Fix the root cause of the problem (zhanghailang's patch instead fixes the logic in superio_ioport_writeb).

---
  hw/isa/vt82c686.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/isa/vt82c686.c +1 -1
index e0c235c..a43e26d 100644
@@ -36,7 +36,7 @@
 
  typedef struct SuperIOConfig
  {
-    uint8_t config[0xff];
+    uint8_t config[0x100];
      uint8_t index;
      uint8_t data;
  } SuperIOConfig;
#2 lore raw
Quoted 8 lines · zhanghailiang

Hi paolo,

Will this change affects the migration?
I noticed that there is a member 'SuperIOConfig superio_conf' in VT82C686BState.

vt82c686 seems only to be used in mips64el target, Do we support migration for mips target?

No, there is no VMState for superio_conf.

Paolo

Reviewed-by on v1 1/1
#3 lore raw
In reply to Paolo Bonzini
Quoted 18 lines · Paolo Bonzini

superio_ioport_readb can read the 256th element of the array. Coverity reports an out-of-bounds write in superio_ioport_writeb, but it does not show the corresponding out-of-bounds read because it cannot prove that it can happen. Fix the root cause of the problem (zhanghailang's patch instead fixes the logic in superio_ioport_writeb).

---
  hw/isa/vt82c686.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/isa/vt82c686.c +0 -0
index e0c235c..a43e26d 100644

hw/isa/vt82c686.c line 42

Quoted 8 lines
hw/isa/vt82c686.c +1 -1
@@ -36,7 +36,7 @@
 
  typedef struct SuperIOConfig
  {
-    uint8_t config[0xff];
+    uint8_t config[0x100];
      uint8_t index;
      uint8_t data;
  } SuperIOConfig;
#4 lore raw
In reply to Paolo Bonzini
Quoted 1 line · Paolo Bonzini

superio_ioport_readb can read the 256th element of the array.

Is there a legitimate reason for it to access byte index 256? What is the actual size of superio config memory, 256 or 257? I don't know, but somehow it looks like it should be 256. If that's the case, the fix is wrong and superio_ioport_readb() should be fixed instead...

Thanks,

/mjt

#5 lore raw
Quoted 2 lines · Michael Tokarev
Quoted 1 line
Quoted 1 line

superio_ioport_readb can read the 256th element of the array.

Is there a legitimate reason for it to access byte index 256?

The 256th element is byte index 255. :)

Quoted 1 line

What is the actual size of superio config memory, 256 or 257?

It's 256 and the array is sized conf[0xff].

Quoted 1 line

I don't know, but somehow it looks like it should be 256.

That's what the patch does. :)

Paolo

#6 lore raw
In reply to Paolo Bonzini
Quoted 6 lines · Paolo Bonzini

superio_ioport_readb can read the 256th element of the array. Coverity reports an out-of-bounds write in superio_ioport_writeb, but it does not show the corresponding out-of-bounds read because it cannot prove that it can happen. Fix the root cause of the problem (zhanghailang's patch instead fixes the logic in superio_ioport_writeb).

(Finally) applied to -trivial, thanks!

/mjt