riscv: Fix no params with nodefault segfault
Subsystems (3)
PATCH 1/1 riscv: Fix no params with nodefault segfault
Fix segfault received when using --nodefault without --params.
--- riscv/fdt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
riscv/fdt.c +2 -1
@@ -256,9 +256,10 @@ static int setup_fdt(struct kvm *kvm)if (kvm->cfg.kernel_cmdline)_FDT (fdt_property_string (fdt,"bootargs" , kvm->cfg.kernel_cmdline)); - }else + }else if (kvm->cfg.real_cmdline) {_FDT (fdt_property_string (fdt,"bootargs" , kvm->cfg.real_cmdline)); + }_FDT (fdt_property_string (fdt,"stdout-path" ,"serial0" ));
Signature · 1 line
2.48.1
Hi Drew,
Quoted 14 lines · Andrew Jones
Fix segfault received when using --nodefault without --params.
Fixes 7c9aac003925 ("riscv: Generate FDT at runtime for Guest/VM")Suggested-by Alexandru Elisei <[email protected]>Signed-off-by Andrew Jones <[email protected]>--- riscv/fdt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)riscv/fdt.c +0
-0
riscv/fdt.c static int setup_fdt(struct kvm *kvm) · line 259
Quoted 5 lines
riscv/fdt.c +1
-1@@ -256,9 +256,10 @@ static int setup_fdt(struct kvm *kvm)if (kvm->cfg.kernel_cmdline)_FDT (fdt_property_string (fdt,"bootargs" , kvm->cfg.kernel_cmdline)); - }else + }else if (kvm->cfg.real_cmdline) {
Looks good to me, matches how arm/fdt.c handles real_cmdline:
Some context here. Before the patch that introduced --nodefaults, in commit 5613ae26b998 ("Add --nodefaults command line argument"), kvmtool would always fiddle with the kernel command line to make it more likely that a kernel boots - kvm_cmd_run_init() called kvm_run_set_real_cmdline() unconditionally, which made it that kvm->cfg.real_cmdline was always pointing to a valid string. Hence no check was needed here.
After --nodefaults was introduced, if the user specifies --nodefaults and doesn't set the kernel command line (via -p/--params), real_cmdline ends up being NULL and the fdt generator segfaults below.
The riscv port was developed in parallel to the series that introduced --nodefaults, so I guess this check was missed during integration.
Thanks,
Alex
Quoted 9 lines
riscv/fdt.c +1
-0_FDT (fdt_property_string (fdt,"bootargs" , kvm->cfg.real_cmdline)); + }_FDT (fdt_property_string (fdt,"stdout-path" ,"serial0" ));Signature · 1 line
2.48.1