97f3bec
From: Prasad J Pandit <address@hidden>
97f3bec
97f3bec
When processing firmware configurations, an OOB r/w access occurs
97f3bec
if 's->cur_entry' is set to be invalid(FW_CFG_INVALID=0xffff).
97f3bec
Add a check to validate 's->cur_entry' to avoid such access.
97f3bec
97f3bec
Reported-by: Donghai Zdh <address@hidden>
97f3bec
Signed-off-by: Prasad J Pandit <address@hidden>
97f3bec
---
97f3bec
 hw/nvram/fw_cfg.c | 12 ++++++++----
97f3bec
 1 file changed, 8 insertions(+), 4 deletions(-)
97f3bec
97f3bec
Updated as per review in
97f3bec
  -> https://lists.gnu.org/archive/html/qemu-devel/2016-01/msg00398.html
97f3bec
97f3bec
diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
97f3bec
index 68eff77..e73c0fb 100644
97f3bec
--- a/tools/qemu-xen/hw/nvram/fw_cfg.c
97f3bec
+++ b/tools/qemu-xen/hw/nvram/fw_cfg.c
97f3bec
@@ -233,12 +233,15 @@ static void fw_cfg_reboot(FWCfgState *s)
97f3bec
 static void fw_cfg_write(FWCfgState *s, uint8_t value)
97f3bec
 {
97f3bec
     int arch = !!(s->cur_entry & FW_CFG_ARCH_LOCAL);
97f3bec
-    FWCfgEntry *e = &s->entries[arch][s->cur_entry & FW_CFG_ENTRY_MASK];
97f3bec
+    FWCfgEntry *e = (s->cur_entry == FW_CFG_INVALID) ? NULL :
97f3bec
+                     &s->entries[arch][s->cur_entry & FW_CFG_ENTRY_MASK];
97f3bec
 
97f3bec
     trace_fw_cfg_write(s, value);
97f3bec
 
97f3bec
-    if (s->cur_entry & FW_CFG_WRITE_CHANNEL && e->callback &&
97f3bec
-        s->cur_offset < e->len) {
97f3bec
+    if (s->cur_entry & FW_CFG_WRITE_CHANNEL
97f3bec
+        && e != NULL
97f3bec
+        && e->callback
97f3bec
+        && s->cur_offset < e->len) {
97f3bec
         e->data[s->cur_offset++] = value;
97f3bec
         if (s->cur_offset == e->len) {
97f3bec
             e->callback(e->callback_opaque, e->data);
97f3bec
@@ -267,7 +270,8 @@ static int fw_cfg_select(FWCfgState *s, uint16_t key)
97f3bec
 static uint8_t fw_cfg_read(FWCfgState *s)
97f3bec
 {
97f3bec
     int arch = !!(s->cur_entry & FW_CFG_ARCH_LOCAL);
97f3bec
-    FWCfgEntry *e = &s->entries[arch][s->cur_entry & FW_CFG_ENTRY_MASK];
97f3bec
+    FWCfgEntry *e = (s->cur_entry == FW_CFG_INVALID) ? NULL :
97f3bec
+                     &s->entries[arch][s->cur_entry & FW_CFG_ENTRY_MASK];
97f3bec
     uint8_t ret;
97f3bec
 
97f3bec
     if (s->cur_entry == FW_CFG_INVALID || !e->data || s->cur_offset >= e->len)
97f3bec
-- 
97f3bec
2.4.3