peterdelevoryas / rpms / qemu

Forked from rpms/qemu 2 years ago
Clone

Blame 0122-hw-mcf5206-Fix-buffer-overflow-for-MBAR-read-write.patch

5544c1
From 90c742c7f36f45249c62c0c5db2e138a604e44ac Mon Sep 17 00:00:00 2001
5544c1
From: Stefan Weil <sw@weilnetz.de>
5544c1
Date: Tue, 4 Sep 2012 19:37:39 +0200
5544c1
Subject: [PATCH] hw/mcf5206: Fix buffer overflow for MBAR read / write
5544c1
5544c1
Report from smatch:
5544c1
5544c1
mcf5206.c:384 m5206_mbar_readb(7) error: buffer overflow 'm5206_mbar_width' 128 <= 128
5544c1
mcf5206.c:403 m5206_mbar_readw(8) error: buffer overflow 'm5206_mbar_width' 128 <= 128
5544c1
mcf5206.c:427 m5206_mbar_readl(8) error: buffer overflow 'm5206_mbar_width' 128 <= 128
5544c1
mcf5206.c:451 m5206_mbar_writeb(9) error: buffer overflow 'm5206_mbar_width' 128 <= 128
5544c1
mcf5206.c:475 m5206_mbar_writew(9) error: buffer overflow 'm5206_mbar_width' 128 <= 128
5544c1
mcf5206.c:503 m5206_mbar_writel(9) error: buffer overflow 'm5206_mbar_width' 128 <= 128
5544c1
5544c1
m5206_mbar_width has 0x80 elements and supports 0 <= offset < 0x200.
5544c1
5544c1
Signed-off-by: Stefan Weil <sw@weilnetz.de>
5544c1
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
5544c1
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
5544c1
(cherry picked from commit a32354e206895400d17c3de9a8df1de96d3df289)
5544c1
5544c1
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
5544c1
---
5544c1
 hw/mcf5206.c | 12 ++++++------
5544c1
 1 file changed, 6 insertions(+), 6 deletions(-)
5544c1
5544c1
diff --git a/hw/mcf5206.c b/hw/mcf5206.c
5544c1
index 539b391..27753e2 100644
5544c1
--- a/hw/mcf5206.c
5544c1
+++ b/hw/mcf5206.c
5544c1
@@ -378,7 +378,7 @@ static uint32_t m5206_mbar_readb(void *opaque, target_phys_addr_t offset)
5544c1
 {
5544c1
     m5206_mbar_state *s = (m5206_mbar_state *)opaque;
5544c1
     offset &= 0x3ff;
5544c1
-    if (offset > 0x200) {
5544c1
+    if (offset >= 0x200) {
5544c1
         hw_error("Bad MBAR read offset 0x%x", (int)offset);
5544c1
     }
5544c1
     if (m5206_mbar_width[offset >> 2] > 1) {
5544c1
@@ -397,7 +397,7 @@ static uint32_t m5206_mbar_readw(void *opaque, target_phys_addr_t offset)
5544c1
     m5206_mbar_state *s = (m5206_mbar_state *)opaque;
5544c1
     int width;
5544c1
     offset &= 0x3ff;
5544c1
-    if (offset > 0x200) {
5544c1
+    if (offset >= 0x200) {
5544c1
         hw_error("Bad MBAR read offset 0x%x", (int)offset);
5544c1
     }
5544c1
     width = m5206_mbar_width[offset >> 2];
5544c1
@@ -421,7 +421,7 @@ static uint32_t m5206_mbar_readl(void *opaque, target_phys_addr_t offset)
5544c1
     m5206_mbar_state *s = (m5206_mbar_state *)opaque;
5544c1
     int width;
5544c1
     offset &= 0x3ff;
5544c1
-    if (offset > 0x200) {
5544c1
+    if (offset >= 0x200) {
5544c1
         hw_error("Bad MBAR read offset 0x%x", (int)offset);
5544c1
     }
5544c1
     width = m5206_mbar_width[offset >> 2];
5544c1
@@ -445,7 +445,7 @@ static void m5206_mbar_writeb(void *opaque, target_phys_addr_t offset,
5544c1
     m5206_mbar_state *s = (m5206_mbar_state *)opaque;
5544c1
     int width;
5544c1
     offset &= 0x3ff;
5544c1
-    if (offset > 0x200) {
5544c1
+    if (offset >= 0x200) {
5544c1
         hw_error("Bad MBAR write offset 0x%x", (int)offset);
5544c1
     }
5544c1
     width = m5206_mbar_width[offset >> 2];
5544c1
@@ -469,7 +469,7 @@ static void m5206_mbar_writew(void *opaque, target_phys_addr_t offset,
5544c1
     m5206_mbar_state *s = (m5206_mbar_state *)opaque;
5544c1
     int width;
5544c1
     offset &= 0x3ff;
5544c1
-    if (offset > 0x200) {
5544c1
+    if (offset >= 0x200) {
5544c1
         hw_error("Bad MBAR write offset 0x%x", (int)offset);
5544c1
     }
5544c1
     width = m5206_mbar_width[offset >> 2];
5544c1
@@ -497,7 +497,7 @@ static void m5206_mbar_writel(void *opaque, target_phys_addr_t offset,
5544c1
     m5206_mbar_state *s = (m5206_mbar_state *)opaque;
5544c1
     int width;
5544c1
     offset &= 0x3ff;
5544c1
-    if (offset > 0x200) {
5544c1
+    if (offset >= 0x200) {
5544c1
         hw_error("Bad MBAR write offset 0x%x", (int)offset);
5544c1
     }
5544c1
     width = m5206_mbar_width[offset >> 2];
5544c1
-- 
5544c1
1.7.12.1
5544c1