Skip to content

Commit

Permalink
hw/i386: Improve bounds checking in OVMF table parsing
Browse files Browse the repository at this point in the history
When pc_system_parse_ovmf_flash() parses the optional GUIDed table in
the end of the OVMF flash memory area, the table length field is checked
for sizes that are too small, but doesn't error on sizes that are too
big (bigger than the flash content itself).

Add a check for maximal size of the OVMF table, and add an error report
in case the size is invalid.  In such a case, an error like this will be
displayed during launch:

    qemu-system-x86_64: OVMF table has invalid size 4047

and the table parsing is skipped.

Signed-off-by: Dov Murik <dovmurik@linux.ibm.com>
Message-Id: <20220222071906.2632426-2-dovmurik@linux.ibm.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
  • Loading branch information
dubek authored and mstsirkin committed Mar 6, 2022
1 parent b8ffd7d commit e5aaeac
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion hw/i386/pc_sysfw_ovmf.c
Expand Up @@ -24,6 +24,7 @@
*/

#include "qemu/osdep.h"
#include "qemu/error-report.h"
#include "hw/i386/pc.h"
#include "cpu.h"

Expand Down Expand Up @@ -66,7 +67,13 @@ void pc_system_parse_ovmf_flash(uint8_t *flash_ptr, size_t flash_size)
ptr -= sizeof(uint16_t);
tot_len = le16_to_cpu(*(uint16_t *)ptr) - sizeof(guid) - sizeof(uint16_t);

if (tot_len <= 0) {
if (tot_len < 0 || tot_len > (ptr - flash_ptr)) {
error_report("OVMF table has invalid size %d", tot_len);
return;
}

if (tot_len == 0) {
/* no entries in the OVMF table */
return;
}

Expand Down

0 comments on commit e5aaeac

Please sign in to comment.