hw/mcf5206: Fix buffer overflow for MBAR read / write
PATCH 1/1 hw/mcf5206: Fix buffer overflow for MBAR read / write
Report from smatch:
mcf5206.c:384 m5206_mbar_readb(7) error: buffer overflow 'm5206_mbar_width' 128 <= 128 mcf5206.c:403 m5206_mbar_readw(8) error: buffer overflow 'm5206_mbar_width' 128 <= 128 mcf5206.c:427 m5206_mbar_readl(8) error: buffer overflow 'm5206_mbar_width' 128 <= 128 mcf5206.c:451 m5206_mbar_writeb(9) error: buffer overflow 'm5206_mbar_width' 128 <= 128 mcf5206.c:475 m5206_mbar_writew(9) error: buffer overflow 'm5206_mbar_width' 128 <= 128 mcf5206.c:503 m5206_mbar_writel(9) error: buffer overflow 'm5206_mbar_width' 128 <= 128
m5206_mbar_width has 0x80 elements and supports 0 <= offset < 0x200.
--- hw/mcf5206.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
hw/mcf5206.c +6 -6
@@ -378,7 +378,7 @@ static uint32_t m5206_mbar_readb(void *opaque, target_phys_addr_t offset) {m5206_mbar_state *s = (m5206_mbar_state *)opaque; offset &=0x3ff ; -if (offset >0x200 ) { +if (offset >=0x200 ) {hw_error ("Bad MBAR read offset 0x%x" , (int )offset); }if (m5206_mbar_width[offset >>2 ] >1 ) {
@@ -397,7 +397,7 @@ static uint32_t m5206_mbar_readw(void *opaque, target_phys_addr_t offset)m5206_mbar_state *s = (m5206_mbar_state *)opaque;int width; offset &=0x3ff ; -if (offset >0x200 ) { +if (offset >=0x200 ) {hw_error ("Bad MBAR read offset 0x%x" , (int )offset); } width = m5206_mbar_width[offset >>2 ];
@@ -421,7 +421,7 @@ static uint32_t m5206_mbar_readl(void *opaque, target_phys_addr_t offset)m5206_mbar_state *s = (m5206_mbar_state *)opaque;int width; offset &=0x3ff ; -if (offset >0x200 ) { +if (offset >=0x200 ) {hw_error ("Bad MBAR read offset 0x%x" , (int )offset); } width = m5206_mbar_width[offset >>2 ];
@@ -445,7 +445,7 @@ static void m5206_mbar_writeb(void *opaque, target_phys_addr_t offset,m5206_mbar_state *s = (m5206_mbar_state *)opaque;int width; offset &=0x3ff ; -if (offset >0x200 ) { +if (offset >=0x200 ) {hw_error ("Bad MBAR write offset 0x%x" , (int )offset); } width = m5206_mbar_width[offset >>2 ];
@@ -469,7 +469,7 @@ static void m5206_mbar_writew(void *opaque, target_phys_addr_t offset,m5206_mbar_state *s = (m5206_mbar_state *)opaque;int width; offset &=0x3ff ; -if (offset >0x200 ) { +if (offset >=0x200 ) {hw_error ("Bad MBAR write offset 0x%x" , (int )offset); } width = m5206_mbar_width[offset >>2 ];
@@ -497,7 +497,7 @@ static void m5206_mbar_writel(void *opaque, target_phys_addr_t offset,m5206_mbar_state *s = (m5206_mbar_state *)opaque;int width; offset &=0x3ff ; -if (offset >0x200 ) { +if (offset >=0x200 ) {hw_error ("Bad MBAR write offset 0x%x" , (int )offset); } width = m5206_mbar_width[offset >>2 ];
Signature · 1 line
1.7.10
Quoted 9 lines · Stefan Weil
Report from smatch:
mcf5206.c:384
m5206_mbar_readb(7)error: buffer overflow 'm5206_mbar_width' 128 <= 128 mcf5206.c:403m5206_mbar_readw(8)error: buffer overflow 'm5206_mbar_width' 128 <= 128 mcf5206.c:427m5206_mbar_readl(8)error: buffer overflow 'm5206_mbar_width' 128 <= 128 mcf5206.c:451m5206_mbar_writeb(9)error: buffer overflow 'm5206_mbar_width' 128 <= 128 mcf5206.c:475m5206_mbar_writew(9)error: buffer overflow 'm5206_mbar_width' 128 <= 128 mcf5206.c:503m5206_mbar_writel(9)error: buffer overflow 'm5206_mbar_width' 128 <= 128
Quoted 3 lines
m5206_mbar_widthhas0x80elements and supports 0 <= offset <0x200.Signed-off-by Stefan Weil <[email protected]>
Checked against the data sheet -- last documented register is at offset $1F0, so correcting the offset check rather than the array length is the correct fix.
-- PMM
Am 04.09.2012 19:57, schrieb Peter Maydell:
Quoted 12 lines · Stefan Weil
Quoted 11 lines
Report from smatch:
mcf5206.c:384
m5206_mbar_readb(7)error: buffer overflow 'm5206_mbar_width' 128 <= 128 mcf5206.c:403m5206_mbar_readw(8)error: buffer overflow 'm5206_mbar_width' 128 <= 128 mcf5206.c:427m5206_mbar_readl(8)error: buffer overflow 'm5206_mbar_width' 128 <= 128 mcf5206.c:451m5206_mbar_writeb(9)error: buffer overflow 'm5206_mbar_width' 128 <= 128 mcf5206.c:475m5206_mbar_writew(9)error: buffer overflow 'm5206_mbar_width' 128 <= 128 mcf5206.c:503m5206_mbar_writel(9)error: buffer overflow 'm5206_mbar_width' 128 <= 128
m5206_mbar_widthhas0x80elements and supports 0 <= offset <0x200.
Quoted 8 lines
Quoted 1 line
Signed-off-by Stefan Weil <[email protected]>Checked against the data sheet -- last documented register is at offset $1F0, so correcting the offset check rather than the array length is the correct fix.
Reviewed-by Peter Maydell <[email protected]>-- PMM
Then m5206_mbar_width should be shortened to 124 elements (0x1f0 / 4) _and_ the offset check needs a correction.
-- sw
Am 04.09.2012 20:12, schrieb Stefan Weil:
Quoted 18 lines
Am 04.09.2012 19:57, schrieb Peter Maydell:
Quoted 17 lines · Stefan Weil
Quoted 9 lines
Report from smatch:
mcf5206.c:384
m5206_mbar_readb(7)error: buffer overflow 'm5206_mbar_width' 128 <= 128 mcf5206.c:403m5206_mbar_readw(8)error: buffer overflow 'm5206_mbar_width' 128 <= 128 mcf5206.c:427m5206_mbar_readl(8)error: buffer overflow 'm5206_mbar_width' 128 <= 128 mcf5206.c:451m5206_mbar_writeb(9)error: buffer overflow 'm5206_mbar_width' 128 <= 128 mcf5206.c:475m5206_mbar_writew(9)error: buffer overflow 'm5206_mbar_width' 128 <= 128 mcf5206.c:503m5206_mbar_writel(9)error: buffer overflow 'm5206_mbar_width' 128 <= 128Quoted 3 lines
m5206_mbar_widthhas0x80elements and supports 0 <= offset <0x200.Signed-off-by Stefan Weil <[email protected]>Checked against the data sheet -- last documented register is at offset $1F0, so correcting the offset check rather than the array length is the correct fix.
Quoted 8 lines
Quoted 3 lines
Reviewed-by Peter Maydell <[email protected]>-- PMM
Then
m5206_mbar_widthshould be shortened to 124 elements (0x1f0/ 4) _and_ the offset check needs a correction.-- sw
Sorry, 125 elements, of course. Or are there undocumented registers at 0x1f4, 0x1f8 and 0x1fc?
- sw
Quoted 8 lines · Stefan Weil
Am 04.09.2012 20:12, schrieb Stefan Weil:
Quoted 7 lines
Am 04.09.2012 19:57, schrieb Peter Maydell:
Quoted 3 lines
Checked against the data sheet -- last documented register is at offset $1F0, so correcting the offset check rather than the array length is the correct fix.
Then
m5206_mbar_widthshould be shortened to 124 elements (0x1f0/ 4) _and_ the offset check needs a correction.
Why bother? The relevant offsets will hit the hw_error() cases in m5206_mbar_read() and m5206_mbar_write() anyway, the same as for the other cases where there are "holes" in the register space. The only reason we're doing these checks here is to avoid overrunning the width array...
Quoted 2 lines
Sorry, 125 elements, of course. Or are there undocumented registers at
0x1f4,0x1f8and0x1fc?
If there were, I wouldn't know, because they aren't documented :-)
-- PMM
Aurelien Jarno
AppliedQuoted 77 lines · Stefan Weil
Report from smatch:
mcf5206.c:384
m5206_mbar_readb(7)error: buffer overflow 'm5206_mbar_width' 128 <= 128 mcf5206.c:403m5206_mbar_readw(8)error: buffer overflow 'm5206_mbar_width' 128 <= 128 mcf5206.c:427m5206_mbar_readl(8)error: buffer overflow 'm5206_mbar_width' 128 <= 128 mcf5206.c:451m5206_mbar_writeb(9)error: buffer overflow 'm5206_mbar_width' 128 <= 128 mcf5206.c:475m5206_mbar_writew(9)error: buffer overflow 'm5206_mbar_width' 128 <= 128 mcf5206.c:503m5206_mbar_writel(9)error: buffer overflow 'm5206_mbar_width' 128 <= 128
m5206_mbar_widthhas0x80elements and supports 0 <= offset <0x200.Signed-off-by Stefan Weil <[email protected]>--- hw/mcf5206.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)hw/mcf5206.c +6
-6@@ -378,7 +378,7 @@ static uint32_t m5206_mbar_readb(void *opaque, target_phys_addr_t offset) {m5206_mbar_state *s = (m5206_mbar_state *)opaque; offset &=0x3ff ; -if (offset >0x200 ) { +if (offset >=0x200 ) {hw_error ("Bad MBAR read offset 0x%x" , (int )offset); }if (m5206_mbar_width[offset >>2 ] >1 ) {@@ -397,7 +397,7 @@ static uint32_t m5206_mbar_readw(void *opaque, target_phys_addr_t offset)m5206_mbar_state *s = (m5206_mbar_state *)opaque;int width; offset &=0x3ff ; -if (offset >0x200 ) { +if (offset >=0x200 ) {hw_error ("Bad MBAR read offset 0x%x" , (int )offset); } width = m5206_mbar_width[offset >>2 ];@@ -421,7 +421,7 @@ static uint32_t m5206_mbar_readl(void *opaque, target_phys_addr_t offset)m5206_mbar_state *s = (m5206_mbar_state *)opaque;int width; offset &=0x3ff ; -if (offset >0x200 ) { +if (offset >=0x200 ) {hw_error ("Bad MBAR read offset 0x%x" , (int )offset); } width = m5206_mbar_width[offset >>2 ];@@ -445,7 +445,7 @@ static void m5206_mbar_writeb(void *opaque, target_phys_addr_t offset,m5206_mbar_state *s = (m5206_mbar_state *)opaque;int width; offset &=0x3ff ; -if (offset >0x200 ) { +if (offset >=0x200 ) {hw_error ("Bad MBAR write offset 0x%x" , (int )offset); } width = m5206_mbar_width[offset >>2 ];@@ -469,7 +469,7 @@ static void m5206_mbar_writew(void *opaque, target_phys_addr_t offset,m5206_mbar_state *s = (m5206_mbar_state *)opaque;int width; offset &=0x3ff ; -if (offset >0x200 ) { +if (offset >=0x200 ) {hw_error ("Bad MBAR write offset 0x%x" , (int )offset); } width = m5206_mbar_width[offset >>2 ];@@ -497,7 +497,7 @@ static void m5206_mbar_writel(void *opaque, target_phys_addr_t offset,m5206_mbar_state *s = (m5206_mbar_state *)opaque;int width; offset &=0x3ff ; -if (offset >0x200 ) { +if (offset >=0x200 ) {hw_error ("Bad MBAR write offset 0x%x" , (int )offset); } width = m5206_mbar_width[offset >>2 ];Signature · 1 line
1.7.10
Thanks, applied.
Signature · 2 lines
Aurelien Jarno GPG: 1024D/F1BCDB73 [email protected] http://www.aurel32.net