|
|
9bac43 |
From 0df9f346cb7d66701c79cb6fa1b187aa603d659b Mon Sep 17 00:00:00 2001
|
|
|
9bac43 |
From: Marcel Apfelbaum <marcel@redhat.com>
|
|
|
9bac43 |
Date: Mon, 15 Jan 2018 10:06:42 +0100
|
|
|
9bac43 |
Subject: [PATCH 09/12] fw_cfg: fix memory corruption when all fw_cfg slots are
|
|
|
9bac43 |
used
|
|
|
9bac43 |
MIME-Version: 1.0
|
|
|
9bac43 |
Content-Type: text/plain; charset=UTF-8
|
|
|
9bac43 |
Content-Transfer-Encoding: 8bit
|
|
|
9bac43 |
|
|
|
9bac43 |
RH-Author: Marcel Apfelbaum <marcel@redhat.com>
|
|
|
9bac43 |
Message-id: <20180115100642.64493-1-marcel@redhat.com>
|
|
|
9bac43 |
Patchwork-id: 78571
|
|
|
9bac43 |
O-Subject: [RHEL-7.5 qemu-kvm-rhev PATCH] fw_cfg: fix memory corruption when all fw_cfg slots are used
|
|
|
9bac43 |
Bugzilla: 1462145
|
|
|
9bac43 |
RH-Acked-by: Marc-André Lureau <mlureau@redhat.com>
|
|
|
9bac43 |
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
|
|
|
9bac43 |
RH-Acked-by: Gerd Hoffmann <kraxel@redhat.com>
|
|
|
9bac43 |
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
|
|
|
9bac43 |
|
|
|
9bac43 |
When all the fw_cfg slots are used, a write is made outside the
|
|
|
9bac43 |
bounds of the fw_cfg files array as part of the sort algorithm.
|
|
|
9bac43 |
|
|
|
9bac43 |
Fix it by avoiding an unnecessary array element move.
|
|
|
9bac43 |
Fix also an assert while at it.
|
|
|
9bac43 |
|
|
|
9bac43 |
Signed-off-by: Marcel Apfelbaum <marcel@redhat.com>
|
|
|
9bac43 |
Message-Id: <20180108215007.46471-1-marcel@redhat.com>
|
|
|
9bac43 |
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
|
|
|
9bac43 |
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
|
|
|
9bac43 |
(cherry picked from commit 45eda6c8eb45107630da670bc993074cf85ef64c)
|
|
|
9bac43 |
Signed-off-by: Marcel Apfelbaum <marcel@redhat.com>
|
|
|
9bac43 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9bac43 |
---
|
|
|
9bac43 |
hw/nvram/fw_cfg.c | 6 ++++--
|
|
|
9bac43 |
1 file changed, 4 insertions(+), 2 deletions(-)
|
|
|
9bac43 |
|
|
|
9bac43 |
diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
|
|
|
9bac43 |
index 753ac0e..4313484 100644
|
|
|
9bac43 |
--- a/hw/nvram/fw_cfg.c
|
|
|
9bac43 |
+++ b/hw/nvram/fw_cfg.c
|
|
|
9bac43 |
@@ -784,7 +784,7 @@ void fw_cfg_add_file_callback(FWCfgState *s, const char *filename,
|
|
|
9bac43 |
* index and "i - 1" is the one being copied from, thus the
|
|
|
9bac43 |
* unusual start and end in the for statement.
|
|
|
9bac43 |
*/
|
|
|
9bac43 |
- for (i = count + 1; i > index; i--) {
|
|
|
9bac43 |
+ for (i = count; i > index; i--) {
|
|
|
9bac43 |
s->files->f[i] = s->files->f[i - 1];
|
|
|
9bac43 |
s->files->f[i].select = cpu_to_be16(FW_CFG_FILE_FIRST + i);
|
|
|
9bac43 |
s->entries[0][FW_CFG_FILE_FIRST + i] =
|
|
|
9bac43 |
@@ -833,7 +833,6 @@ void *fw_cfg_modify_file(FWCfgState *s, const char *filename,
|
|
|
9bac43 |
assert(s->files);
|
|
|
9bac43 |
|
|
|
9bac43 |
index = be32_to_cpu(s->files->count);
|
|
|
9bac43 |
- assert(index < fw_cfg_file_slots(s));
|
|
|
9bac43 |
|
|
|
9bac43 |
for (i = 0; i < index; i++) {
|
|
|
9bac43 |
if (strcmp(filename, s->files->f[i].name) == 0) {
|
|
|
9bac43 |
@@ -843,6 +842,9 @@ void *fw_cfg_modify_file(FWCfgState *s, const char *filename,
|
|
|
9bac43 |
return ptr;
|
|
|
9bac43 |
}
|
|
|
9bac43 |
}
|
|
|
9bac43 |
+
|
|
|
9bac43 |
+ assert(index < fw_cfg_file_slots(s));
|
|
|
9bac43 |
+
|
|
|
9bac43 |
/* add new one */
|
|
|
9bac43 |
fw_cfg_add_file_callback(s, filename, NULL, NULL, NULL, data, len, true);
|
|
|
9bac43 |
return NULL;
|
|
|
9bac43 |
--
|
|
|
9bac43 |
1.8.3.1
|
|
|
9bac43 |
|