fw_cfg: fix the life cycle and the name of "qemu_extra_params_fw"
PATCH 1/1 fw_cfg: fix the life cycle and the name of "qemu_extra_params_fw"
Commit 19bcc4bc3213 ("fw_cfg: Make qemu_extra_params_fw locally", 2019-01-04) changed the storage duration of the "qemu_extra_params_fw" array from static to automatic. This broke the interface contract on the fw_cfg_add_file() function, which is documented as follows, in "include/hw/nvram/fw_cfg.h":
Quoted 2 lines
[...] The data referenced by the starting pointer is only linked, NOT copied, into the data structure of the
fw_cfgdevice. [...]
As a result, when guest firmware fetches the "etc/boot-menu-wait" fw_cfg file, it now sees garbage. Fix the regression by changing the storage duration to allocated. (The call is reached at most once, on the realize path of the board-specific fw_cfg sysbus device.)
While at it, clean up the name and the assignment of the object as well.
--- hw/nvram/fw_cfg.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
hw/nvram/fw_cfg.c +5 -4
@@ -118,7 +118,6 @@ static void fw_cfg_bootsplash(FWCfgState *s) {const char *boot_splash_filename =NULL ;const char *boot_splash_time =NULL ; -uint8_t qemu_extra_params_fw[2 ];char *filename, *file_data;gsize file_size;int file_type;
@@ -132,6 +131,8 @@ static void fw_cfg_bootsplash(FWCfgState *s)/* insert splash time if user configurated */ if (boot_splash_time) {int64_t bst_val =qemu_opt_get_number (opts,"splash-time" ,-1 ); +uint16_t bst_le16; +/* validate the input */ if (bst_val <0 || bst_val >0xffff ) { error_report("splash-time is invalid,"
@@ -139,9 +140,9 @@ static void fw_cfg_bootsplash(FWCfgState *s)exit (1 ); }/* use little endian format */ - qemu_extra_params_fw[0 ] = (uint8_t )(bst_val &0xff ); - qemu_extra_params_fw[1 ] = (uint8_t )((bst_val >>8 ) &0xff ); -fw_cfg_add_file (s,"etc/boot-menu-wait" , qemu_extra_params_fw,2 ); + bst_le16 =cpu_to_le16 (bst_val); +fw_cfg_add_file (s,"etc/boot-menu-wait" , +g_memdup (&bst_le16,sizeof bst_le16),sizeof bst_le16); }/* insert splash file if user configurated */
Signature · 1 line
2.19.1.3.g30247aa5d201
Quoted 9 lines · Laszlo Ersek
Commit
19bcc4bc3213("fw_cfg: Makeqemu_extra_params_fwlocally", 2019-01-04) changed the storage duration of the "qemu_extra_params_fw" array from static to automatic. This broke the interface contract on thefw_cfg_add_file()function, which is documented as follows, in "include/hw/nvram/fw_cfg.h":Quoted 2 lines
[...] The data referenced by the starting pointer is only linked, NOT copied, into the data structure of the
fw_cfgdevice. [...]
Quoted 6 lines
As a result, when guest firmware fetches the "etc/boot-menu-wait"
fw_cfgfile, it now sees garbage. Fix the regression by changing the storage duration to allocated. (The call is reached at most once, on the realize path of the board-specificfw_cfgsysbus device.)While at it, clean up the name and the assignment of the object as well.
Quoted 47 lines
Cc Gerd Hoffmann <[email protected]>Cc Markus Armbruster <[email protected]>Cc Philippe Mathieu-Daudé <[email protected]>Fixes 19bcc4bc3213e78c303ad480a7a578f62258252dSigned-off-by Laszlo Ersek <[email protected]>--- hw/nvram/fw_cfg.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)hw/nvram/fw_cfg.c +5
-4@@ -118,7 +118,6 @@ static void fw_cfg_bootsplash(FWCfgState *s) {const char *boot_splash_filename =NULL ;const char *boot_splash_time =NULL ; -uint8_t qemu_extra_params_fw[2 ];char *filename, *file_data;gsize file_size;int file_type;@@ -132,6 +131,8 @@ static void fw_cfg_bootsplash(FWCfgState *s)/* insert splash time if user configurated */ if (boot_splash_time) {int64_t bst_val =qemu_opt_get_number (opts,"splash-time" ,-1 ); +uint16_t bst_le16; +/* validate the input */ if (bst_val <0 || bst_val >0xffff ) { error_report("splash-time is invalid,"@@ -139,9 +140,9 @@ static void fw_cfg_bootsplash(FWCfgState *s)exit (1 ); }/* use little endian format */ - qemu_extra_params_fw[0 ] = (uint8_t )(bst_val &0xff ); - qemu_extra_params_fw[1 ] = (uint8_t )((bst_val >>8 ) &0xff ); -fw_cfg_add_file (s,"etc/boot-menu-wait" , qemu_extra_params_fw,2 ); + bst_le16 =cpu_to_le16 (bst_val); +fw_cfg_add_file (s,"etc/boot-menu-wait" , +g_memdup (&bst_le16,sizeof bst_le16),sizeof bst_le16); }/* insert splash file if user configurated */ Signature · 1 line
2.19.1.3.g30247aa5d201
Li Qiang
Reviewed-byQuoted 10 lines · Gerd Hoffmann <[email protected]> 于2019年1月21日周一 下午3:22写道:
Quoted 9 lines · Laszlo Ersek
Commit
19bcc4bc3213("fw_cfg: Makeqemu_extra_params_fwlocally", 2019-01-04) changed the storage duration of the "qemu_extra_params_fw" array from static to automatic. This broke the interface contract on thefw_cfg_add_file()function, which is documented as follows, in "include/hw/nvram/fw_cfg.h":Quoted 2 lines
[...] The data referenced by the starting pointer is only linked, NOT copied, into the data structure of the
fw_cfgdevice. [...]
Quoted 16 lines
Quoted 6 lines
As a result, when guest firmware fetches the "etc/boot-menu-wait"
fw_cfgfile, it now sees garbage. Fix the regression by changing the storage duration to allocated. (The call is reached at most once, on the realize path of the board-specificfw_cfgsysbus device.)While at it, clean up the name and the assignment of the object as well.
Reviewed-by Gerd Hoffmann <[email protected]>Quoted 6 lines
Cc Gerd Hoffmann <[email protected]>Cc Markus Armbruster <[email protected]>Cc Philippe Mathieu-Daudé <[email protected]>Fixes 19bcc4bc3213e78c303ad480a7a578f62258252dSigned-off-by Laszlo Ersek <[email protected]>
Oh my fault.
So I think my patch:
-->http://lists.nongnu.org/archive/html/qemu-devel/2019-01/msg04896.html is useful to write this file entry test cases
Thanks,
Li Qiang
Quoted 45 lines
Quoted 26 lines
--- hw/nvram/fw_cfg.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)hw/nvram/fw_cfg.c +2
-1@@ -118,7 +118,6 @@ static void fw_cfg_bootsplash(FWCfgState *s) {const char *boot_splash_filename =NULL ;const char *boot_splash_time =NULL ; -uint8_t qemu_extra_params_fw[2 ];char *filename, *file_data;gsize file_size;int file_type;@@ -132,6 +131,8 @@ static void fw_cfg_bootsplash(FWCfgState *s)/* insert splash time if user configurated */ if (boot_splash_time) {int64_t bst_val =qemu_opt_get_number (opts,"splash-time" ,-1 ); +uint16_t bst_le16; +/* validate the input */ if (bst_val <0 || bst_val >0xffff ) { error_report("splash-time is invalid,"hw/nvram/fw_cfg.c static void fw_cfg_bootsplash(FWCfgState *s) · line 144
Quoted 6 lines
hw/nvram/fw_cfg.c +0
-3@@ -139,9 +140,9 @@ static void fw_cfg_bootsplash(FWCfgState *s)exit (1 ); }/* use little endian format */ - qemu_extra_params_fw[0 ] = (uint8_t )(bst_val &0xff ); - qemu_extra_params_fw[1 ] = (uint8_t )((bst_val >>8 ) &0xff ); - fw_cfg_add_file(s, "etc/boot-menu-wait", qemu_extra_params_fw,2);
hw/nvram/fw_cfg.c static void fw_cfg_bootsplash(FWCfgState *s)
Quoted 3 lines
hw/nvram/fw_cfg.c +3
-0+ bst_le16 =cpu_to_le16 (bst_val); + fw_cfg_add_file(s, "etc/boot-menu-wait", + g_memdup(&bst_le16, sizeof bst_le16), sizeof
bst_le16);Quoted 6 lines
hw/nvram/fw_cfg.c +0
-1}/* insert splash file if user configurated */ --2.19.1.3.g30247aa5d201
Quoted 16 lines · Laszlo Ersek
Commit
19bcc4bc3213("fw_cfg: Makeqemu_extra_params_fwlocally", 2019-01-04) changed the storage duration of the "qemu_extra_params_fw" array from static to automatic. This broke the interface contract on thefw_cfg_add_file()function, which is documented as follows, in "include/hw/nvram/fw_cfg.h":Quoted 2 lines
[...] The data referenced by the starting pointer is only linked, NOT copied, into the data structure of the
fw_cfgdevice. [...]As a result, when guest firmware fetches the "etc/boot-menu-wait"
fw_cfgfile, it now sees garbage. Fix the regression by changing the storage duration to allocated. (The call is reached at most once, on the realize path of the board-specificfw_cfgsysbus device.)While at it, clean up the name and the assignment of the object as well.
Quoted 8 lines
Cc Gerd Hoffmann <[email protected]>Cc Markus Armbruster <[email protected]>Cc Philippe Mathieu-Daudé <[email protected]>Fixes 19bcc4bc3213e78c303ad480a7a578f62258252dSigned-off-by Laszlo Ersek <[email protected]>--- hw/nvram/fw_cfg.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
Quoted 6 lines · Laszlo Ersek
Commit
19bcc4bc3213("fw_cfg: Makeqemu_extra_params_fwlocally", 2019-01-04) changed the storage duration of the "qemu_extra_params_fw" array from static to automatic. This broke the interface contract on thefw_cfg_add_file()function, which is documented as follows, in "include/hw/nvram/fw_cfg.h":
Quoted 7 lines
Quoted 2 lines
[...] The data referenced by the starting pointer is only linked, NOT copied, into the data structure of the
fw_cfgdevice. [...]As a result, when guest firmware fetches the "etc/boot-menu-wait"
fw_cfgfile, it now sees garbage. Fix the regression by changing the storage duration to allocated. (The call is reached at most once, on the realize path of the board-specificfw_cfgsysbus device.)
Hopefully you catched this in time. This also demonstrate my testing is poor. This will be improved.
Quoted 34 lines
While at it, clean up the name and the assignment of the object as well.
Cc Gerd Hoffmann <[email protected]>Cc Markus Armbruster <[email protected]>Cc Philippe Mathieu-Daudé <[email protected]>Fixes 19bcc4bc3213e78c303ad480a7a578f62258252dSigned-off-by Laszlo Ersek <[email protected]>--- hw/nvram/fw_cfg.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)hw/nvram/fw_cfg.c +2
-1@@ -118,7 +118,6 @@ static void fw_cfg_bootsplash(FWCfgState *s) {const char *boot_splash_filename =NULL ;const char *boot_splash_time =NULL ; -uint8_t qemu_extra_params_fw[2 ];char *filename, *file_data;gsize file_size;int file_type;@@ -132,6 +131,8 @@ static void fw_cfg_bootsplash(FWCfgState *s)/* insert splash time if user configurated */ if (boot_splash_time) {int64_t bst_val =qemu_opt_get_number (opts,"splash-time" ,-1 ); +uint16_t bst_le16; +/* validate the input */ if (bst_val <0 || bst_val >0xffff ) { error_report("splash-time is invalid,"
hw/nvram/fw_cfg.c static void fw_cfg_bootsplash(FWCfgState *s) · line 143
Quoted 7 lines
hw/nvram/fw_cfg.c +1
-3@@ -139,9 +140,9 @@ static void fw_cfg_bootsplash(FWCfgState *s)exit (1 ); }/* use little endian format */ - qemu_extra_params_fw[0 ] = (uint8_t )(bst_val &0xff ); - qemu_extra_params_fw[1 ] = (uint8_t )((bst_val >>8 ) &0xff ); -fw_cfg_add_file (s,"etc/boot-menu-wait" , qemu_extra_params_fw,2 ); + bst_le16 =cpu_to_le16 (bst_val);
I had a similar patch staged using the ldst API, however using the cpu_to API is more consistent with the rest of this file.
hw/nvram/fw_cfg.c static void fw_cfg_bootsplash(FWCfgState *s) · line 145
Quoted 2 lines
hw/nvram/fw_cfg.c +2
-0+fw_cfg_add_file (s,"etc/boot-menu-wait" , +g_memdup (&bst_le16,sizeof bst_le16),sizeof bst_le16);
Using the heap and not worrying about releasing it is also consistent with the rest of this file, so:
Sorry for having you going throught this bug, and thanks for fixing it!
Phil.
Quoted 4 lines
hw/nvram/fw_cfg.c +0
-0}/* insert splash file if user configurated */
Quoted 50 lines · Laszlo Ersek
Commit
19bcc4bc3213("fw_cfg: Makeqemu_extra_params_fwlocally", 2019-01-04) changed the storage duration of the "qemu_extra_params_fw" array from static to automatic. This broke the interface contract on thefw_cfg_add_file()function, which is documented as follows, in "include/hw/nvram/fw_cfg.h":Quoted 2 lines
[...] The data referenced by the starting pointer is only linked, NOT copied, into the data structure of the
fw_cfgdevice. [...]As a result, when guest firmware fetches the "etc/boot-menu-wait"
fw_cfgfile, it now sees garbage. Fix the regression by changing the storage duration to allocated. (The call is reached at most once, on the realize path of the board-specificfw_cfgsysbus device.)While at it, clean up the name and the assignment of the object as well.
Cc Gerd Hoffmann <[email protected]>Cc Markus Armbruster <[email protected]>Cc Philippe Mathieu-Daudé <[email protected]>Fixes 19bcc4bc3213e78c303ad480a7a578f62258252dSigned-off-by Laszlo Ersek <[email protected]>--- hw/nvram/fw_cfg.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)hw/nvram/fw_cfg.c +2
-1@@ -118,7 +118,6 @@ static void fw_cfg_bootsplash(FWCfgState *s) {const char *boot_splash_filename =NULL ;const char *boot_splash_time =NULL ; -uint8_t qemu_extra_params_fw[2 ];char *filename, *file_data;gsize file_size;int file_type;@@ -132,6 +131,8 @@ static void fw_cfg_bootsplash(FWCfgState *s)/* insert splash time if user configurated */ if (boot_splash_time) {int64_t bst_val =qemu_opt_get_number (opts,"splash-time" ,-1 ); +uint16_t bst_le16; +/* validate the input */ if (bst_val <0 || bst_val >0xffff ) { error_report("splash-time is invalid,"@@ -139,9 +140,9 @@ static void fw_cfg_bootsplash(FWCfgState *s)exit (1 ); }
hw/nvram/fw_cfg.c static void fw_cfg_bootsplash(FWCfgState *s) · line 148
Quoted 10 lines
hw/nvram/fw_cfg.c +3
-3/* use little endian format */ - qemu_extra_params_fw[0 ] = (uint8_t )(bst_val &0xff ); - qemu_extra_params_fw[1 ] = (uint8_t )((bst_val >>8 ) &0xff ); -fw_cfg_add_file (s,"etc/boot-menu-wait" , qemu_extra_params_fw,2 ); + bst_le16 =cpu_to_le16 (bst_val); +fw_cfg_add_file (s,"etc/boot-menu-wait" , +g_memdup (&bst_le16,sizeof bst_le16),sizeof bst_le16); }/* insert splash file if user configurated */
I hope a polite ping can't hurt; can we get this merged please?
Thanks
LAszlo
Quoted 59 lines · Laszlo Ersek
Quoted 58 lines · Laszlo Ersek
Commit
19bcc4bc3213("fw_cfg: Makeqemu_extra_params_fwlocally", 2019-01-04) changed the storage duration of the "qemu_extra_params_fw" array from static to automatic. This broke the interface contract on thefw_cfg_add_file()function, which is documented as follows, in "include/hw/nvram/fw_cfg.h":Quoted 2 lines
[...] The data referenced by the starting pointer is only linked, NOT copied, into the data structure of the
fw_cfgdevice. [...]As a result, when guest firmware fetches the "etc/boot-menu-wait"
fw_cfgfile, it now sees garbage. Fix the regression by changing the storage duration to allocated. (The call is reached at most once, on the realize path of the board-specificfw_cfgsysbus device.)While at it, clean up the name and the assignment of the object as well.
Cc Gerd Hoffmann <[email protected]>Cc Markus Armbruster <[email protected]>Cc Philippe Mathieu-Daudé <[email protected]>Fixes 19bcc4bc3213e78c303ad480a7a578f62258252dSigned-off-by Laszlo Ersek <[email protected]>--- hw/nvram/fw_cfg.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)hw/nvram/fw_cfg.c +5
-4@@ -118,7 +118,6 @@ static void fw_cfg_bootsplash(FWCfgState *s) {const char *boot_splash_filename =NULL ;const char *boot_splash_time =NULL ; -uint8_t qemu_extra_params_fw[2 ];char *filename, *file_data;gsize file_size;int file_type;@@ -132,6 +131,8 @@ static void fw_cfg_bootsplash(FWCfgState *s)/* insert splash time if user configurated */ if (boot_splash_time) {int64_t bst_val =qemu_opt_get_number (opts,"splash-time" ,-1 ); +uint16_t bst_le16; +/* validate the input */ if (bst_val <0 || bst_val >0xffff ) { error_report("splash-time is invalid,"@@ -139,9 +140,9 @@ static void fw_cfg_bootsplash(FWCfgState *s)exit (1 ); }/* use little endian format */ - qemu_extra_params_fw[0 ] = (uint8_t )(bst_val &0xff ); - qemu_extra_params_fw[1 ] = (uint8_t )((bst_val >>8 ) &0xff ); -fw_cfg_add_file (s,"etc/boot-menu-wait" , qemu_extra_params_fw,2 ); + bst_le16 =cpu_to_le16 (bst_val); +fw_cfg_add_file (s,"etc/boot-menu-wait" , +g_memdup (&bst_le16,sizeof bst_le16),sizeof bst_le16); }
Quoted 7 lines
hw/nvram/fw_cfg.c static void fw_cfg_bootsplash(FWCfgState *s) · line 148
Quoted 2 lines
hw/nvram/fw_cfg.c +0
-0/* insert splash file if user configurated */ I hope a polite ping can't hurt; can we get this merged please?
Thanks
LAszlo
Sure it does not hurt. I have it tagged for the next pull.
Quoted 65 lines · Michael S. Tsirkin
Quoted 64 lines · Laszlo Ersek
Quoted 50 lines · Laszlo Ersek
Commit
19bcc4bc3213("fw_cfg: Makeqemu_extra_params_fwlocally", 2019-01-04) changed the storage duration of the "qemu_extra_params_fw" array from static to automatic. This broke the interface contract on thefw_cfg_add_file()function, which is documented as follows, in "include/hw/nvram/fw_cfg.h":Quoted 2 lines
[...] The data referenced by the starting pointer is only linked, NOT copied, into the data structure of the
fw_cfgdevice. [...]As a result, when guest firmware fetches the "etc/boot-menu-wait"
fw_cfgfile, it now sees garbage. Fix the regression by changing the storage duration to allocated. (The call is reached at most once, on the realize path of the board-specificfw_cfgsysbus device.)While at it, clean up the name and the assignment of the object as well.
Cc Gerd Hoffmann <[email protected]>Cc Markus Armbruster <[email protected]>Cc Philippe Mathieu-Daudé <[email protected]>Fixes 19bcc4bc3213e78c303ad480a7a578f62258252dSigned-off-by Laszlo Ersek <[email protected]>--- hw/nvram/fw_cfg.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)hw/nvram/fw_cfg.c +2
-1@@ -118,7 +118,6 @@ static void fw_cfg_bootsplash(FWCfgState *s) {const char *boot_splash_filename =NULL ;const char *boot_splash_time =NULL ; -uint8_t qemu_extra_params_fw[2 ];char *filename, *file_data;gsize file_size;int file_type;@@ -132,6 +131,8 @@ static void fw_cfg_bootsplash(FWCfgState *s)/* insert splash time if user configurated */ if (boot_splash_time) {int64_t bst_val =qemu_opt_get_number (opts,"splash-time" ,-1 ); +uint16_t bst_le16; +/* validate the input */ if (bst_val <0 || bst_val >0xffff ) { error_report("splash-time is invalid,"@@ -139,9 +140,9 @@ static void fw_cfg_bootsplash(FWCfgState *s)exit (1 ); }hw/nvram/fw_cfg.c static void fw_cfg_bootsplash(FWCfgState *s) · line 148
Quoted 10 lines
hw/nvram/fw_cfg.c +3
-3/* use little endian format */ - qemu_extra_params_fw[0 ] = (uint8_t )(bst_val &0xff ); - qemu_extra_params_fw[1 ] = (uint8_t )((bst_val >>8 ) &0xff ); -fw_cfg_add_file (s,"etc/boot-menu-wait" , qemu_extra_params_fw,2 ); + bst_le16 =cpu_to_le16 (bst_val); +fw_cfg_add_file (s,"etc/boot-menu-wait" , +g_memdup (&bst_le16,sizeof bst_le16),sizeof bst_le16); }/* insert splash file if user configurated */ I hope a polite ping can't hurt; can we get this merged please?
Quoted 5 lines
Quoted 2 lines
Thanks
LAszloSure it does not hurt. I have it tagged for the next pull.
Thanks!
Laszlo