[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL v2 19/19] fw_cfg: fix memory corruption when all fw_c
From: |
Eduardo Habkost |
Subject: |
[Qemu-devel] [PULL v2 19/19] fw_cfg: fix memory corruption when all fw_cfg slots are used |
Date: |
Fri, 19 Jan 2018 14:33:45 -0200 |
From: Marcel Apfelbaum <address@hidden>
When all the fw_cfg slots are used, a write is made outside the
bounds of the fw_cfg files array as part of the sort algorithm.
Fix it by avoiding an unnecessary array element move.
Fix also an assert while at it.
Signed-off-by: Marcel Apfelbaum <address@hidden>
Message-Id: <address@hidden>
Reviewed-by: Laszlo Ersek <address@hidden>
Signed-off-by: Eduardo Habkost <address@hidden>
---
hw/nvram/fw_cfg.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
index 753ac0e4ea..4313484b21 100644
--- a/hw/nvram/fw_cfg.c
+++ b/hw/nvram/fw_cfg.c
@@ -784,7 +784,7 @@ void fw_cfg_add_file_callback(FWCfgState *s, const char
*filename,
* index and "i - 1" is the one being copied from, thus the
* unusual start and end in the for statement.
*/
- for (i = count + 1; i > index; i--) {
+ for (i = count; i > index; i--) {
s->files->f[i] = s->files->f[i - 1];
s->files->f[i].select = cpu_to_be16(FW_CFG_FILE_FIRST + i);
s->entries[0][FW_CFG_FILE_FIRST + i] =
@@ -833,7 +833,6 @@ void *fw_cfg_modify_file(FWCfgState *s, const char
*filename,
assert(s->files);
index = be32_to_cpu(s->files->count);
- assert(index < fw_cfg_file_slots(s));
for (i = 0; i < index; i++) {
if (strcmp(filename, s->files->f[i].name) == 0) {
@@ -843,6 +842,9 @@ void *fw_cfg_modify_file(FWCfgState *s, const char
*filename,
return ptr;
}
}
+
+ assert(index < fw_cfg_file_slots(s));
+
/* add new one */
fw_cfg_add_file_callback(s, filename, NULL, NULL, NULL, data, len, true);
return NULL;
--
2.14.3
- [Qemu-devel] [PULL v2 09/19] spapr: Allow only supported dynamic sysbus devices, (continued)
- [Qemu-devel] [PULL v2 09/19] spapr: Allow only supported dynamic sysbus devices, Eduardo Habkost, 2018/01/19
- [Qemu-devel] [PULL v2 10/19] xen: Add only xen-sysdev to dynamic sysbus device list, Eduardo Habkost, 2018/01/19
- [Qemu-devel] [PULL v2 11/19] q35: Allow only supported dynamic sysbus devices, Eduardo Habkost, 2018/01/19
- [Qemu-devel] [PULL v2 12/19] qdev_monitor: Simplify error handling in qdev_device_add(), Eduardo Habkost, 2018/01/19
- [Qemu-devel] [PULL v2 13/19] qdev: Check for the availability of a hotplug controller before adding a device, Eduardo Habkost, 2018/01/19
- [Qemu-devel] [PULL v2 14/19] scripts: Remove fixed entries from the device-crash-test, Eduardo Habkost, 2018/01/19
- [Qemu-devel] [PULL v2 15/19] hostmem-file: add "align" option, Eduardo Habkost, 2018/01/19
- [Qemu-devel] [PULL v2 16/19] nvdimm: add a macro for property "label-size", Eduardo Habkost, 2018/01/19
- [Qemu-devel] [PULL v2 17/19] nvdimm: add 'unarmed' option, Eduardo Habkost, 2018/01/19
- [Qemu-devel] [PULL v2 18/19] possible_cpus: add CPUArchId::type field, Eduardo Habkost, 2018/01/19
- [Qemu-devel] [PULL v2 19/19] fw_cfg: fix memory corruption when all fw_cfg slots are used,
Eduardo Habkost <=
- Re: [Qemu-devel] [PULL v2 00/19] machine queue, 2018-01-19, Peter Maydell, 2018/01/19