Merge "Change requested in launchpad bug #1288352" into 5.0
[packages/centos6/qemu.git] / 0122-hw-mcf5206-Fix-buffer-overflow-for-MBAR-read-write.patch
1 From 90c742c7f36f45249c62c0c5db2e138a604e44ac Mon Sep 17 00:00:00 2001
2 From: Stefan Weil <sw@weilnetz.de>
3 Date: Tue, 4 Sep 2012 19:37:39 +0200
4 Subject: [PATCH] hw/mcf5206: Fix buffer overflow for MBAR read / write
5
6 Report from smatch:
7
8 mcf5206.c:384 m5206_mbar_readb(7) error: buffer overflow 'm5206_mbar_width' 128 <= 128
9 mcf5206.c:403 m5206_mbar_readw(8) error: buffer overflow 'm5206_mbar_width' 128 <= 128
10 mcf5206.c:427 m5206_mbar_readl(8) error: buffer overflow 'm5206_mbar_width' 128 <= 128
11 mcf5206.c:451 m5206_mbar_writeb(9) error: buffer overflow 'm5206_mbar_width' 128 <= 128
12 mcf5206.c:475 m5206_mbar_writew(9) error: buffer overflow 'm5206_mbar_width' 128 <= 128
13 mcf5206.c:503 m5206_mbar_writel(9) error: buffer overflow 'm5206_mbar_width' 128 <= 128
14
15 m5206_mbar_width has 0x80 elements and supports 0 <= offset < 0x200.
16
17 Signed-off-by: Stefan Weil <sw@weilnetz.de>
18 Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
19 Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
20 (cherry picked from commit a32354e206895400d17c3de9a8df1de96d3df289)
21
22 Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
23 ---
24  hw/mcf5206.c | 12 ++++++------
25  1 file changed, 6 insertions(+), 6 deletions(-)
26
27 diff --git a/hw/mcf5206.c b/hw/mcf5206.c
28 index 539b391..27753e2 100644
29 --- a/hw/mcf5206.c
30 +++ b/hw/mcf5206.c
31 @@ -378,7 +378,7 @@ static uint32_t m5206_mbar_readb(void *opaque, target_phys_addr_t offset)
32  {
33      m5206_mbar_state *s = (m5206_mbar_state *)opaque;
34      offset &= 0x3ff;
35 -    if (offset > 0x200) {
36 +    if (offset >= 0x200) {
37          hw_error("Bad MBAR read offset 0x%x", (int)offset);
38      }
39      if (m5206_mbar_width[offset >> 2] > 1) {
40 @@ -397,7 +397,7 @@ static uint32_t m5206_mbar_readw(void *opaque, target_phys_addr_t offset)
41      m5206_mbar_state *s = (m5206_mbar_state *)opaque;
42      int width;
43      offset &= 0x3ff;
44 -    if (offset > 0x200) {
45 +    if (offset >= 0x200) {
46          hw_error("Bad MBAR read offset 0x%x", (int)offset);
47      }
48      width = m5206_mbar_width[offset >> 2];
49 @@ -421,7 +421,7 @@ static uint32_t m5206_mbar_readl(void *opaque, target_phys_addr_t offset)
50      m5206_mbar_state *s = (m5206_mbar_state *)opaque;
51      int width;
52      offset &= 0x3ff;
53 -    if (offset > 0x200) {
54 +    if (offset >= 0x200) {
55          hw_error("Bad MBAR read offset 0x%x", (int)offset);
56      }
57      width = m5206_mbar_width[offset >> 2];
58 @@ -445,7 +445,7 @@ static void m5206_mbar_writeb(void *opaque, target_phys_addr_t offset,
59      m5206_mbar_state *s = (m5206_mbar_state *)opaque;
60      int width;
61      offset &= 0x3ff;
62 -    if (offset > 0x200) {
63 +    if (offset >= 0x200) {
64          hw_error("Bad MBAR write offset 0x%x", (int)offset);
65      }
66      width = m5206_mbar_width[offset >> 2];
67 @@ -469,7 +469,7 @@ static void m5206_mbar_writew(void *opaque, target_phys_addr_t offset,
68      m5206_mbar_state *s = (m5206_mbar_state *)opaque;
69      int width;
70      offset &= 0x3ff;
71 -    if (offset > 0x200) {
72 +    if (offset >= 0x200) {
73          hw_error("Bad MBAR write offset 0x%x", (int)offset);
74      }
75      width = m5206_mbar_width[offset >> 2];
76 @@ -497,7 +497,7 @@ static void m5206_mbar_writel(void *opaque, target_phys_addr_t offset,
77      m5206_mbar_state *s = (m5206_mbar_state *)opaque;
78      int width;
79      offset &= 0x3ff;
80 -    if (offset > 0x200) {
81 +    if (offset >= 0x200) {
82          hw_error("Bad MBAR write offset 0x%x", (int)offset);
83      }
84      width = m5206_mbar_width[offset >> 2];
85 -- 
86 1.7.12.1
87