hw/nvram/fw_cfg: fix FWCfgDataGeneratorClass::get_data() consumption
PATCH 1/1 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:
Quoted 4 lines
Returns
the element data if
free_segmentis FALSE, otherwise NULL. The element data should be freed usingg_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.
--- hw/nvram/fw_cfg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/nvram/fw_cfg.c +1 -1
@@ -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; }
Signature · 1 line
2.19.1.3.g30247aa5d201
Quoted 11 lines · Laszlo Ersek
The documentation on
g_byte_array_free()
<https://developer.gnome.org/glib/stable/glib-Byte-Arrays.html#g-byte-array-free>
says:Quoted 4 lines
Returns
the element data if
free_segmentis FALSE, otherwise NULL. The element data should be freed usingg_free().Because we currently call
g_byte_array_free()with free_segment=TRUE, we end up passing data=NULL tofw_cfg_add_file().
Mea culpa...
Quoted 9 lines
On the plus side,
fw_cfg_data_read()andfw_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_CIPHERarray, generated otherwise correctly by the "tls-cipher-suites" object, is in effect replaced with a zero blob.
Quoted 7 lines
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, asfw_cfg_add_file()links (not copies) "data" intofw_cfg.
Thanks!
Quoted 24 lines
Cc "Daniel P. Berrangé" <[email protected]>Cc "Philippe Mathieu-Daudé" <[email protected]>Cc Gerd Hoffmann <[email protected]>Fixes 3203148917d035b09f71986ac2eaa19a352d6d9dSigned-off-by Laszlo Ersek <[email protected]>--- hw/nvram/fw_cfg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/nvram/fw_cfg.c +1
-1@@ -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; }
Quoted 28 lines · Laszlo Ersek
The documentation on
g_byte_array_free()
<https://developer.gnome.org/glib/stable/glib-Byte-Arrays.html#g-byte-array-free>
says:Quoted 4 lines
Returns
the element data if
free_segmentis FALSE, otherwise NULL. The element data should be freed usingg_free().Because we currently call
g_byte_array_free()with free_segment=TRUE, we end up passing data=NULL tofw_cfg_add_file().On the plus side,
fw_cfg_data_read()andfw_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_CIPHERarray, 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, asfw_cfg_add_file()links (not copies) "data" intofw_cfg.
Quoted 8 lines
Cc "Daniel P. Berrangé" <[email protected]>Cc "Philippe Mathieu-Daudé" <[email protected]>Cc Gerd Hoffmann <[email protected]>Fixes 3203148917d035b09f71986ac2eaa19a352d6d9dSigned-off-by Laszlo Ersek <[email protected]>--- hw/nvram/fw_cfg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Regards,
Daniel
Signature · 3 lines
|: 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 :|
Philippe Mathieu-Daudé
AppliedQuoted 43 lines · Laszlo Ersek
The documentation on
g_byte_array_free()
<https://developer.gnome.org/glib/stable/glib-Byte-Arrays.html#g-byte-array-free>
says:Quoted 4 lines
Returns
the element data if
free_segmentis FALSE, otherwise NULL. The element data should be freed usingg_free().Because we currently call
g_byte_array_free()with free_segment=TRUE, we end up passing data=NULL tofw_cfg_add_file().On the plus side,
fw_cfg_data_read()andfw_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_CIPHERarray, 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, asfw_cfg_add_file()links (not copies) "data" intofw_cfg.Cc "Daniel P. Berrangé" <[email protected]>Cc "Philippe Mathieu-Daudé" <[email protected]>Cc Gerd Hoffmann <[email protected]>Fixes 3203148917d035b09f71986ac2eaa19a352d6d9dSigned-off-by Laszlo Ersek <[email protected]>--- hw/nvram/fw_cfg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/nvram/fw_cfg.c +0
-0
hw/nvram/fw_cfg.c bool fw_cfg_add_from_generator(FWCfgState *s, const char *filename, · line 1062
Quoted 8 lines
hw/nvram/fw_cfg.c +1
-1@@ -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; }
Thanks, applied to my fw_cfg tree.