yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
34b321
From ba24567fd90702ea40ff320a79bc921b38510f22 Mon Sep 17 00:00:00 2001
95f32b
From: Miroslav Rezanina <mrezanin@redhat.com>
95f32b
Date: Thu, 21 Jan 2016 07:17:43 +0100
34b321
Subject: [PATCH 2/2] fw_cfg: add check to validate current entry value
95f32b
 (CVE-2016-1714)
95f32b
MIME-Version: 1.0
95f32b
Content-Type: text/plain; charset=UTF-8
95f32b
Content-Transfer-Encoding: 8bit
95f32b
34b321
RH-Author: Miroslav Rezanina <mrezanin@redhat.com>
95f32b
Message-id: <1453360663-5066-1-git-send-email-mrezanin@redhat.com>
95f32b
Patchwork-id: 68834
95f32b
O-Subject: [RHEL-7.2.z/RHEL-7.3 qemu-kvm PATCH] fw_cfg: add check to validate current entry value (CVE-2016-1714)
34b321
Bugzilla: 1298048
95f32b
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
95f32b
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
95f32b
RH-Acked-by: Gerd Hoffmann <kraxel@redhat.com>
95f32b
95f32b
From: Prasad J Pandit <pjp@fedoraproject.org>
95f32b
95f32b
When processing firmware configurations, an OOB r/w access occurs
95f32b
if 's->cur_entry' is set to be invalid(FW_CFG_INVALID=0xffff).
95f32b
Add a check to validate 's->cur_entry' to avoid such access.
95f32b
95f32b
This patch is based on upstream commit 66f8fd9dda312191b78d2a2ba2848bcee76127a2
95f32b
  Author: Gabriel L. Somlo <somlo@cmu.edu>
95f32b
  Date:   Thu Nov 5 09:32:50 2015 -0500
95f32b
95f32b
    fw_cfg: avoid calculating invalid current entry pointer
95f32b
95f32b
    When calculating a pointer to the currently selected fw_cfg item, the
95f32b
    following is used:
95f32b
95f32b
      FWCfgEntry *e = &s->entries[arch][s->cur_entry & FW_CFG_ENTRY_MASK];
95f32b
95f32b
    When s->cur_entry is FW_CFG_INVALID, we are calculating the address of
95f32b
    a non-existent element in s->entries[arch][...], which is undefined.
95f32b
95f32b
    This patch ensures the resulting entry pointer is set to NULL whenever
95f32b
    s->cur_entry is FW_CFG_INVALID.
95f32b
95f32b
    Reported-by: Laszlo Ersek <lersek@redhat.com>
95f32b
    Reviewed-by: Laszlo Ersek <lersek@redhat.com>
95f32b
    Signed-off-by: Gabriel Somlo <somlo@cmu.edu>
95f32b
    Message-id: 1446733972-1602-5-git-send-email-somlo@cmu.edu
95f32b
    Cc: Marc MarĂ­ <markmb@redhat.com>
95f32b
    Signed-off-by: Gabriel Somlo <somlo@cmu.edu>
95f32b
    Reviewed-by: Laszlo Ersek <lersek@redhat.com>
95f32b
    Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
95f32b
95f32b
with added chunk for fw_cfg_write() that was removed in commit
95f32b
023e3148567ac898c7258138f8e86c3c2bb40d07
95f32b
and missing chunk for fw_cfg_dma_transfer that was added in commit
95f32b
a4c0d1deb785611c96a455f65ec032976b00b36f.
95f32b
95f32b
Reported-by: Donghai Zdh <donghai.zdh@alibaba-inc.com>
95f32b
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
95f32b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
95f32b
---
95f32b
 hw/nvram/fw_cfg.c | 12 ++++++++----
95f32b
 1 file changed, 8 insertions(+), 4 deletions(-)
95f32b
95f32b
diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
95f32b
index b865c09..fcb3146 100644
95f32b
--- a/hw/nvram/fw_cfg.c
95f32b
+++ b/hw/nvram/fw_cfg.c
95f32b
@@ -207,12 +207,15 @@ static void fw_cfg_reboot(FWCfgState *s)
95f32b
 static void fw_cfg_write(FWCfgState *s, uint8_t value)
95f32b
 {
95f32b
     int arch = !!(s->cur_entry & FW_CFG_ARCH_LOCAL);
95f32b
-    FWCfgEntry *e = &s->entries[arch][s->cur_entry & FW_CFG_ENTRY_MASK];
95f32b
+    FWCfgEntry *e = (s->cur_entry == FW_CFG_INVALID) ? NULL :
95f32b
+                     &s->entries[arch][s->cur_entry & FW_CFG_ENTRY_MASK];
95f32b
 
95f32b
     trace_fw_cfg_write(s, value);
95f32b
 
95f32b
-    if (s->cur_entry & FW_CFG_WRITE_CHANNEL && e->callback &&
95f32b
-        s->cur_offset < e->len) {
95f32b
+    if (s->cur_entry & FW_CFG_WRITE_CHANNEL
95f32b
+        && e != NULL
95f32b
+        && e->callback
95f32b
+        && s->cur_offset < e->len) {
95f32b
         e->data[s->cur_offset++] = value;
95f32b
         if (s->cur_offset == e->len) {
95f32b
             e->callback(e->callback_opaque, e->data);
95f32b
@@ -241,7 +244,8 @@ static int fw_cfg_select(FWCfgState *s, uint16_t key)
95f32b
 static uint8_t fw_cfg_read(FWCfgState *s)
95f32b
 {
95f32b
     int arch = !!(s->cur_entry & FW_CFG_ARCH_LOCAL);
95f32b
-    FWCfgEntry *e = &s->entries[arch][s->cur_entry & FW_CFG_ENTRY_MASK];
95f32b
+    FWCfgEntry *e = (s->cur_entry == FW_CFG_INVALID) ? NULL :
95f32b
+                     &s->entries[arch][s->cur_entry & FW_CFG_ENTRY_MASK];
95f32b
     uint8_t ret;
95f32b
 
95f32b
     if (s->cur_entry == FW_CFG_INVALID || !e->data || s->cur_offset >= e->len)
95f32b
-- 
95f32b
1.8.3.1
95f32b