diff --git a/hypervisor/arch/x86/seed/seed.c b/hypervisor/arch/x86/seed/seed.c index c2b618133..950dd51e7 100644 --- a/hypervisor/arch/x86/seed/seed.c +++ b/hypervisor/arch/x86/seed/seed.c @@ -45,7 +45,7 @@ static uint32_t parse_seed_arg(void) uint32_t i = SEED_ARG_NUM - 1U; uint32_t len; - cmd_src = abi->mi_cmdline; + cmd_src = abi->cmdline; if (cmd_src != NULL) { for (i = 0U; seed_arg[i].str != NULL; i++) { diff --git a/hypervisor/boot/guest/vboot_info.c b/hypervisor/boot/guest/vboot_info.c index 16e222ad3..0063cda52 100644 --- a/hypervisor/boot/guest/vboot_info.c +++ b/hypervisor/boot/guest/vboot_info.c @@ -136,13 +136,13 @@ static void init_vm_bootargs_info(struct acrn_vm *vm, const struct acrn_boot_inf pr_err("failed to fill seed arg to SOS bootargs!"); } - /* If there is cmdline from mbi->mi_cmdline, merge it with configured SOS bootargs. + /* If there is cmdline from abi->cmdline, merge it with configured SOS bootargs. * This is very helpful when one of configured bootargs need to be revised at GRUB runtime * (e.g. "root="), since the later one would override the previous one if multiple bootargs exist. */ - if ((abi->mi_cmdline != NULL) && (*(abi->mi_cmdline) != '\0')) { + if (abi->cmdline[0] != '\0') { if (strncat_s((char *)vm->sw.bootargs_info.src_addr, MAX_BOOTARGS_SIZE, - abi->mi_cmdline, (MAX_BOOTARGS_SIZE - 1U)) != 0) { + abi->cmdline, (MAX_BOOTARGS_SIZE - 1U)) != 0) { pr_err("failed to merge mbi cmdline to SOS bootargs!"); } } diff --git a/hypervisor/boot/include/boot.h b/hypervisor/boot/include/boot.h index 71ab74f84..c387c981b 100644 --- a/hypervisor/boot/include/boot.h +++ b/hypervisor/boot/include/boot.h @@ -27,8 +27,7 @@ struct acrn_boot_info { char protocol_name[MAX_PROTOCOL_NAME_SIZE]; - - const char *mi_cmdline; + const char cmdline[MAX_BOOTARGS_SIZE]; const char *mi_loader_name; uint32_t mi_mods_count; diff --git a/hypervisor/boot/multiboot/multiboot.c b/hypervisor/boot/multiboot/multiboot.c index 21173898f..01ee68075 100644 --- a/hypervisor/boot/multiboot/multiboot.c +++ b/hypervisor/boot/multiboot/multiboot.c @@ -18,7 +18,9 @@ int32_t multiboot_to_acrn_bi(struct acrn_boot_info *abi, void *mb_info) { struct multiboot_mmap *mmap = (struct multiboot_mmap *)hpa2hva_early((uint64_t)mbi->mi_mmap_addr); struct multiboot_module *mods = (struct multiboot_module *)hpa2hva_early((uint64_t)mbi->mi_mods_addr); - abi->mi_cmdline = (char *)hpa2hva_early((uint64_t)mbi->mi_cmdline); + (void)strncpy_s((void *)(abi->cmdline), MAX_BOOTARGS_SIZE, (char *)hpa2hva_early((uint64_t)mbi->mi_cmdline), + strnlen_s((char *)hpa2hva_early((uint64_t)mbi->mi_cmdline), (MAX_BOOTARGS_SIZE - 1U))); + abi->mi_loader_name = (char *)hpa2hva_early((uint64_t)mbi->mi_loader_name); abi->mi_mmap_entries = mbi->mi_mmap_length / sizeof(struct multiboot_mmap); abi->mi_mods_count = mbi->mi_mods_count; diff --git a/hypervisor/boot/multiboot/multiboot2.c b/hypervisor/boot/multiboot/multiboot2.c index 83882f1a3..6e4433653 100644 --- a/hypervisor/boot/multiboot/multiboot2.c +++ b/hypervisor/boot/multiboot/multiboot2.c @@ -77,6 +77,7 @@ int32_t multiboot2_to_acrn_bi(struct acrn_boot_info *abi, void *mb2_info) struct multiboot2_tag *mb2_tag, *mb2_tag_end; uint32_t mb2_info_size = *(uint32_t *)mb2_info; uint32_t mod_idx = 0U; + void *str; /* The start part of multiboot2 info: total mbi size (4 bytes), reserved (4 bytes) */ mb2_tag = (struct multiboot2_tag *)((uint8_t *)mb2_info + 8U); @@ -85,7 +86,9 @@ int32_t multiboot2_to_acrn_bi(struct acrn_boot_info *abi, void *mb2_info) while ((mb2_tag->type != MULTIBOOT2_TAG_TYPE_END) && (mb2_tag < mb2_tag_end)) { switch (mb2_tag->type) { case MULTIBOOT2_TAG_TYPE_CMDLINE: - abi->mi_cmdline = ((struct multiboot2_tag_string *)mb2_tag)->string; + str = ((struct multiboot2_tag_string *)mb2_tag)->string; + (void)strncpy_s((void *)(abi->cmdline), MAX_BOOTARGS_SIZE, str, + strnlen_s(str, (MAX_BOOTARGS_SIZE - 1U))); break; case MULTIBOOT2_TAG_TYPE_MMAP: mb2_mmap_to_abi(abi, (const struct multiboot2_tag_mmap *)mb2_tag); diff --git a/hypervisor/debug/console.c b/hypervisor/debug/console.c index 7fb7adc59..826f1a2c4 100644 --- a/hypervisor/debug/console.c +++ b/hypervisor/debug/console.c @@ -31,9 +31,9 @@ static void parse_hvdbg_cmdline(void) const char *end = NULL; struct acrn_boot_info *abi = get_acrn_boot_info(); - start = abi->mi_cmdline; + start = abi->cmdline; - while ((start != NULL) && ((*start) != '\0')) { + while ((*start) != '\0') { while ((*start) == ' ') start++; if ((*start) != '\0') {