yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-fw_cfg-add-check-to-validate-current-entry-value-CVE.patch

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