diff options
author | Laszlo Ersek | 2020-09-16 17:15:10 +0200 |
---|---|---|
committer | Philippe Mathieu-Daudé | 2020-09-18 17:18:18 +0200 |
commit | 4318432ccd3f7fb69b7169f39dcae3d4ee04f5ea (patch) | |
tree | 562f543ea47f121c5ab608405d7b66475a58e8fd /hw/nvram | |
parent | Merge remote-tracking branch 'remotes/legoater/tags/pull-aspeed-20200918' int... (diff) | |
download | qemu-4318432ccd3f7fb69b7169f39dcae3d4ee04f5ea.tar.gz qemu-4318432ccd3f7fb69b7169f39dcae3d4ee04f5ea.tar.xz qemu-4318432ccd3f7fb69b7169f39dcae3d4ee04f5ea.zip |
hw/nvram/fw_cfg: fix FWCfgDataGeneratorClass::get_data() consumption
The documentation on g_byte_array_free()
<https://developer.gnome.org/glib/stable/glib-Byte-Arrays.html#g-byte-array-free>
says:
> Returns
>
> the element data if free_segment is FALSE, otherwise NULL. The element
> data should be freed using g_free().
Because we currently call g_byte_array_free() with free_segment=TRUE, we
end up passing data=NULL to fw_cfg_add_file().
On the plus side, fw_cfg_data_read() and fw_cfg_dma_transfer() both deal
with NULL data gracefully: QEMU does not crash when the guest reads such
an item, the guest just gets a properly sized, but zero-filled blob.
However, the bug breaks UEFI HTTPS boot, as the IANA_TLS_CIPHER array,
generated otherwise correctly by the "tls-cipher-suites" object, is in
effect replaced with a zero blob.
Fix the issue by passing free_segment=FALSE to g_byte_array_free():
- the caller (fw_cfg_add_from_generator()) temporarily assumes ownership
of the generated byte array,
- then ownership of the byte array is transfered to fw_cfg, as
fw_cfg_add_file() links (not copies) "data" into fw_cfg.
Cc: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: "Philippe Mathieu-Daudé" <philmd@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Fixes: 3203148917d035b09f71986ac2eaa19a352d6d9d
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Message-Id: <20200916151510.22767-1-lersek@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Diffstat (limited to 'hw/nvram')
-rw-r--r-- | hw/nvram/fw_cfg.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c index f3a4728288..0e95d057fd 100644 --- a/hw/nvram/fw_cfg.c +++ b/hw/nvram/fw_cfg.c @@ -1056,7 +1056,7 @@ bool fw_cfg_add_from_generator(FWCfgState *s, const char *filename, return false; } size = array->len; - fw_cfg_add_file(s, filename, g_byte_array_free(array, TRUE), size); + fw_cfg_add_file(s, filename, g_byte_array_free(array, FALSE), size); return true; } |