yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-fw_cfg-Fix-boot-bootsplash-error-checking.patch

Pablo Greco e6a3ae
From f798645d16957453ee49a5a2945ed80eeb87cd15 Mon Sep 17 00:00:00 2001
Pablo Greco e6a3ae
From: Markus Armbruster <armbru@redhat.com>
Pablo Greco e6a3ae
Date: Mon, 7 Oct 2019 07:35:07 +0100
Pablo Greco e6a3ae
Subject: [PATCH 14/22] fw_cfg: Fix -boot bootsplash error checking
Pablo Greco e6a3ae
MIME-Version: 1.0
Pablo Greco e6a3ae
Content-Type: text/plain; charset=UTF-8
Pablo Greco e6a3ae
Content-Transfer-Encoding: 8bit
Pablo Greco e6a3ae
Pablo Greco e6a3ae
RH-Author: Markus Armbruster <armbru@redhat.com>
Pablo Greco e6a3ae
Message-id: <20191007073509.5887-3-armbru@redhat.com>
Pablo Greco e6a3ae
Patchwork-id: 90980
Pablo Greco e6a3ae
O-Subject: [RHEL-8.2.0 qemu-kvm PATCH v2 2/4] fw_cfg: Fix -boot bootsplash error checking
Pablo Greco e6a3ae
Bugzilla: 1607367
Pablo Greco e6a3ae
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
Pablo Greco e6a3ae
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Pablo Greco e6a3ae
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
Pablo Greco e6a3ae
Pablo Greco e6a3ae
From: Li Qiang <liq3ea@gmail.com>
Pablo Greco e6a3ae
Pablo Greco e6a3ae
fw_cfg_bootsplash() gets option parameter "splash-time"
Pablo Greco e6a3ae
with qemu_opt_get(), then converts it to an integer by hand.
Pablo Greco e6a3ae
It neglects to check that conversion for errors. This is
Pablo Greco e6a3ae
needlessly complicated and error-prone. But as "splash-time
Pablo Greco e6a3ae
not specified" is not the same as "splash-time=T" for any T,
Pablo Greco e6a3ae
we need use qemu_opt_get() to check if splash time exists.
Pablo Greco e6a3ae
This patch also make the qemu exit when finding or loading
Pablo Greco e6a3ae
splash file failed.
Pablo Greco e6a3ae
Pablo Greco e6a3ae
Signed-off-by: Li Qiang <liq3ea@gmail.com>
Pablo Greco e6a3ae
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Pablo Greco e6a3ae
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
Pablo Greco e6a3ae
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Pablo Greco e6a3ae
Message-Id: <1542777026-2788-2-git-send-email-liq3ea@gmail.com>
Pablo Greco e6a3ae
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Pablo Greco e6a3ae
(cherry picked from commit 6912bb0b3d3b140c70d8cdfd2dff77f9890d7f12)
Pablo Greco e6a3ae
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
Pablo Greco e6a3ae
---
Pablo Greco e6a3ae
 hw/nvram/fw_cfg.c | 35 +++++++++++++----------------------
Pablo Greco e6a3ae
 vl.c              |  2 +-
Pablo Greco e6a3ae
 2 files changed, 14 insertions(+), 23 deletions(-)
Pablo Greco e6a3ae
Pablo Greco e6a3ae
diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
Pablo Greco e6a3ae
index d35ac7b..d7185ea 100644
Pablo Greco e6a3ae
--- a/hw/nvram/fw_cfg.c
Pablo Greco e6a3ae
+++ b/hw/nvram/fw_cfg.c
Pablo Greco e6a3ae
@@ -117,47 +117,38 @@ error:
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
 static void fw_cfg_bootsplash(FWCfgState *s)
Pablo Greco e6a3ae
 {
Pablo Greco e6a3ae
-    int boot_splash_time = -1;
Pablo Greco e6a3ae
     const char *boot_splash_filename = NULL;
Pablo Greco e6a3ae
-    char *p;
Pablo Greco e6a3ae
+    const char *boot_splash_time = NULL;
Pablo Greco e6a3ae
     char *filename, *file_data;
Pablo Greco e6a3ae
     gsize file_size;
Pablo Greco e6a3ae
     int file_type;
Pablo Greco e6a3ae
-    const char *temp;
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
     /* get user configuration */
Pablo Greco e6a3ae
     QemuOptsList *plist = qemu_find_opts("boot-opts");
Pablo Greco e6a3ae
     QemuOpts *opts = QTAILQ_FIRST(&plist->head);
Pablo Greco e6a3ae
-    if (opts != NULL) {
Pablo Greco e6a3ae
-        temp = qemu_opt_get(opts, "splash");
Pablo Greco e6a3ae
-        if (temp != NULL) {
Pablo Greco e6a3ae
-            boot_splash_filename = temp;
Pablo Greco e6a3ae
-        }
Pablo Greco e6a3ae
-        temp = qemu_opt_get(opts, "splash-time");
Pablo Greco e6a3ae
-        if (temp != NULL) {
Pablo Greco e6a3ae
-            p = (char *)temp;
Pablo Greco e6a3ae
-            boot_splash_time = strtol(p, &p, 10);
Pablo Greco e6a3ae
-        }
Pablo Greco e6a3ae
-    }
Pablo Greco e6a3ae
+    boot_splash_filename = qemu_opt_get(opts, "splash");
Pablo Greco e6a3ae
+    boot_splash_time = qemu_opt_get(opts, "splash-time");
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
     /* insert splash time if user configurated */
Pablo Greco e6a3ae
-    if (boot_splash_time >= 0) {
Pablo Greco e6a3ae
+    if (boot_splash_time) {
Pablo Greco e6a3ae
+        int64_t bst_val = qemu_opt_get_number(opts, "splash-time", -1);
Pablo Greco e6a3ae
         /* validate the input */
Pablo Greco e6a3ae
-        if (boot_splash_time > 0xffff) {
Pablo Greco e6a3ae
-            error_report("splash time is big than 65535, force it to 65535.");
Pablo Greco e6a3ae
-            boot_splash_time = 0xffff;
Pablo Greco e6a3ae
+        if (bst_val < 0 || bst_val > 0xffff) {
Pablo Greco e6a3ae
+            error_report("splash-time is invalid,"
Pablo Greco e6a3ae
+                         "it should be a value between 0 and 65535");
Pablo Greco e6a3ae
+            exit(1);
Pablo Greco e6a3ae
         }
Pablo Greco e6a3ae
         /* use little endian format */
Pablo Greco e6a3ae
-        qemu_extra_params_fw[0] = (uint8_t)(boot_splash_time & 0xff);
Pablo Greco e6a3ae
-        qemu_extra_params_fw[1] = (uint8_t)((boot_splash_time >> 8) & 0xff);
Pablo Greco e6a3ae
+        qemu_extra_params_fw[0] = (uint8_t)(bst_val & 0xff);
Pablo Greco e6a3ae
+        qemu_extra_params_fw[1] = (uint8_t)((bst_val >> 8) & 0xff);
Pablo Greco e6a3ae
         fw_cfg_add_file(s, "etc/boot-menu-wait", qemu_extra_params_fw, 2);
Pablo Greco e6a3ae
     }
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
     /* insert splash file if user configurated */
Pablo Greco e6a3ae
-    if (boot_splash_filename != NULL) {
Pablo Greco e6a3ae
+    if (boot_splash_filename) {
Pablo Greco e6a3ae
         filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, boot_splash_filename);
Pablo Greco e6a3ae
         if (filename == NULL) {
Pablo Greco e6a3ae
-            error_report("failed to find file '%s'.", boot_splash_filename);
Pablo Greco e6a3ae
+            error_report("failed to find file '%s'", boot_splash_filename);
Pablo Greco e6a3ae
             return;
Pablo Greco e6a3ae
         }
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
diff --git a/vl.c b/vl.c
Pablo Greco e6a3ae
index c778594..e2212f5 100644
Pablo Greco e6a3ae
--- a/vl.c
Pablo Greco e6a3ae
+++ b/vl.c
Pablo Greco e6a3ae
@@ -364,7 +364,7 @@ static QemuOptsList qemu_boot_opts = {
Pablo Greco e6a3ae
             .type = QEMU_OPT_STRING,
Pablo Greco e6a3ae
         }, {
Pablo Greco e6a3ae
             .name = "splash-time",
Pablo Greco e6a3ae
-            .type = QEMU_OPT_STRING,
Pablo Greco e6a3ae
+            .type = QEMU_OPT_NUMBER,
Pablo Greco e6a3ae
         }, {
Pablo Greco e6a3ae
             .name = "reboot-timeout",
Pablo Greco e6a3ae
             .type = QEMU_OPT_STRING,
Pablo Greco e6a3ae
-- 
Pablo Greco e6a3ae
1.8.3.1
Pablo Greco e6a3ae