diff --git a/src/dragonball/Cargo.toml b/src/dragonball/Cargo.toml index 01d11a592..c1a24a4f6 100644 --- a/src/dragonball/Cargo.toml +++ b/src/dragonball/Cargo.toml @@ -26,7 +26,7 @@ kvm-bindings = "0.5.0" kvm-ioctls = "0.11.0" lazy_static = "1.2" libc = "0.2.39" -linux-loader = "0.5.0" +linux-loader = "0.6.0" log = "0.4.14" nix = "0.24.2" seccompiler = "0.2.0" diff --git a/src/dragonball/src/device_manager/blk_dev_mgr.rs b/src/dragonball/src/device_manager/blk_dev_mgr.rs index e4688b4f6..4f0fa1e4b 100644 --- a/src/dragonball/src/device_manager/blk_dev_mgr.rs +++ b/src/dragonball/src/device_manager/blk_dev_mgr.rs @@ -577,7 +577,13 @@ impl BlockDeviceMgr { ) -> std::result::Result<(), DeviceMgrError> { // Respect user configuration if kernel_cmdline contains "root=", // special attention for the case when kernel command line starting with "root=xxx" - let old_kernel_cmdline = format!(" {}", kernel_config.kernel_cmdline().as_str()); + let old_kernel_cmdline = format!( + " {:?}", + kernel_config + .kernel_cmdline() + .as_cstring() + .map_err(DeviceMgrError::Cmdline)? + ); if !old_kernel_cmdline.contains(" root=") && self.has_root_block { let cmdline = kernel_config.kernel_cmdline_mut(); if let Some(ref uuid) = self.part_uuid { diff --git a/src/dragonball/src/error.rs b/src/dragonball/src/error.rs index 35cf639bb..9ad0b0792 100644 --- a/src/dragonball/src/error.rs +++ b/src/dragonball/src/error.rs @@ -127,6 +127,10 @@ pub enum StartMicroVmError { #[error("failure while configuring guest kernel commandline: {0}")] LoadCommandline(#[source] linux_loader::loader::Error), + /// Cannot process command line string. + #[error("failure while processing guest kernel commandline: {0}.")] + ProcessCommandlne(#[source] linux_loader::cmdline::Error), + /// The device manager was not configured. #[error("the device manager failed to manage devices: {0}")] DeviceManager(#[source] device_manager::DeviceMgrError), diff --git a/src/dragonball/src/vm/x86_64.rs b/src/dragonball/src/vm/x86_64.rs index 96ca0acb1..d2e084947 100644 --- a/src/dragonball/src/vm/x86_64.rs +++ b/src/dragonball/src/vm/x86_64.rs @@ -217,11 +217,17 @@ impl Vm { linux_loader::loader::load_cmdline(vm_memory, cmdline_addr, cmdline) .map_err(StartMicroVmError::LoadCommandline)?; + let cmdline_size = cmdline + .as_cstring() + .map_err(StartMicroVmError::ProcessCommandlne)? + .as_bytes_with_nul() + .len(); + configure_system( vm_memory, self.address_space.address_space(), cmdline_addr, - cmdline.as_str().len() + 1, + cmdline_size, &initrd, self.vm_config.vcpu_count, self.vm_config.max_vcpu_count,