As per observation in practice, initrd->cmdline_pa is not normally zero. Hence so far we always appended at least one byte. That alone may already render insufficient the "allocation" made by find_memory(). Things would be worse when there's actually a (perhaps long) command line.
Skip setup when the command line is empty. Amend the "allocation" size by padding and actual size of module command line. Fixes: 0ecb8eb09f9f ("x86/pvh: pass module command line to dom0") Signed-off-by: Jan Beulich <jbeul...@suse.com> --- a/xen/arch/x86/hvm/dom0_build.c +++ b/xen/arch/x86/hvm/dom0_build.c @@ -712,7 +712,15 @@ static int __init pvh_load_kernel( * simplify it. */ last_addr = find_memory(d, &elf, sizeof(start_info) + - (initrd ? ROUNDUP(initrd_len, PAGE_SIZE) + + (initrd ? ROUNDUP(ROUNDUP(initrd_len, + elf_64bit(&elf) ? 8 : 4) + + (initrd->cmdline_pa && + strlen(__va(initrd-> + cmdline_pa)) + ? strlen(__va(initrd-> + cmdline_pa)) + 1 + : 0), + PAGE_SIZE) + sizeof(mod) : 0) + (cmdline ? ROUNDUP(strlen(cmdline) + 1, @@ -740,16 +748,19 @@ static int __init pvh_load_kernel( if ( initrd->cmdline_pa ) { char *str = __va(initrd->cmdline_pa); - size_t len = strlen(str) + 1; + size_t len = strlen(str); - rc = hvm_copy_to_guest_phys(last_addr, str, len, v); - if ( rc ) + if ( len++ ) { - printk("Unable to copy module command line\n"); - return rc; + rc = hvm_copy_to_guest_phys(last_addr, str, len, v); + if ( rc ) + { + printk("Unable to copy module command line\n"); + return rc; + } + mod.cmdline_paddr = last_addr; + last_addr += len; } - mod.cmdline_paddr = last_addr; - last_addr += len; } last_addr = ROUNDUP(last_addr, PAGE_SIZE); }