b24b7f1
From: Prasad J Pandit <pjp@fedoraproject.org>
b24b7f1
Date: Thu, 31 Dec 2015 17:05:27 +0530
b24b7f1
Subject: [PATCH] net: ne2000: fix bounds check in ioport operations
b24b7f1
b24b7f1
While doing ioport r/w operations, ne2000 device emulation suffers
b24b7f1
from OOB r/w errors. Update respective array bounds check to avoid
b24b7f1
OOB access.
b24b7f1
b24b7f1
Reported-by: Ling Liu <liuling-it@360.cn>
b24b7f1
Cc: qemu-stable@nongnu.org
b24b7f1
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
b24b7f1
Signed-off-by: Jason Wang <jasowang@redhat.com>
b24b7f1
(cherry picked from commit aa7f9966dfdff500bbbf1956d9e115b1fa8987a6)
b24b7f1
---
b24b7f1
 hw/net/ne2000.c | 10 ++++++----
b24b7f1
 1 file changed, 6 insertions(+), 4 deletions(-)
b24b7f1
b24b7f1
diff --git a/hw/net/ne2000.c b/hw/net/ne2000.c
b24b7f1
index 010f9ef..a3dffff 100644
b24b7f1
--- a/hw/net/ne2000.c
b24b7f1
+++ b/hw/net/ne2000.c
b24b7f1
@@ -467,8 +467,9 @@ static inline void ne2000_mem_writel(NE2000State *s, uint32_t addr,
b24b7f1
                                      uint32_t val)
b24b7f1
 {
b24b7f1
     addr &= ~1; /* XXX: check exact behaviour if not even */
b24b7f1
-    if (addr < 32 ||
b24b7f1
-        (addr >= NE2000_PMEM_START && addr < NE2000_MEM_SIZE)) {
b24b7f1
+    if (addr < 32
b24b7f1
+        || (addr >= NE2000_PMEM_START
b24b7f1
+            && addr + sizeof(uint32_t) <= NE2000_MEM_SIZE)) {
b24b7f1
         stl_le_p(s->mem + addr, val);
b24b7f1
     }
b24b7f1
 }
b24b7f1
@@ -497,8 +498,9 @@ static inline uint32_t ne2000_mem_readw(NE2000State *s, uint32_t addr)
b24b7f1
 static inline uint32_t ne2000_mem_readl(NE2000State *s, uint32_t addr)
b24b7f1
 {
b24b7f1
     addr &= ~1; /* XXX: check exact behaviour if not even */
b24b7f1
-    if (addr < 32 ||
b24b7f1
-        (addr >= NE2000_PMEM_START && addr < NE2000_MEM_SIZE)) {
b24b7f1
+    if (addr < 32
b24b7f1
+        || (addr >= NE2000_PMEM_START
b24b7f1
+            && addr + sizeof(uint32_t) <= NE2000_MEM_SIZE)) {
b24b7f1
         return ldl_le_p(s->mem + addr);
b24b7f1
     } else {
b24b7f1
         return 0xffffffff;