]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
plat/*: Introduce cmdline length to bootinfo
authorMarco Schlumpp <marco@unikraft.io>
Thu, 9 Feb 2023 13:34:39 +0000 (14:34 +0100)
committerUnikraft <monkey@unikraft.io>
Mon, 8 May 2023 19:49:15 +0000 (19:49 +0000)
Some boot protocols already have the length information and the internal
command line handling works with non-null terminated strings anyway.

Signed-off-by: Marco Schlumpp <marco@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu.moga@protonmail.com>
Approved-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #760

plat/common/include/uk/plat/common/bootinfo.h
plat/kvm/x86/multiboot.c
plat/kvm/x86/setup.c
support/scripts/mkbootinfo.py

index fc541b361ad74a067310dd0a58804a19cae8e7bd..b19c314962db08bd76cef4ff2a99d4170425fb25 100644 (file)
@@ -28,9 +28,14 @@ struct ukplat_bootinfo {
        /** Null-terminated boot protocol identifier */
        char bootprotocol[16];
 
-       /** Address of null-terminated kernel command line */
+       /** Address of the kernel command line. The string is not necessarily
+        * null-terminated.
+        */
        __u64 cmdline;
 
+       /** Size of the kernel command-line without the null terminator */
+       __u64 cmdline_len;
+
        /**
         * List of memory regions. Must be the last member as the
         * memory regions directly follow this boot information structure
@@ -38,7 +43,7 @@ struct ukplat_bootinfo {
        struct ukplat_memregion_list mrds;
 } __packed __align(__SIZEOF_LONG__);
 
-UK_CTASSERT(sizeof(struct ukplat_bootinfo) == 56);
+UK_CTASSERT(sizeof(struct ukplat_bootinfo) == 64);
 
 #ifdef CONFIG_UKPLAT_MEMRNAME
 #if __SIZEOF_LONG__ == 8
index 60f2e3b853178c9eb910cc4cfe96155443a170ae..f2994aa5fb33d585e338873319c87f66dc9bcda6 100644 (file)
@@ -53,7 +53,7 @@ void multiboot_entry(struct lcpu *lcpu, struct multiboot_info *mi)
        struct ukplat_memregion_desc *mrdp;
        multiboot_memory_map_t *m;
        multiboot_module_t *mods;
-       __sz offset;
+       __sz offset, cmdline_len;
        __paddr_t start, end;
        __u32 i;
 
@@ -64,15 +64,17 @@ void multiboot_entry(struct lcpu *lcpu, struct multiboot_info *mi)
        /* Add the cmdline */
        if (mi->flags & MULTIBOOT_INFO_CMDLINE) {
                if (mi->cmdline) {
+                       cmdline_len = strlen((const char *)(__uptr)mi->cmdline);
                        mrd.pbase = mi->cmdline;
                        mrd.vbase = mi->cmdline; /* 1:1 mapping */
-                       mrd.len   = strlen((const char *)(__uptr)mi->cmdline);
+                       mrd.len   = cmdline_len;
                        mrd.type  = UKPLAT_MEMRT_CMDLINE;
                        mrd.flags = UKPLAT_MEMRF_READ | UKPLAT_MEMRF_MAP;
 
                        mrd_insert(bi, &mrd);
 
                        bi->cmdline = mi->cmdline;
+                       bi->cmdline_len = cmdline_len;
                }
        }
 
index e24df5ebc113b68e246324f32c10d54abffe5da0..586f399189df213e59d2ecdb9d9581b35a26d010 100644 (file)
@@ -274,15 +274,23 @@ static __sz cmdline_len;
 
 static inline int cmdline_init(struct ukplat_bootinfo *bi)
 {
-       char *cmdl = (bi->cmdline) ? (char *)bi->cmdline : CONFIG_UK_NAME;
+       char *cmdl;
 
-       cmdline_len = strlen(cmdl) + 1;
+       if (bi->cmdline_len) {
+               cmdl = (char *)bi->cmdline;
+               cmdline_len = bi->cmdline_len;
+       } else {
+               cmdl = CONFIG_UK_NAME;
+               cmdline_len = sizeof(CONFIG_UK_NAME) - 1;
+       }
 
-       cmdline = bootmemory_palloc(cmdline_len, UKPLAT_MEMRT_CMDLINE);
+       cmdline = bootmemory_palloc(cmdline_len + 1, UKPLAT_MEMRT_CMDLINE);
        if (unlikely(!cmdline))
                return -ENOMEM;
 
-       strncpy(cmdline, cmdl, cmdline_len);
+       memcpy(cmdline, cmdl, cmdline_len);
+       cmdline[cmdline_len] = 0;
+
        return 0;
 }
 
index 83f452f121fe3de9d2cdd17e2a0163f156e6333e..982f82a284e4fbb0abfd433ebb9d8537a821291c 100755 (executable)
@@ -23,7 +23,7 @@ UKPLAT_MEMRF_EXECUTE    = 0x0004   # Region is executable
 UKPLAT_MEMR_NAME_LEN    = 36
 
 # Boot info structure (see include/uk/plat/common/bootinfo.h)
-UKPLAT_BOOTINFO_SIZE    = 56
+UKPLAT_BOOTINFO_SIZE    = 64
 
 UKPLAT_BOOTINFO_MAGIC   = 0xB007B0B0 # Boot Bobo
 UKPLAT_BOOTINFO_VERSION = 0x01
@@ -91,6 +91,7 @@ def main():
         secobj.write(b'\0' * 16) # bootloader
         secobj.write(b'\0' * 16) # bootprotocol
         secobj.write(b'\0' * 8) # cmdline
+        secobj.write(b'\0' * 8) # cmdline_len
         secobj.write(cap.to_bytes(4, endianness)) # mrds.capacity
         secobj.write(b'\0' * 4) # mrds.count