* [PATCH v3 0/2] hw/i386: OVMF table parsing fixes
@ 2022-02-22 7:19 Dov Murik
2022-02-22 7:19 ` [PATCH v3 1/2] hw/i386: Improve bounds checking in OVMF table parsing Dov Murik
2022-02-22 7:19 ` [PATCH v3 2/2] hw/i386: Replace magic number with field length calculation Dov Murik
0 siblings, 2 replies; 6+ messages in thread
From: Dov Murik @ 2022-02-22 7:19 UTC (permalink / raw)
To: qemu-devel
Cc: Eduardo Habkost, Daniel P. Berrangé, Michael S. Tsirkin,
James Bottomley, Richard Henderson, Philippe Mathieu-Daudé,
Dr. David Alan Gilbert, Dov Murik, Tobin Feldman-Fitzthum,
Gerd Hoffmann, Paolo Bonzini
Fix missing bounds check when parsing the OVMF table.
This already had two iterations as a single patch; I decided to split it
to two patches. The first deals only with bounds checking, and the
second is a non-functional change to clear the code according to
reviewers' suggestions.
v3:
- simplify bounds check and remove max_tot_len (thanks Dave)
- split one patch to two
v2:
- add error message example to commit description
- replace magic numbers 48 and 50 with size calculations (thanks Phil
MD)
Dov Murik (2):
hw/i386: Improve bounds checking in OVMF table parsing
hw/i386: Replace magic number with field length calculation
hw/i386/pc_sysfw_ovmf.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
base-commit: 477c3b934a47adf7de285863f59d6e4503dd1a6d
--
2.25.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v3 1/2] hw/i386: Improve bounds checking in OVMF table parsing
2022-02-22 7:19 [PATCH v3 0/2] hw/i386: OVMF table parsing fixes Dov Murik
@ 2022-02-22 7:19 ` Dov Murik
2022-02-22 9:23 ` Daniel P. Berrangé
2022-02-22 9:43 ` Dr. David Alan Gilbert
2022-02-22 7:19 ` [PATCH v3 2/2] hw/i386: Replace magic number with field length calculation Dov Murik
1 sibling, 2 replies; 6+ messages in thread
From: Dov Murik @ 2022-02-22 7:19 UTC (permalink / raw)
To: qemu-devel
Cc: Eduardo Habkost, Daniel P. Berrangé, Michael S. Tsirkin,
James Bottomley, Richard Henderson, Philippe Mathieu-Daudé,
Dr. David Alan Gilbert, Dov Murik, Tobin Feldman-Fitzthum,
Gerd Hoffmann, Paolo Bonzini
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>
---
hw/i386/pc_sysfw_ovmf.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/hw/i386/pc_sysfw_ovmf.c b/hw/i386/pc_sysfw_ovmf.c
index f4dd92c588..df15c9737b 100644
--- a/hw/i386/pc_sysfw_ovmf.c
+++ b/hw/i386/pc_sysfw_ovmf.c
@@ -24,6 +24,7 @@
*/
#include "qemu/osdep.h"
+#include "qemu/error-report.h"
#include "hw/i386/pc.h"
#include "cpu.h"
@@ -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;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v3 1/2] hw/i386: Improve bounds checking in OVMF table parsing
2022-02-22 7:19 ` [PATCH v3 1/2] hw/i386: Improve bounds checking in OVMF table parsing Dov Murik
@ 2022-02-22 9:23 ` Daniel P. Berrangé
2022-02-22 9:43 ` Dr. David Alan Gilbert
1 sibling, 0 replies; 6+ messages in thread
From: Daniel P. Berrangé @ 2022-02-22 9:23 UTC (permalink / raw)
To: Dov Murik
Cc: Eduardo Habkost, Michael S. Tsirkin, James Bottomley,
Richard Henderson, qemu-devel, Philippe Mathieu-Daudé,
Tobin Feldman-Fitzthum, Gerd Hoffmann, Paolo Bonzini,
Dr. David Alan Gilbert
On Tue, Feb 22, 2022 at 07:19:05AM +0000, Dov Murik wrote:
> 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>
> ---
> hw/i386/pc_sysfw_ovmf.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v3 1/2] hw/i386: Improve bounds checking in OVMF table parsing
2022-02-22 7:19 ` [PATCH v3 1/2] hw/i386: Improve bounds checking in OVMF table parsing Dov Murik
2022-02-22 9:23 ` Daniel P. Berrangé
@ 2022-02-22 9:43 ` Dr. David Alan Gilbert
1 sibling, 0 replies; 6+ messages in thread
From: Dr. David Alan Gilbert @ 2022-02-22 9:43 UTC (permalink / raw)
To: Dov Murik
Cc: Eduardo Habkost, Daniel P. Berrangé, Michael S. Tsirkin,
James Bottomley, Richard Henderson, qemu-devel,
Philippe Mathieu-Daudé, Tobin Feldman-Fitzthum,
Gerd Hoffmann, Paolo Bonzini
* Dov Murik (dovmurik@linux.ibm.com) wrote:
> 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>
Thanks,
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> ---
> hw/i386/pc_sysfw_ovmf.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/hw/i386/pc_sysfw_ovmf.c b/hw/i386/pc_sysfw_ovmf.c
> index f4dd92c588..df15c9737b 100644
> --- a/hw/i386/pc_sysfw_ovmf.c
> +++ b/hw/i386/pc_sysfw_ovmf.c
> @@ -24,6 +24,7 @@
> */
>
> #include "qemu/osdep.h"
> +#include "qemu/error-report.h"
> #include "hw/i386/pc.h"
> #include "cpu.h"
>
> @@ -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;
> }
>
> --
> 2.25.1
>
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v3 2/2] hw/i386: Replace magic number with field length calculation
2022-02-22 7:19 [PATCH v3 0/2] hw/i386: OVMF table parsing fixes Dov Murik
2022-02-22 7:19 ` [PATCH v3 1/2] hw/i386: Improve bounds checking in OVMF table parsing Dov Murik
@ 2022-02-22 7:19 ` Dov Murik
2022-02-22 9:25 ` Daniel P. Berrangé
1 sibling, 1 reply; 6+ messages in thread
From: Dov Murik @ 2022-02-22 7:19 UTC (permalink / raw)
To: qemu-devel
Cc: Eduardo Habkost, Daniel P. Berrangé, Michael S. Tsirkin,
James Bottomley, Richard Henderson, Philippe Mathieu-Daudé,
Dr. David Alan Gilbert, Dov Murik, Tobin Feldman-Fitzthum,
Gerd Hoffmann, Paolo Bonzini
Replce the literal magic number 48 with length calculation (32 bytes at
the end of the firmware after the table footer + 16 bytes of the OVMF
table footer GUID).
No functional change intended.
Signed-off-by: Dov Murik <dovmurik@linux.ibm.com>
---
hw/i386/pc_sysfw_ovmf.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/hw/i386/pc_sysfw_ovmf.c b/hw/i386/pc_sysfw_ovmf.c
index df15c9737b..07a4c267fa 100644
--- a/hw/i386/pc_sysfw_ovmf.c
+++ b/hw/i386/pc_sysfw_ovmf.c
@@ -30,6 +30,8 @@
#define OVMF_TABLE_FOOTER_GUID "96b582de-1fb2-45f7-baea-a366c55a082d"
+static const int bytes_after_table_footer = 32;
+
static bool ovmf_flash_parsed;
static uint8_t *ovmf_table;
static int ovmf_table_len;
@@ -53,12 +55,13 @@ void pc_system_parse_ovmf_flash(uint8_t *flash_ptr, size_t flash_size)
/*
* if this is OVMF there will be a table footer
- * guid 48 bytes before the end of the flash file. If it's
- * not found, silently abort the flash parsing.
+ * guid 48 bytes before the end of the flash file
+ * (= 32 bytes after the table + 16 bytes the GUID itself).
+ * If it's not found, silently abort the flash parsing.
*/
qemu_uuid_parse(OVMF_TABLE_FOOTER_GUID, &guid);
guid = qemu_uuid_bswap(guid); /* guids are LE */
- ptr = flash_ptr + flash_size - 48;
+ ptr = flash_ptr + flash_size - (bytes_after_table_footer + sizeof(guid));
if (!qemu_uuid_is_equal((QemuUUID *)ptr, &guid)) {
return;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v3 2/2] hw/i386: Replace magic number with field length calculation
2022-02-22 7:19 ` [PATCH v3 2/2] hw/i386: Replace magic number with field length calculation Dov Murik
@ 2022-02-22 9:25 ` Daniel P. Berrangé
0 siblings, 0 replies; 6+ messages in thread
From: Daniel P. Berrangé @ 2022-02-22 9:25 UTC (permalink / raw)
To: Dov Murik
Cc: Eduardo Habkost, Michael S. Tsirkin, James Bottomley,
Richard Henderson, qemu-devel, Philippe Mathieu-Daudé,
Tobin Feldman-Fitzthum, Gerd Hoffmann, Paolo Bonzini,
Dr. David Alan Gilbert
On Tue, Feb 22, 2022 at 07:19:06AM +0000, Dov Murik wrote:
> Replce the literal magic number 48 with length calculation (32 bytes at
> the end of the firmware after the table footer + 16 bytes of the OVMF
> table footer GUID).
>
> No functional change intended.
>
> Signed-off-by: Dov Murik <dovmurik@linux.ibm.com>
> ---
> hw/i386/pc_sysfw_ovmf.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-02-22 9:45 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-22 7:19 [PATCH v3 0/2] hw/i386: OVMF table parsing fixes Dov Murik
2022-02-22 7:19 ` [PATCH v3 1/2] hw/i386: Improve bounds checking in OVMF table parsing Dov Murik
2022-02-22 9:23 ` Daniel P. Berrangé
2022-02-22 9:43 ` Dr. David Alan Gilbert
2022-02-22 7:19 ` [PATCH v3 2/2] hw/i386: Replace magic number with field length calculation Dov Murik
2022-02-22 9:25 ` Daniel P. Berrangé
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).