From 758b4f721ba664f383bd234458f78984f22823b6 Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Thu, 26 Jul 2018 16:24:43 +0200 Subject: [PATCH 1/8] multiboot: bss_end_addr can be zero RH-Author: Kevin Wolf Message-id: <20180726162448.22072-2-kwolf@redhat.com> Patchwork-id: 81517 O-Subject: [RHEL-7.6/7.5.z qemu-kvm PATCH 1/6] multiboot: bss_end_addr can be zero Bugzilla: 1549822 RH-Acked-by: John Snow RH-Acked-by: Stefan Hajnoczi RH-Acked-by: Miroslav Rezanina From: Jack Schwartz 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 Signed-off-by: Jack Schwartz Reviewed-by: Daniel Kiper Reviewed-by: Prasad J Pandit Signed-off-by: Kevin Wolf (cherry picked from commit 2a8fcd119eb7c6bb3837fc3669eb1b2dfb31daf8) Signed-off-by: Kevin Wolf Signed-off-by: Miroslav Rezanina --- 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 7eec230..9a9a2e1 100644 --- a/hw/i386/multiboot.c +++ b/hw/i386/multiboot.c @@ -212,12 +212,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); @@ -228,8 +222,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. -- 1.8.3.1