Skip to contentSkip to conversation

multiboot: bss_end_addr can be zero / cleanup

PATCH In review Jack Schwartz 6 participants 25 messages Dec 21, 2017 – Mar 15, 2018

lore
Share & tools
lore
#0 lore raw

cover multiboot: bss_end_addr can be zero / cleanup

Properly account for the possibility of multiboot kernels with a zero bss_end_addr. The Multiboot Specification, section 3.1.3 allows for kernels without a bss section, by allowing a zeroed bss_end_addr multiboot header field.

Do some cleanup to multiboot.c as well:
- Remove some unused variables.
- Use more intuitive header names when displaying fields in messages.
- Change fprintf(stderr...) to error_report

Testing:
1) Ran the "make check" test suite.
2) Booted multiboot kernel with bss_end_addr=0. (I rolled my own grub multiboot.elf test "kernel" by modifying source.) Verified with gdb that new code that reads addresses/offsets from multiboot header was accessed.
3) Booted multiboot kernel with non-zero bss_end_addr.
4) Uncommented DEBUG_MULTIBOOT in multiboot.c and verified messages worked.
5) Code has soaked in an internal repo for two months.

Thanks,
Jack

Jack Schwartz (4):
multiboot: bss_end_addr can be zero
multiboot: Remove unused variables from multiboot.c
multiboot: Use header names when displaying fields
multiboot: fprintf(stderr...) -> error_report()

 hw/i386/multiboot.c | 77 ++++++++++++++++++++++++++---------------------------
 1 file changed, 38 insertions(+), 39 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/4 multiboot: bss_end_addr can be zero

The multiboot spec (https://www.gnu.org/software/grub/manual/multiboot/),
section 3.1.3, allows for bss_end_addr to be zero.

A zero bss_end_addr signifies there is no .bss section.

---
 hw/i386/multiboot.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
hw/i386/multiboot.c +10 -8
index c7b70c9..ff2733d 100644
@@ -233,12 +233,6 @@ int load_multiboot(FWCfgState *fw_cfg,
         mh_entry_addr = ldl_p(header+i+28);
 
         if (mh_load_end_addr) {
-            if (mh_bss_end_addr < mh_load_addr) {
-                fprintf(stderr, "invalid mh_bss_end_addr address\n");
-                exit(1);
-            }
-            mb_kernel_size = mh_bss_end_addr - mh_load_addr;
-
             if (mh_load_end_addr < mh_load_addr) {
                 fprintf(stderr, "invalid mh_load_end_addr address\n");
                 exit(1);
@@ -249,8 +243,16 @@ int load_multiboot(FWCfgState *fw_cfg,
                 fprintf(stderr, "invalid kernel_file_size\n");
                 exit(1);
             }
-            mb_kernel_size = kernel_file_size - mb_kernel_text_offset;
-            mb_load_size = mb_kernel_size;
+            mb_load_size = kernel_file_size - mb_kernel_text_offset;
+        }
+        if (mh_bss_end_addr) {
+            if (mh_bss_end_addr < (mh_load_addr + mb_load_size)) {
+                fprintf(stderr, "invalid mh_bss_end_addr address\n");
+                exit(1);
+            }
+            mb_kernel_size = mh_bss_end_addr - mh_load_addr;
+        } else {
+            mb_kernel_size = mb_load_size;
         }
 
         /* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_VBE.
Signature · 1 line
1.8.3.1
Reviewed-by Prasad J Pandit on v1 1/4
#2 lore raw

Re: [Qemu-devel] [PATCH QEMU v1 1/4] multiboot: bss_end_addr can be zero

+-- On Thu, 21 Dec 2017, Jack Schwartz wrote --+
| The multiboot spec (https://www.gnu.org/software/grub/manual/multiboot/),
| section 3.1.3, allows for bss_end_addr to be zero.
| 
| A zero bss_end_addr signifies there is no .bss section.
| 
| Suggested-by: Daniel Kiper <[email protected]>
| Signed-off-by: Jack Schwartz <[email protected]>
| Reviewed-by: Daniel Kiper <[email protected]>
| ---
|  hw/i386/multiboot.c | 18 ++++++++++--------
|  1 file changed, 10 insertions(+), 8 deletions(-)
| 
| diff --git a/hw/i386/multiboot.c b/hw/i386/multiboot.c
| index c7b70c9..ff2733d 100644
| --- a/hw/i386/multiboot.c
| +++ b/hw/i386/multiboot.c
| @@ -233,12 +233,6 @@ int load_multiboot(FWCfgState *fw_cfg,
|          mh_entry_addr = ldl_p(header+i+28);
|  
|          if (mh_load_end_addr) {
| -            if (mh_bss_end_addr < mh_load_addr) {
| -                fprintf(stderr, "invalid mh_bss_end_addr address\n");
| -                exit(1);
| -            }
| -            mb_kernel_size = mh_bss_end_addr - mh_load_addr;
| -
|              if (mh_load_end_addr < mh_load_addr) {
|                  fprintf(stderr, "invalid mh_load_end_addr address\n");
|                  exit(1);
| @@ -249,8 +243,16 @@ int load_multiboot(FWCfgState *fw_cfg,
|                  fprintf(stderr, "invalid kernel_file_size\n");
|                  exit(1);
|              }
| -            mb_kernel_size = kernel_file_size - mb_kernel_text_offset;
| -            mb_load_size = mb_kernel_size;
| +            mb_load_size = kernel_file_size - mb_kernel_text_offset;
| +        }
| +        if (mh_bss_end_addr) {
| +            if (mh_bss_end_addr < (mh_load_addr + mb_load_size)) {
| +                fprintf(stderr, "invalid mh_bss_end_addr address\n");
| +                exit(1);
| +            }
| +            mb_kernel_size = mh_bss_end_addr - mh_load_addr;
| +        } else {
| +            mb_kernel_size = mb_load_size;
|          }
|  
|          /* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_VBE.

Looks good.

Thank you.
--
Prasad J Pandit / Red Hat Product Security Team
47AF CE69 3A90 54AA 9045 1053 DD13 3D32 FE5B 041F

#3 lore raw

PATCH 2/4 multiboot: Remove unused variables from multiboot.c

In reply to Jack Schwartz

Remove unused variables: mh_mode_type, mh_width, mh_height, mh_depth

---
 hw/i386/multiboot.c | 6 ------
 1 file changed, 6 deletions(-)
hw/i386/multiboot.c +0 -6
index ff2733d..964feaf 100644
@@ -255,12 +255,6 @@ int load_multiboot(FWCfgState *fw_cfg,
             mb_kernel_size = mb_load_size;
         }
 
-        /* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_VBE.
-        uint32_t mh_mode_type = ldl_p(header+i+32);
-        uint32_t mh_width = ldl_p(header+i+36);
-        uint32_t mh_height = ldl_p(header+i+40);
-        uint32_t mh_depth = ldl_p(header+i+44); */
-
         mb_debug("multiboot: mh_header_addr = %#x\n", mh_header_addr);
         mb_debug("multiboot: mh_load_addr = %#x\n", mh_load_addr);
         mb_debug("multiboot: mh_load_end_addr = %#x\n", mh_load_end_addr);
Signature · 1 line
1.8.3.1
Reviewed-by Prasad J Pandit on v1 2/4
#4 lore raw

Re: [Qemu-devel] [PATCH QEMU v1 2/4] multiboot: Remove unused variables from multiboot.c

+-- On Thu, 21 Dec 2017, Jack Schwartz wrote --+
| Remove unused variables: mh_mode_type, mh_width, mh_height, mh_depth
| 
| Signed-off-by: Jack Schwartz <[email protected]>
| Reviewed-by: Daniel Kiper <[email protected]>
| ---
|  hw/i386/multiboot.c | 6 ------
|  1 file changed, 6 deletions(-)
| 
| diff --git a/hw/i386/multiboot.c b/hw/i386/multiboot.c
| index ff2733d..964feaf 100644
| --- a/hw/i386/multiboot.c
| +++ b/hw/i386/multiboot.c
| @@ -255,12 +255,6 @@ int load_multiboot(FWCfgState *fw_cfg,
|              mb_kernel_size = mb_load_size;
|          }
|  
| -        /* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_VBE.
| -        uint32_t mh_mode_type = ldl_p(header+i+32);
| -        uint32_t mh_width = ldl_p(header+i+36);
| -        uint32_t mh_height = ldl_p(header+i+40);
| -        uint32_t mh_depth = ldl_p(header+i+44); */
| -

+1 They are anyway comments.

Thank you.
--
Prasad J Pandit / Red Hat Product Security Team
47AF CE69 3A90 54AA 9045 1053 DD13 3D32 FE5B 041F

#5 lore raw

PATCH 3/4 multiboot: Use header names when displaying fields

In reply to Jack Schwartz

Refer to field names when displaying fields in printf and debug statements.

---
 hw/i386/multiboot.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
hw/i386/multiboot.c +8 -8
index 964feaf..818728b 100644
@@ -224,7 +224,7 @@ int load_multiboot(FWCfgState *fw_cfg,
 
         mh_load_addr = ldl_p(header+i+16);
         if (mh_header_addr < mh_load_addr) {
-            fprintf(stderr, "invalid mh_load_addr address\n");
+            fprintf(stderr, "invalid load_addr address\n");
             exit(1);
         }
 
@@ -234,7 +234,7 @@ int load_multiboot(FWCfgState *fw_cfg,
 
         if (mh_load_end_addr) {
             if (mh_load_end_addr < mh_load_addr) {
-                fprintf(stderr, "invalid mh_load_end_addr address\n");
+                fprintf(stderr, "invalid load_end_addr address\n");
                 exit(1);
             }
             mb_load_size = mh_load_end_addr - mh_load_addr;
@@ -247,7 +247,7 @@ int load_multiboot(FWCfgState *fw_cfg,
         }
         if (mh_bss_end_addr) {
             if (mh_bss_end_addr < (mh_load_addr + mb_load_size)) {
-                fprintf(stderr, "invalid mh_bss_end_addr address\n");
+                fprintf(stderr, "invalid bss_end_addr address\n");
                 exit(1);
             }
             mb_kernel_size = mh_bss_end_addr - mh_load_addr;
@@ -255,10 +255,10 @@ int load_multiboot(FWCfgState *fw_cfg,
             mb_kernel_size = mb_load_size;
         }
 
-        mb_debug("multiboot: mh_header_addr = %#x\n", mh_header_addr);
-        mb_debug("multiboot: mh_load_addr = %#x\n", mh_load_addr);
-        mb_debug("multiboot: mh_load_end_addr = %#x\n", mh_load_end_addr);
-        mb_debug("multiboot: mh_bss_end_addr = %#x\n", mh_bss_end_addr);
+        mb_debug("multiboot: header_addr = %#x\n", mh_header_addr);
+        mb_debug("multiboot: load_addr = %#x\n", mh_load_addr);
+        mb_debug("multiboot: load_end_addr = %#x\n", mh_load_end_addr);
+        mb_debug("multiboot: bss_end_addr = %#x\n", mh_bss_end_addr);
         mb_debug("qemu: loading multiboot kernel (%#x bytes) at %#x\n",
                  mb_load_size, mh_load_addr);
 
@@ -361,7 +361,7 @@ int load_multiboot(FWCfgState *fw_cfg,
     stl_p(bootinfo + MBI_BOOT_DEVICE, 0x8000ffff); /* XXX: use the -boot switch? */
     stl_p(bootinfo + MBI_MMAP_ADDR,   ADDR_E820_MAP);
 
-    mb_debug("multiboot: mh_entry_addr = %#x\n", mh_entry_addr);
+    mb_debug("multiboot: entry_addr = %#x\n", mh_entry_addr);
     mb_debug("           mb_buf_phys   = "TARGET_FMT_plx"\n", mbs.mb_buf_phys);
     mb_debug("           mod_start     = "TARGET_FMT_plx"\n", mbs.mb_buf_phys + mbs.offset_mods);
     mb_debug("           mb_mods_count = %d\n", mbs.mb_mods_count);
Signature · 1 line
1.8.3.1
#6 lore raw

Re: [Qemu-devel] [PATCH QEMU v1 3/4] multiboot: Use header names when displaying fields

+-- On Thu, 21 Dec 2017, Jack Schwartz wrote --+
| Refer to field names when displaying fields in printf and debug statements.

I wonder if it's required; Having variable names is helpful while going through code.

Thank you.
--
Prasad J Pandit / Red Hat Product Security Team
47AF CE69 3A90 54AA 9045 1053 DD13 3D32 FE5B 041F

#7 lore raw

PATCH 4/4 multiboot: fprintf(stderr...) -> error_report()

In reply to Jack Schwartz

Change all fprintf(stderr...) calls in hw/i386/multiboot.c to call error_report() instead, including the mb_debug macro. Remove the "\n" from strings passed to all modified calls, since error_report() appends one.

---
 hw/i386/multiboot.c | 55 ++++++++++++++++++++++++++++-------------------------
 1 file changed, 29 insertions(+), 26 deletions(-)
hw/i386/multiboot.c +29 -26
index 818728b..d9a0a95 100644
@@ -31,12 +31,13 @@
 #include "hw/loader.h"
 #include "elf.h"
 #include "sysemu/sysemu.h"
+#include "qemu/error-report.h"
 
 /* Show multiboot debug output */
 //#define DEBUG_MULTIBOOT
 
 #ifdef DEBUG_MULTIBOOT
-#define mb_debug(a...) fprintf(stderr, ## a)
+#define mb_debug(a...) error_report(a)
 #else
 #define mb_debug(a...)
 #endif
@@ -137,7 +138,7 @@ static void mb_add_mod(MultibootState *s,
     stl_p(p + MB_MOD_END,     end);
     stl_p(p + MB_MOD_CMDLINE, cmdline_phys);
 
-    mb_debug("mod%02d: "TARGET_FMT_plx" - "TARGET_FMT_plx"\n",
+    mb_debug("mod%02d: "TARGET_FMT_plx" - "TARGET_FMT_plx,
              s->mb_mods_count, start, end);
 
     s->mb_mods_count++;
@@ -179,12 +180,12 @@ int load_multiboot(FWCfgState *fw_cfg,
     if (!is_multiboot)
         return 0; /* no multiboot */
 
-    mb_debug("qemu: I believe we found a multiboot image!\n");
+    mb_debug("qemu: I believe we found a multiboot image!");
     memset(bootinfo, 0, sizeof(bootinfo));
     memset(&mbs, 0, sizeof(mbs));
 
     if (flags & 0x00000004) { /* MULTIBOOT_HEADER_HAS_VBE */
-        fprintf(stderr, "qemu: multiboot knows VBE. we don't.\n");
+        error_report("qemu: multiboot knows VBE. we don't.");
     }
     if (!(flags & 0x00010000)) { /* MULTIBOOT_HEADER_HAS_ADDR */
         uint64_t elf_entry;
@@ -193,7 +194,7 @@ int load_multiboot(FWCfgState *fw_cfg,
         fclose(f);
 
         if (((struct elf64_hdr*)header)->e_machine == EM_X86_64) {
-            fprintf(stderr, "Cannot load x86-64 image, give a 32bit one.\n");
+            error_report("Cannot load x86-64 image, give a 32bit one.");
             exit(1);
         }
 
@@ -201,7 +202,7 @@ int load_multiboot(FWCfgState *fw_cfg,
                                &elf_low, &elf_high, 0, I386_ELF_MACHINE,
                                0, 0);
         if (kernel_size < 0) {
-            fprintf(stderr, "Error while loading elf kernel\n");
+            error_report("Error while loading elf kernel");
             exit(1);
         }
         mh_load_addr = elf_low;
@@ -210,12 +211,13 @@ int load_multiboot(FWCfgState *fw_cfg,
 
         mbs.mb_buf = g_malloc(mb_kernel_size);
         if (rom_copy(mbs.mb_buf, mh_load_addr, mb_kernel_size) != mb_kernel_size) {
-            fprintf(stderr, "Error while fetching elf kernel from rom\n");
+            error_report("Error while fetching elf kernel from rom");
             exit(1);
         }
 
-        mb_debug("qemu: loading multiboot-elf kernel (%#x bytes) with entry %#zx\n",
-                  mb_kernel_size, (size_t)mh_entry_addr);
+        mb_debug("qemu: loading multiboot-elf kernel "
+                 "(%#x bytes) with entry %#zx",
+                 mb_kernel_size, (size_t)mh_entry_addr);
     } else {
         /* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_ADDR. */
         uint32_t mh_header_addr = ldl_p(header+i+12);
@@ -224,7 +226,7 @@ int load_multiboot(FWCfgState *fw_cfg,
 
         mh_load_addr = ldl_p(header+i+16);
         if (mh_header_addr < mh_load_addr) {
-            fprintf(stderr, "invalid load_addr address\n");
+            error_report("invalid load_addr address");
             exit(1);
         }
 
@@ -234,20 +236,20 @@ int load_multiboot(FWCfgState *fw_cfg,
 
         if (mh_load_end_addr) {
             if (mh_load_end_addr < mh_load_addr) {
-                fprintf(stderr, "invalid load_end_addr address\n");
+                error_report("invalid load_end_addr address");
                 exit(1);
             }
             mb_load_size = mh_load_end_addr - mh_load_addr;
         } else {
             if (kernel_file_size < mb_kernel_text_offset) {
-                fprintf(stderr, "invalid kernel_file_size\n");
+                error_report("invalid kernel_file_size");
                 exit(1);
             }
             mb_load_size = kernel_file_size - mb_kernel_text_offset;
         }
         if (mh_bss_end_addr) {
             if (mh_bss_end_addr < (mh_load_addr + mb_load_size)) {
-                fprintf(stderr, "invalid bss_end_addr address\n");
+                error_report("invalid bss_end_addr address");
                 exit(1);
             }
             mb_kernel_size = mh_bss_end_addr - mh_load_addr;
@@ -255,17 +257,17 @@ int load_multiboot(FWCfgState *fw_cfg,
             mb_kernel_size = mb_load_size;
         }
 
-        mb_debug("multiboot: header_addr = %#x\n", mh_header_addr);
-        mb_debug("multiboot: load_addr = %#x\n", mh_load_addr);
-        mb_debug("multiboot: load_end_addr = %#x\n", mh_load_end_addr);
-        mb_debug("multiboot: bss_end_addr = %#x\n", mh_bss_end_addr);
-        mb_debug("qemu: loading multiboot kernel (%#x bytes) at %#x\n",
+        mb_debug("multiboot: header_addr = %#x", mh_header_addr);
+        mb_debug("multiboot: load_addr = %#x", mh_load_addr);
+        mb_debug("multiboot: load_end_addr = %#x", mh_load_end_addr);
+        mb_debug("multiboot: bss_end_addr = %#x", mh_bss_end_addr);
+        mb_debug("qemu: loading multiboot kernel (%#x bytes) at %#x",
                  mb_load_size, mh_load_addr);
 
         mbs.mb_buf = g_malloc(mb_kernel_size);
         fseek(f, mb_kernel_text_offset, SEEK_SET);
         if (fread(mbs.mb_buf, 1, mb_load_size, f) != mb_load_size) {
-            fprintf(stderr, "fread() failed\n");
+            error_report("fread() failed");
             exit(1);
         }
         memset(mbs.mb_buf + mb_load_size, 0, mb_kernel_size - mb_load_size);
@@ -319,10 +321,10 @@ int load_multiboot(FWCfgState *fw_cfg,
             hwaddr c = mb_add_cmdline(&mbs, tmpbuf);
             if ((next_space = strchr(tmpbuf, ' ')))
                 *next_space = '\0';
-            mb_debug("multiboot loading module: %s\n", tmpbuf);
+            mb_debug("multiboot loading module: %s", tmpbuf);
             mb_mod_length = get_image_size(tmpbuf);
             if (mb_mod_length < 0) {
-                fprintf(stderr, "Failed to open file '%s'\n", tmpbuf);
+                error_report("Failed to open file '%s'", tmpbuf);
                 exit(1);
             }
 
@@ -333,7 +335,7 @@ int load_multiboot(FWCfgState *fw_cfg,
             mb_add_mod(&mbs, mbs.mb_buf_phys + offs,
                        mbs.mb_buf_phys + offs + mb_mod_length, c);
 
-            mb_debug("mod_start: %p\nmod_end:   %p\n  cmdline: "TARGET_FMT_plx"\n",
+            mb_debug("mod_start: %p\nmod_end:   %p\n  cmdline: "TARGET_FMT_plx,
                      (char *)mbs.mb_buf + offs,
                      (char *)mbs.mb_buf + offs + mb_mod_length, c);
             initrd_filename = next_initrd+1;
@@ -361,10 +363,11 @@ int load_multiboot(FWCfgState *fw_cfg,
     stl_p(bootinfo + MBI_BOOT_DEVICE, 0x8000ffff); /* XXX: use the -boot switch? */
     stl_p(bootinfo + MBI_MMAP_ADDR,   ADDR_E820_MAP);
 
-    mb_debug("multiboot: entry_addr = %#x\n", mh_entry_addr);
-    mb_debug("           mb_buf_phys   = "TARGET_FMT_plx"\n", mbs.mb_buf_phys);
-    mb_debug("           mod_start     = "TARGET_FMT_plx"\n", mbs.mb_buf_phys + mbs.offset_mods);
-    mb_debug("           mb_mods_count = %d\n", mbs.mb_mods_count);
+    mb_debug("multiboot: entry_addr = %#x", mh_entry_addr);
+    mb_debug("           mb_buf_phys   = "TARGET_FMT_plx, mbs.mb_buf_phys);
+    mb_debug("           mod_start     = "TARGET_FMT_plx,
+             mbs.mb_buf_phys + mbs.offset_mods);
+    mb_debug("           mb_mods_count = %d", mbs.mb_mods_count);
 
     /* save bootinfo off the stack */
     mb_bootinfo_data = g_memdup(bootinfo, sizeof(bootinfo));
Signature · 1 line
1.8.3.1
#8 lore raw

Re: [Qemu-devel] [PATCH QEMU v1 4/4] multiboot: fprintf(stderr...) -> error_report()

+-- On Thu, 21 Dec 2017, Jack Schwartz wrote --+
| Change all fprintf(stderr...) calls in hw/i386/multiboot.c to call
| error_report() instead, including the mb_debug macro.  Remove the "\n"
| from strings passed to all modified calls, since error_report() appends
| one.
| 
| Signed-off-by: Jack Schwartz <[email protected]>
| Reviewed-by: Daniel Kiper <[email protected]>
| ---
|  hw/i386/multiboot.c | 55 ++++++++++++++++++++++++++++-------------------------
|  1 file changed, 29 insertions(+), 26 deletions(-)
| 
| diff --git a/hw/i386/multiboot.c b/hw/i386/multiboot.c
| index 818728b..d9a0a95 100644
| --- a/hw/i386/multiboot.c
| +++ b/hw/i386/multiboot.c
| @@ -31,12 +31,13 @@
|  #include "hw/loader.h"
|  #include "elf.h"
|  #include "sysemu/sysemu.h"
| +#include "qemu/error-report.h"
|  
|  /* Show multiboot debug output */
|  //#define DEBUG_MULTIBOOT
|  
|  #ifdef DEBUG_MULTIBOOT
| -#define mb_debug(a...) fprintf(stderr, ## a)
| +#define mb_debug(a...) error_report(a)
|  #else
|  #define mb_debug(a...)
|  #endif
| @@ -137,7 +138,7 @@ static void mb_add_mod(MultibootState *s,
|      stl_p(p + MB_MOD_END,     end);
|      stl_p(p + MB_MOD_CMDLINE, cmdline_phys);
|  
| -    mb_debug("mod%02d: "TARGET_FMT_plx" - "TARGET_FMT_plx"\n",
| +    mb_debug("mod%02d: "TARGET_FMT_plx" - "TARGET_FMT_plx,
|               s->mb_mods_count, start, end);
|  
|      s->mb_mods_count++;
| @@ -179,12 +180,12 @@ int load_multiboot(FWCfgState *fw_cfg,
|      if (!is_multiboot)
|          return 0; /* no multiboot */
|  
| -    mb_debug("qemu: I believe we found a multiboot image!\n");
| +    mb_debug("qemu: I believe we found a multiboot image!");
|      memset(bootinfo, 0, sizeof(bootinfo));
|      memset(&mbs, 0, sizeof(mbs));
|  
|      if (flags & 0x00000004) { /* MULTIBOOT_HEADER_HAS_VBE */
| -        fprintf(stderr, "qemu: multiboot knows VBE. we don't.\n");
| +        error_report("qemu: multiboot knows VBE. we don't.");
|      }
|      if (!(flags & 0x00010000)) { /* MULTIBOOT_HEADER_HAS_ADDR */
|          uint64_t elf_entry;
| @@ -193,7 +194,7 @@ int load_multiboot(FWCfgState *fw_cfg,
|          fclose(f);
|  
|          if (((struct elf64_hdr*)header)->e_machine == EM_X86_64) {
| -            fprintf(stderr, "Cannot load x86-64 image, give a 32bit one.\n");
| +            error_report("Cannot load x86-64 image, give a 32bit one.");
|              exit(1);
|          }
|  
| @@ -201,7 +202,7 @@ int load_multiboot(FWCfgState *fw_cfg,
|                                 &elf_low, &elf_high, 0, I386_ELF_MACHINE,
|                                 0, 0);
|          if (kernel_size < 0) {
| -            fprintf(stderr, "Error while loading elf kernel\n");
| +            error_report("Error while loading elf kernel");
|              exit(1);
|          }
|          mh_load_addr = elf_low;
| @@ -210,12 +211,13 @@ int load_multiboot(FWCfgState *fw_cfg,
|  
|          mbs.mb_buf = g_malloc(mb_kernel_size);
|          if (rom_copy(mbs.mb_buf, mh_load_addr, mb_kernel_size) != mb_kernel_size) {
| -            fprintf(stderr, "Error while fetching elf kernel from rom\n");
| +            error_report("Error while fetching elf kernel from rom");
|              exit(1);
|          }
|  
| -        mb_debug("qemu: loading multiboot-elf kernel (%#x bytes) with entry %#zx\n",
| -                  mb_kernel_size, (size_t)mh_entry_addr);
| +        mb_debug("qemu: loading multiboot-elf kernel "
| +                 "(%#x bytes) with entry %#zx",
| +                 mb_kernel_size, (size_t)mh_entry_addr);
|      } else {
|          /* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_ADDR. */
|          uint32_t mh_header_addr = ldl_p(header+i+12);
| @@ -224,7 +226,7 @@ int load_multiboot(FWCfgState *fw_cfg,
|  
|          mh_load_addr = ldl_p(header+i+16);
|          if (mh_header_addr < mh_load_addr) {
| -            fprintf(stderr, "invalid load_addr address\n");
| +            error_report("invalid load_addr address");
|              exit(1);
|          }
|  
| @@ -234,20 +236,20 @@ int load_multiboot(FWCfgState *fw_cfg,
|  
|          if (mh_load_end_addr) {
|              if (mh_load_end_addr < mh_load_addr) {
| -                fprintf(stderr, "invalid load_end_addr address\n");
| +                error_report("invalid load_end_addr address");
|                  exit(1);
|              }
|              mb_load_size = mh_load_end_addr - mh_load_addr;
|          } else {
|              if (kernel_file_size < mb_kernel_text_offset) {
| -                fprintf(stderr, "invalid kernel_file_size\n");
| +                error_report("invalid kernel_file_size");
|                  exit(1);
|              }
|              mb_load_size = kernel_file_size - mb_kernel_text_offset;
|          }
|          if (mh_bss_end_addr) {
|              if (mh_bss_end_addr < (mh_load_addr + mb_load_size)) {
| -                fprintf(stderr, "invalid bss_end_addr address\n");
| +                error_report("invalid bss_end_addr address");
|                  exit(1);
|              }
|              mb_kernel_size = mh_bss_end_addr - mh_load_addr;
| @@ -255,17 +257,17 @@ int load_multiboot(FWCfgState *fw_cfg,
|              mb_kernel_size = mb_load_size;
|          }
|  
| -        mb_debug("multiboot: header_addr = %#x\n", mh_header_addr);
| -        mb_debug("multiboot: load_addr = %#x\n", mh_load_addr);
| -        mb_debug("multiboot: load_end_addr = %#x\n", mh_load_end_addr);
| -        mb_debug("multiboot: bss_end_addr = %#x\n", mh_bss_end_addr);
| -        mb_debug("qemu: loading multiboot kernel (%#x bytes) at %#x\n",
| +        mb_debug("multiboot: header_addr = %#x", mh_header_addr);
| +        mb_debug("multiboot: load_addr = %#x", mh_load_addr);
| +        mb_debug("multiboot: load_end_addr = %#x", mh_load_end_addr);
| +        mb_debug("multiboot: bss_end_addr = %#x", mh_bss_end_addr);
| +        mb_debug("qemu: loading multiboot kernel (%#x bytes) at %#x",
|                   mb_load_size, mh_load_addr);
|  
|          mbs.mb_buf = g_malloc(mb_kernel_size);
|          fseek(f, mb_kernel_text_offset, SEEK_SET);
|          if (fread(mbs.mb_buf, 1, mb_load_size, f) != mb_load_size) {
| -            fprintf(stderr, "fread() failed\n");
| +            error_report("fread() failed");
|              exit(1);
|          }
|          memset(mbs.mb_buf + mb_load_size, 0, mb_kernel_size - mb_load_size);
| @@ -319,10 +321,10 @@ int load_multiboot(FWCfgState *fw_cfg,
|              hwaddr c = mb_add_cmdline(&mbs, tmpbuf);
|              if ((next_space = strchr(tmpbuf, ' ')))
|                  *next_space = '\0';
| -            mb_debug("multiboot loading module: %s\n", tmpbuf);
| +            mb_debug("multiboot loading module: %s", tmpbuf);
|              mb_mod_length = get_image_size(tmpbuf);
|              if (mb_mod_length < 0) {
| -                fprintf(stderr, "Failed to open file '%s'\n", tmpbuf);
| +                error_report("Failed to open file '%s'", tmpbuf);
|                  exit(1);
|              }
|  
| @@ -333,7 +335,7 @@ int load_multiboot(FWCfgState *fw_cfg,
|              mb_add_mod(&mbs, mbs.mb_buf_phys + offs,
|                         mbs.mb_buf_phys + offs + mb_mod_length, c);
|  
| -            mb_debug("mod_start: %p\nmod_end:   %p\n  cmdline: "TARGET_FMT_plx"\n",
| +            mb_debug("mod_start: %p\nmod_end:   %p\n  cmdline: "TARGET_FMT_plx,
|                       (char *)mbs.mb_buf + offs,
|                       (char *)mbs.mb_buf + offs + mb_mod_length, c);
|              initrd_filename = next_initrd+1;
| @@ -361,10 +363,11 @@ int load_multiboot(FWCfgState *fw_cfg,
|      stl_p(bootinfo + MBI_BOOT_DEVICE, 0x8000ffff); /* XXX: use the -boot switch? */
|      stl_p(bootinfo + MBI_MMAP_ADDR,   ADDR_E820_MAP);
|  
| -    mb_debug("multiboot: entry_addr = %#x\n", mh_entry_addr);
| -    mb_debug("           mb_buf_phys   = "TARGET_FMT_plx"\n", mbs.mb_buf_phys);
| -    mb_debug("           mod_start     = "TARGET_FMT_plx"\n", mbs.mb_buf_phys + mbs.offset_mods);
| -    mb_debug("           mb_mods_count = %d\n", mbs.mb_mods_count);
| +    mb_debug("multiboot: entry_addr = %#x", mh_entry_addr);
| +    mb_debug("           mb_buf_phys   = "TARGET_FMT_plx, mbs.mb_buf_phys);
| +    mb_debug("           mod_start     = "TARGET_FMT_plx,
| +             mbs.mb_buf_phys + mbs.offset_mods);
| +    mb_debug("           mb_mods_count = %d", mbs.mb_mods_count);
|  
|      /* save bootinfo off the stack */
|      mb_bootinfo_data = g_memdup(bootinfo, sizeof(bootinfo));
| 

Looks okay.

It maybe good to have version of error_report() which calls exit(1) too. I guess err(3) family of functions isn't used because they are nonstandard.

Thank you.
--
Prasad J Pandit / Red Hat Product Security Team
47AF CE69 3A90 54AA 9045 1053 DD13 3D32 FE5B 041F

#9 lore raw

[Qemu-devel] ping: Re: [PATCH QEMU v1 0/4] multiboot: bss_end_addr can be zero / cleanup

In reply to Jack Schwartz

Hi everyone.

Ping!  Please review.

Patchwork links:

1/4 multiboot: bss_end_addr can be zero
http://patchwork.ozlabs.org/patch/852049/

2/4 multiboot: Remove unused variables from multiboot.c
http://patchwork.ozlabs.org/patch/852045/

3/4 multiboot: Use header names when displaying fields
http://patchwork.ozlabs.org/patch/852046/

4/4 multiboot: fprintf(stderr...) -> error_report()
http://patchwork.ozlabs.org/patch/852051/

    Thanks,
    Jack

Quoted 32 lines · Jack Schwartz

Properly account for the possibility of multiboot kernels with a zero bss_end_addr. The Multiboot Specification, section 3.1.3 allows for kernels without a bss section, by allowing a zeroed bss_end_addr multiboot header field.

Do some cleanup to multiboot.c as well:
- Remove some unused variables.
- Use more intuitive header names when displaying fields in messages.
- Change fprintf(stderr...) to error_report

Testing:
1) Ran the "make check" test suite.
2) Booted multiboot kernel with bss_end_addr=0. (I rolled my own grub multiboot.elf test "kernel" by modifying source.) Verified with gdb that new code that reads addresses/offsets from multiboot header was accessed.
3) Booted multiboot kernel with non-zero bss_end_addr.
4) Uncommented DEBUG_MULTIBOOT in multiboot.c and verified messages worked.
5) Code has soaked in an internal repo for two months.

Thanks,
Jack

Jack Schwartz (4):
multiboot: bss_end_addr can be zero
multiboot: Remove unused variables from multiboot.c
multiboot: Use header names when displaying fields
multiboot: fprintf(stderr...) -> error_report()

  hw/i386/multiboot.c | 77 ++++++++++++++++++++++++++---------------------------
  1 file changed, 38 insertions(+), 39 deletions(-)
#10 lore raw
In reply to Jack Schwartz

Am 21.12.2017 um 18:25 hat Jack Schwartz geschrieben:

Quoted 9 lines

Properly account for the possibility of multiboot kernels with a zero bss_end_addr. The Multiboot Specification, section 3.1.3 allows for kernels without a bss section, by allowing a zeroed bss_end_addr multiboot header field.

Do some cleanup to multiboot.c as well:
- Remove some unused variables.
- Use more intuitive header names when displaying fields in messages.
- Change fprintf(stderr...) to error_report

There are some conflicts with Anatol's (CCed) multiboot series:
https://lists.nongnu.org/archive/html/qemu-devel/2017-10/msg03003.html

None if these should be hard to resolve, but it would be good if you could agree with each other whose patch series should come first, and then the other one should be rebased on top of that.

Quoted 9 lines

Testing:
1) Ran the "make check" test suite.
2) Booted multiboot kernel with bss_end_addr=0. (I rolled my own grub multiboot.elf test "kernel" by modifying source.) Verified with gdb that new code that reads addresses/offsets from multiboot header was accessed.
3) Booted multiboot kernel with non-zero bss_end_addr.
4) Uncommented DEBUG_MULTIBOOT in multiboot.c and verified messages worked.
5) Code has soaked in an internal repo for two months.

Can you integrate your test kernel from 2) in tests/multiboot/ so we can keep this as a regression test?

Quoted 5 lines

Jack Schwartz (4):
multiboot: bss_end_addr can be zero
multiboot: Remove unused variables from multiboot.c
multiboot: Use header names when displaying fields
multiboot: fprintf(stderr...) -> error_report()

Apart from the conflicts, the patches look good to me.

Kevin

#11 lore raw

Hi Kevin and Anatol.

Kevin, thanks for your review.

More inline below...

Quoted 10 lines · Kevin Wolf

Am 21.12.2017 um 18:25 hat Jack Schwartz geschrieben:

Quoted 9 lines

Properly account for the possibility of multiboot kernels with a zero bss_end_addr. The Multiboot Specification, section 3.1.3 allows for kernels without a bss section, by allowing a zeroed bss_end_addr multiboot header field.

Do some cleanup to multiboot.c as well:
- Remove some unused variables.
- Use more intuitive header names when displaying fields in messages.
- Change fprintf(stderr...) to error_report

Quoted 6 lines

There are some conflicts with Anatol's (CCed) multiboot series:
https://lists.nongnu.org/archive/html/qemu-devel/2017-10/msg03003.html

None if these should be hard to resolve, but it would be good if you could agree with each other whose patch series should come first, and then the other one should be rebased on top of that.

Anatol,

from my side, there are pros and cons to either patch set going in first, but advantages to either are pretty negligible.  Pro for you going first: I can use the constants you will define in header files.  Pro for me going first: your merge should be about the same as if you went first (since my changes are small, more localized and affect only multiboot.c) and my merge will be easier.

What are your thoughts?

Quoted 11 lines

Testing:
1) Ran the "make check" test suite.
2) Booted multiboot kernel with bss_end_addr=0. (I rolled my own grub multiboot.elf test "kernel" by modifying source.) Verified with gdb that new code that reads addresses/offsets from multiboot header was accessed.
3) Booted multiboot kernel with non-zero bss_end_addr.
4) Uncommented DEBUG_MULTIBOOT in multiboot.c and verified messages worked.
5) Code has soaked in an internal repo for two months.
Can you integrate your test kernel from 2) in tests/multiboot/ so we can keep this as a regression test?

Kevin and alias,

Before I proceed with adding my multiboot test file, I'll clarify here that I started with a version from the grub2 tree.  In that file I expanded a header file, also from the same tree.  Neither file had any license header, though the tree I got them from (Dated October 2017) contains the GNU GPLv3 license file.

I'll need to check with my company before I can say I can deliver this file.  If I deliver it, I'll add a header stating the GPL license, that it came from grub2 and to check its repository for contributors.

Quoted 6 lines
Quoted 5 lines

Jack Schwartz (4):
multiboot: bss_end_addr can be zero
multiboot: Remove unused variables from multiboot.c
multiboot: Use header names when displaying fields
multiboot: fprintf(stderr...) -> error_report()

Apart from the conflicts, the patches look good to me.

    Thanks,
    Jack

Quoted 3 lines

Kevin

#12 lore raw

Am 17.01.2018 um 21:06 hat Jack Schwartz geschrieben:

Quoted 5 lines

Before I proceed with adding my multiboot test file, I'll clarify here that I started with a version from the grub2 tree.  In that file I expanded a header file, also from the same tree.  Neither file had any license header, though the tree I got them from (Dated October 2017) contains the GNU GPLv3 license file.

I see. QEMU as a whole is GPLv2, so this might be a problem. It's probably not as bad as merging GPLv3 code into QEMU proper because it's a standalone test kernel that I suppose could have a different license. But IANAL and maybe it's safer not to go there.

Maybe it would be less hassle to just reimplement the tests, based on the MIT licensed tests that are already in tests/multiboot/.

Kevin

#13 lore raw
Quoted 11 lines · Kevin Wolf

Am 17.01.2018 um 21:06 hat Jack Schwartz geschrieben:

Quoted 5 lines

Before I proceed with adding my multiboot test file, I'll clarify here that I started with a version from the grub2 tree.  In that file I expanded a header file, also from the same tree.  Neither file had any license header, though the tree I got them from (Dated October 2017) contains the GNU GPLv3 license file.

I see. QEMU as a whole is GPLv2, so this might be a problem. It's probably not as bad as merging GPLv3 code into QEMU proper because it's a standalone test kernel that I suppose could have a different license. But IANAL and maybe it's safer not to go there.

As long as the GPLv3 code is not linked / otherwise combined with any of the GPLv2 code in QEMU that will be ok. Since it is a self-contained test kernel, that would not be an issue in this case - it only interfaces to QEMU via the x86 machine ABI.

It just means that the QEMU source tar.gz will be under a conjunction of licenses "GPLv2 and GPLv2+ and GPLv3 and ...all our other licenss..."

The resulting binaries for emulators/tools will still be GPLv2 as they're only linking in the GPLv2 + GPLv2+ source, never linking the GPlv3 test image.

For simplicity of understanding though, it could be desirable to avoid this if not an unreasonable amount of extra work

Quoted 2 lines

Maybe it would be less hassle to just reimplement the tests, based on the MIT licensed tests that are already in tests/multiboot/.

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 :|
#14 lore raw
In reply to Jack Schwartz

Hello Jack

Quoted 30 lines · Jack Schwartz

Hi Kevin and Anatol.

Kevin, thanks for your review.

More inline below...

Quoted 14 lines · Kevin Wolf

Am 21.12.2017 um 18:25 hat Jack Schwartz geschrieben:

Quoted 11 lines

Properly account for the possibility of multiboot kernels with a zero bss_end_addr. The Multiboot Specification, section 3.1.3 allows for kernels without a bss section, by allowing a zeroed bss_end_addr multiboot
header field.

Do some cleanup to multiboot.c as well:
- Remove some unused variables.
- Use more intuitive header names when displaying fields in messages.
- Change fprintf(stderr...) to error_report

Quoted 6 lines

There are some conflicts with Anatol's (CCed) multiboot series:
https://lists.nongnu.org/archive/html/qemu-devel/2017-10/msg03003.html

None if these should be hard to resolve, but it would be good if you could agree with each other whose patch series should come first, and then the other one should be rebased on top of that.

Anatol,

Quoted 8 lines

from my side, there are pros and cons to either patch set going in first, but advantages to either are pretty negligible. Pro for you going first: I can use the constants you will define in header files. Pro for me going
first: your merge should be about the same as if you went first (since my changes are small, more localized and affect only multiboot.c) and my merge will be easier.

What are your thoughts?

Please move ahead with your patches. I'll rebase my changes on top of yours.

Quoted 41 lines
Quoted 13 lines

Testing:
1) Ran the "make check" test suite.
2) Booted multiboot kernel with bss_end_addr=0. (I rolled my own grub multiboot.elf test "kernel" by modifying source.) Verified with gdb that new code that reads addresses/offsets from multiboot header was accessed.
3) Booted multiboot kernel with non-zero bss_end_addr.
4) Uncommented DEBUG_MULTIBOOT in multiboot.c and verified messages
worked.
5) Code has soaked in an internal repo for two months.
Can you integrate your test kernel from 2) in tests/multiboot/ so we can keep this as a regression test?

Kevin and alias,

Before I proceed with adding my multiboot test file, I'll clarify here that I started with a version from the grub2 tree. In that file I expanded a header file, also from the same tree. Neither file had any license header, though the tree I got them from (Dated October 2017) contains the GNU GPLv3 license file.

I'll need to check with my company before I can say I can deliver this file. If I deliver it, I'll add a header stating the GPL license, that it came from grub2 and to check its repository for contributors.

Quoted 8 lines
Quoted 6 lines

Jack Schwartz (4):
multiboot: bss_end_addr can be zero
multiboot: Remove unused variables from multiboot.c
multiboot: Use header names when displaying fields
multiboot: fprintf(stderr...) -> error_report()

Apart from the conflicts, the patches look good to me.

Thanks,
Jack

Quoted 4 lines

Kevin

#15 lore raw

Hi Anatol, Daniel and Kevin.

Quoted 37 lines · Anatol Pomozov

Hello Jack

Quoted 33 lines · Jack Schwartz

Hi Kevin and Anatol.

Kevin, thanks for your review.

More inline below...

Quoted 11 lines · Kevin Wolf

Am 21.12.2017 um 18:25 hat Jack Schwartz geschrieben:

Quoted 10 lines

Properly account for the possibility of multiboot kernels with a zero bss_end_addr. The Multiboot Specification, section 3.1.3 allows for kernels without a bss section, by allowing a zeroed bss_end_addr multiboot
header field.

Do some cleanup to multiboot.c as well:
- Remove some unused variables.
- Use more intuitive header names when displaying fields in messages.
- Change fprintf(stderr...) to error_report

Quoted 6 lines

There are some conflicts with Anatol's (CCed) multiboot series:
https://lists.nongnu.org/archive/html/qemu-devel/2017-10/msg03003.html

None if these should be hard to resolve, but it would be good if you could agree with each other whose patch series should come first, and then the other one should be rebased on top of that.

Anatol,

from my side, there are pros and cons to either patch set going in first, but advantages to either are pretty negligible. Pro for you going first: I can use the constants you will define in header files. Pro for me going
first: your merge should be about the same as if you went first (since my changes are small, more localized and affect only multiboot.c) and my merge will be easier.

Quoted 2 lines
Quoted 1 line

What are your thoughts?

Please move ahead with your patches. I'll rebase my changes on top of yours.

OK.  I'm consulting with my company's legal department and waiting for their approvals for delivery of a test "kernel".  I'll get in touch will everyone once I have an answer about that.  I anticipate about a week before taking next steps to deliver.

Kevin and Daniel, thanks for your inputs on this issue (different subthread), which I have forwarded to our legal department for review.

    Thanks,
    Jack

Quoted 35 lines
Quoted 35 lines
Quoted 13 lines

Testing:
1) Ran the "make check" test suite.
2) Booted multiboot kernel with bss_end_addr=0. (I rolled my own grub multiboot.elf test "kernel" by modifying source.) Verified with gdb that new code that reads addresses/offsets from multiboot header was accessed.
3) Booted multiboot kernel with non-zero bss_end_addr.
4) Uncommented DEBUG_MULTIBOOT in multiboot.c and verified messages
worked.
5) Code has soaked in an internal repo for two months.
Can you integrate your test kernel from 2) in tests/multiboot/ so we can keep this as a regression test?

Kevin and alias,

Before I proceed with adding my multiboot test file, I'll clarify here that I started with a version from the grub2 tree. In that file I expanded a header file, also from the same tree. Neither file had any license header, though the tree I got them from (Dated October 2017) contains the GNU GPLv3 license file.

I'll need to check with my company before I can say I can deliver this file. If I deliver it, I'll add a header stating the GPL license, that it came from grub2 and to check its repository for contributors.

Quoted 6 lines
Quoted 5 lines

Jack Schwartz (4):
multiboot: bss_end_addr can be zero
multiboot: Remove unused variables from multiboot.c
multiboot: Use header names when displaying fields
multiboot: fprintf(stderr...) -> error_report()

Apart from the conflicts, the patches look good to me.

Thanks,
Jack

Quoted 3 lines

Kevin

#16 lore raw
Quoted 41 lines · Jack Schwartz

Hi Anatol, Daniel and Kevin.

Quoted 38 lines · Anatol Pomozov

Hello Jack

Quoted 34 lines · Jack Schwartz

Hi Kevin and Anatol.

Kevin, thanks for your review.

More inline below...

Quoted 11 lines · Kevin Wolf

Am 21.12.2017 um 18:25 hat Jack Schwartz geschrieben:

Quoted 10 lines

Properly account for the possibility of multiboot kernels with a zero bss_end_addr. The Multiboot Specification, section 3.1.3 allows for kernels without a bss section, by allowing a zeroed bss_end_addr multiboot
header field.

Do some cleanup to multiboot.c as well:
- Remove some unused variables.
- Use more intuitive header names when displaying fields in messages.
- Change fprintf(stderr...) to error_report

Quoted 6 lines

There are some conflicts with Anatol's (CCed) multiboot series:
https://lists.nongnu.org/archive/html/qemu-devel/2017-10/msg03003.html

None if these should be hard to resolve, but it would be good if you could agree with each other whose patch series should come first, and then the other one should be rebased on top of that.

Anatol,

from my side, there are pros and cons to either patch set going in first, but advantages to either are pretty negligible. Pro for you going first: I can use the constants you will define in header files. Pro for me going
first: your merge should be about the same as if you went first (since my changes are small, more localized and affect only multiboot.c) and my merge will be easier.

What are your thoughts?

Quoted 8 lines
Quoted 1 line

Please move ahead with your patches. I'll rebase my changes on top of yours.

OK.  I'm consulting with my company's legal department and waiting for their approvals for delivery of a test "kernel".  I'll get in touch will everyone once I have an answer about that.  I anticipate about a week before taking next steps to deliver.

Kevin and Daniel, thanks for your inputs on this issue (different subthread), which I have forwarded to our legal department for review.

FWIW, I don't think it needs to be your responsibility to decide this. I think the QEMU community / maintainer taking the patches needs to decide whether it is acceptable / desirable.

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 :|
#17 lore raw
In reply to Kevin Wolf

Hi Kevin.

Quoted 26 lines · Kevin Wolf

Am 21.12.2017 um 18:25 hat Jack Schwartz geschrieben:

Quoted 9 lines

Properly account for the possibility of multiboot kernels with a zero bss_end_addr. The Multiboot Specification, section 3.1.3 allows for kernels without a bss section, by allowing a zeroed bss_end_addr multiboot header field.

Do some cleanup to multiboot.c as well:
- Remove some unused variables.
- Use more intuitive header names when displaying fields in messages.
- Change fprintf(stderr...) to error_report

There are some conflicts with Anatol's (CCed) multiboot series:
https://lists.nongnu.org/archive/html/qemu-devel/2017-10/msg03003.html

None if these should be hard to resolve, but it would be good if you could agree with each other whose patch series should come first, and then the other one should be rebased on top of that.

Quoted 9 lines

Testing:
1) Ran the "make check" test suite.
2) Booted multiboot kernel with bss_end_addr=0. (I rolled my own grub multiboot.elf test "kernel" by modifying source.) Verified with gdb that new code that reads addresses/offsets from multiboot header was accessed.
3) Booted multiboot kernel with non-zero bss_end_addr.
4) Uncommented DEBUG_MULTIBOOT in multiboot.c and verified messages worked.
5) Code has soaked in an internal repo for two months.

Quoted 2 lines

Can you integrate your test kernel from 2) in tests/multiboot/ so we can keep this as a regression test?

If need be, would you be willing to accept updated versions of these patches (with another review, of course) without the test file?  I will deliver the test file later once I get company approvals.  I don't want the test file to continue holding everything up in the meantime.

Patchwork links, for reference:

1/4 multiboot: bss_end_addr can be zero
http://patchwork.ozlabs.org/patch/852049/

2/4 multiboot: Remove unused variables from multiboot.c
http://patchwork.ozlabs.org/patch/852045/

3/4 multiboot: Use header names when displaying fields
http://patchwork.ozlabs.org/patch/852046/

4/4 multiboot: fprintf(stderr...) -> error_report()
http://patchwork.ozlabs.org/patch/852051/

    Thanks,
    Jack

Quoted 10 lines
Quoted 6 lines

Jack Schwartz (4):
multiboot: bss_end_addr can be zero
multiboot: Remove unused variables from multiboot.c
multiboot: Use header names when displaying fields
multiboot: fprintf(stderr...) -> error_report()

Apart from the conflicts, the patches look good to me.

Kevin

#18 lore raw

Am 02.03.2018 um 20:32 hat Jack Schwartz geschrieben:

Quoted 29 lines

Hi Kevin.

Quoted 26 lines · Kevin Wolf

Am 21.12.2017 um 18:25 hat Jack Schwartz geschrieben:

Quoted 9 lines

Properly account for the possibility of multiboot kernels with a zero bss_end_addr. The Multiboot Specification, section 3.1.3 allows for kernels without a bss section, by allowing a zeroed bss_end_addr multiboot header field.

Do some cleanup to multiboot.c as well:
- Remove some unused variables.
- Use more intuitive header names when displaying fields in messages.
- Change fprintf(stderr...) to error_report

There are some conflicts with Anatol's (CCed) multiboot series:
https://lists.nongnu.org/archive/html/qemu-devel/2017-10/msg03003.html

None if these should be hard to resolve, but it would be good if you could agree with each other whose patch series should come first, and then the other one should be rebased on top of that.

Quoted 9 lines

Testing:
1) Ran the "make check" test suite.
2) Booted multiboot kernel with bss_end_addr=0. (I rolled my own grub multiboot.elf test "kernel" by modifying source.) Verified with gdb that new code that reads addresses/offsets from multiboot header was accessed.
3) Booted multiboot kernel with non-zero bss_end_addr.
4) Uncommented DEBUG_MULTIBOOT in multiboot.c and verified messages worked.
5) Code has soaked in an internal repo for two months.

Quoted 6 lines
Quoted 2 lines

Can you integrate your test kernel from 2) in tests/multiboot/ so we can keep this as a regression test?

If need be, would you be willing to accept updated versions of these patches (with another review, of course) without the test file?  I will deliver the test file later once I get company approvals.  I don't want the test file to continue holding everything up in the meantime.

Sure, let's move forward with what we have now. Please keep me CCed when you send a new version and I'll give it a review and hopeuflly get it merged.

Kevin

#19 lore raw

Hi Kevin and everyone.

Quoted 36 lines · Kevin Wolf

Am 02.03.2018 um 20:32 hat Jack Schwartz geschrieben:

Quoted 29 lines

Hi Kevin.

Quoted 26 lines · Kevin Wolf

Am 21.12.2017 um 18:25 hat Jack Schwartz geschrieben:

Quoted 9 lines

Properly account for the possibility of multiboot kernels with a zero bss_end_addr. The Multiboot Specification, section 3.1.3 allows for kernels without a bss section, by allowing a zeroed bss_end_addr multiboot header field.

Do some cleanup to multiboot.c as well:
- Remove some unused variables.
- Use more intuitive header names when displaying fields in messages.
- Change fprintf(stderr...) to error_report

There are some conflicts with Anatol's (CCed) multiboot series:
https://lists.nongnu.org/archive/html/qemu-devel/2017-10/msg03003.html

None if these should be hard to resolve, but it would be good if you could agree with each other whose patch series should come first, and then the other one should be rebased on top of that.

Quoted 9 lines

Testing:
1) Ran the "make check" test suite.
2) Booted multiboot kernel with bss_end_addr=0. (I rolled my own grub multiboot.elf test "kernel" by modifying source.) Verified with gdb that new code that reads addresses/offsets from multiboot header was accessed.
3) Booted multiboot kernel with non-zero bss_end_addr.
4) Uncommented DEBUG_MULTIBOOT in multiboot.c and verified messages worked.
5) Code has soaked in an internal repo for two months.

Quoted 6 lines
Quoted 2 lines

Can you integrate your test kernel from 2) in tests/multiboot/ so we can keep this as a regression test?

If need be, would you be willing to accept updated versions of these patches (with another review, of course) without the test file?  I will deliver the test file later once I get company approvals.  I don't want the test file to continue holding everything up in the meantime.

Quoted 5 lines

Sure, let's move forward with what we have now. Please keep me CCed when you send a new version and I'll give it a review and hopeuflly get it merged.

Kevin

Thanks, Kevin.

Patches have not changed, and I verified they still work on a current repo.  (Multiboot.c has had a one-line change regarding a header file, so I rebuilt and re-tested to make sure.)

Links again, for your reference:

1/4 multiboot: bss_end_addr can be zero
http://patchwork.ozlabs.org/patch/852049/

2/4 multiboot: Remove unused variables from multiboot.c
http://patchwork.ozlabs.org/patch/852045/

3/4 multiboot: Use header names when displaying fields
http://patchwork.ozlabs.org/patch/852046/

4/4 multiboot: fprintf(stderr...) -> error_report()
http://patchwork.ozlabs.org/patch/852051/

    Thanks,
    Jack

#20 lore raw
In reply to Jack Schwartz

Am 21.12.2017 um 18:25 hat Jack Schwartz geschrieben:

Quoted 20 lines

Properly account for the possibility of multiboot kernels with a zero bss_end_addr. The Multiboot Specification, section 3.1.3 allows for kernels without a bss section, by allowing a zeroed bss_end_addr multiboot header field.

Do some cleanup to multiboot.c as well:
- Remove some unused variables.
- Use more intuitive header names when displaying fields in messages.
- Change fprintf(stderr...) to error_report

Testing:
1) Ran the "make check" test suite.
2) Booted multiboot kernel with bss_end_addr=0. (I rolled my own grub multiboot.elf test "kernel" by modifying source.) Verified with gdb that new code that reads addresses/offsets from multiboot header was accessed.
3) Booted multiboot kernel with non-zero bss_end_addr.
4) Uncommented DEBUG_MULTIBOOT in multiboot.c and verified messages worked.
5) Code has soaked in an internal repo for two months.

Quoted 2 lines

Thanks,
Jack

Thanks, applied to my multiboot branch.

Kevin

#21 lore raw

[Qemu-devel] CVE-2018-7550 (was: multiboot: bss_end_addr can be zero / cleanup)

In reply to Jack Schwartz

Am 21.12.2017 um 18:25 hat Jack Schwartz geschrieben:

Quoted 9 lines

Properly account for the possibility of multiboot kernels with a zero bss_end_addr. The Multiboot Specification, section 3.1.3 allows for kernels without a bss section, by allowing a zeroed bss_end_addr multiboot header field.

Do some cleanup to multiboot.c as well:
- Remove some unused variables.
- Use more intuitive header names when displaying fields in messages.
- Change fprintf(stderr...) to error_report

[ Cc: qemu-stable ]

This series happens to fix CVE-2018-7550.
http://www.openwall.com/lists/oss-security/2018/03/08/4

Just a shame that we weren't told before merging it so that the appropriate tags could have been set in the commit message (and all of the problems could have been addressed; I'm going to send another Multiboot series now).

Kevin

#22 lore raw

Re: [Qemu-devel] CVE-2018-7550 (was: multiboot: bss_end_addr can be zero / cleanup)

Quoted 14 lines · Kevin Wolf

Am 21.12.2017 um 18:25 hat Jack Schwartz geschrieben:

Quoted 3 lines

Properly account for the possibility of multiboot kernels with a zero bss_end_addr. The Multiboot Specification, section 3.1.3 allows for kernels without a bss section, by allowing a zeroed bss_end_addr

multiboot

Quoted 6 lines

header field.

Do some cleanup to multiboot.c as well:
- Remove some unused variables.
- Use more intuitive header names when displaying fields in messages.
- Change fprintf(stderr...) to error_report

[ Cc: qemu-stable ]

Quoted 7 lines

This series happens to fix CVE-2018-7550.
http://www.openwall.com/lists/oss-security/2018/03/08/4

Just a shame that we weren't told before merging it so that the appropriate tags could have been set in the commit message (and all of the problems could have been addressed; I'm going to send another Multiboot series now).

Huh?

You mean the CVE tags that were created in 2018 for a patch posted in 2017?

Or that the reporter of the security issue didn't point to this particular patch?

Irrespective of that, is there a write-up of how security process works at QEMU?

That is what is the usual embargo period, the list of security folks, how one can become one, what are the responsibilities, how changes to process are being carried out (and discussed), what breath of testing and PoC work is done , how security fixes are being reviewed, etc?

Thanks!

Quoted 2 lines

Kevin

#23 lore raw

Re: [Qemu-devel] CVE-2018-7550 (was: multiboot: bss_end_addr can be zero / cleanup)

Am 14.03.2018 um 18:35 hat Konrad Rzeszutek Wilk geschrieben:

Quoted 23 lines · Kevin Wolf
Quoted 14 lines

Am 21.12.2017 um 18:25 hat Jack Schwartz geschrieben:

Quoted 3 lines

Properly account for the possibility of multiboot kernels with a zero bss_end_addr. The Multiboot Specification, section 3.1.3 allows for kernels without a bss section, by allowing a zeroed bss_end_addr

multiboot

Quoted 6 lines

header field.

Do some cleanup to multiboot.c as well:
- Remove some unused variables.
- Use more intuitive header names when displaying fields in messages.
- Change fprintf(stderr...) to error_report

[ Cc: qemu-stable ]

Quoted 7 lines

This series happens to fix CVE-2018-7550.
http://www.openwall.com/lists/oss-security/2018/03/08/4

Just a shame that we weren't told before merging it so that the appropriate tags could have been set in the commit message (and all of the problems could have been addressed; I'm going to send another Multiboot series now).

Quoted 4 lines

Huh?

You mean the CVE tags that were created in 2018 for a patch posted in 2017?

Well, it seems to me that this patch was created for a different purpose, but it happens to fix the bug for which this CVE was assigned now. It's not your or Jack's fault, that's just how things go sometimes.

I think PJP knew that this CVE was coming before the patches were merged into master, so if he had told us, we could have had a better commit message. But either way, it's not a disaster to have a suboptimal commit message.

Quoted 9 lines

Or that the reporter of the security issue didn't point to this particular patch?

Irrespective of that, is there a write-up of how security process works at QEMU?

That is what is the usual embargo period, the list of security folks, how one can become one, what are the responsibilities, how changes to process are being carried out (and discussed), what breath of testing and PoC work is done , how security fixes are being reviewed, etc?

I don't think a problem like this would be embargoed at all. Anyway, have a look here:

https://wiki.qemu.org/SecurityProcess

Kevin

#24 lore raw

Re: [Qemu-devel] CVE-2018-7550 (was: multiboot: bss_end_addr can be zero / cleanup)

+-- On Wed, 14 Mar 2018, Kevin Wolf wrote --+
| Well, it seems to me that this patch was created for a different
| purpose, but it happens to fix the bug for which this CVE was assigned
| now.

Right. I had sent another patch to fix it, there Jack mentioned about his
series from before.

| I think PJP knew that this CVE was coming before the patches were merged
| into master, so if he had told us, we could have had a better commit
| message.

For non-embargoed issues we request CVE from Mitre after a proposed patch is
reviewed and acked for upstream QEMU. Nevertheless, going forward I'll mention the CVE-ID here on the list, as soon as it is assigned.

| I don't think a problem like this would be embargoed at all.

True.

Thank you.
--
Prasad J Pandit / Red Hat Product Security Team
47AF CE69 3A90 54AA 9045 1053 DD13 3D32 FE5B 041F