Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ nvx/target/release/nvx run
| `--network-proxy IPV4:TCP-PORT` | none | Allow one explicit host TCP proxy endpoint. |
| `--host-loopback-forward PROTOCOL:HOST_PORT:GUEST_PORT` | none | Publish one TCP or UDP localhost port to the guest; repeat to add forwards. |
| `--outcome-report PATH` | none | Write a bounded local JSON outcome report to a new file in an existing plain directory. A cold boot rejects an existing destination before launch and never replaces a file or follows a destination symlink. On Windows, it also rejects before launch a file name with a colon, which names a stream of another file there rather than a new file. A missing report or publication failure is diagnosed without replacing OpenVMM's exit status. A restore refuses it. |
| `--cmdline TEXT` | empty | Append kernel parameters. The tokens that NVX renders for the guest's root, view, and shares, such as `nvx_hostname`, `nvx_machine_id`, and `nvx_maps`, `virtfs_*` tokens, those that OpenVMM's machine profile owns, such as `console=`, `earlycon=`, `nr_cpus=`, and the `virtnet_*` bootstrap tokens, and the clock parameters that OpenVMM's time ABI refuses at every cold boot, `tsc_early_khz` and `lapic_timer_hz`, with or without a value and in any dash spelling, are refused before the launch, with `--dry-run` too; see [Effective Command Line](design/5.1-boot-protocol.md#512-effective-command-line). A cold boot takes the blockless mode from `nvx_mode=` or `nvx_lifecycle=`, `one-shot` by default, and the workload identity from `nvx_identity=UID:GID` or from both `nvx_workload_uid=` and `nvx_workload_gid=`, and refuses a mode or an identity given more than once. Cold boots reject double quotes and a standalone `--` token, which the VM control console cannot represent, wherever Linux reads whitespace around the `--`, as at a vertical tab or the `0xa0` in `à`. A restore refuses it. |
| `--cmdline TEXT` | empty | Append kernel parameters. The tokens that NVX renders for the guest's root, view, and shares, such as `nvx_hostname`, `nvx_machine_id`, and `nvx_maps`, `virtfs_*` tokens, those that OpenVMM's machine profile owns, such as `console=`, `earlycon=`, `nr_cpus=`, and the `virtnet_*` bootstrap tokens, and the clock parameters that OpenVMM's time ABI refuses at every cold boot, `tsc_early_khz` and `lapic_timer_hz`, with or without a value and in any dash spelling, are refused before the launch, with `--dry-run` too; see [Effective Command Line](design/5.1-boot-protocol.md#512-effective-command-line). A cold boot takes the blockless mode from `nvx_mode=` or `nvx_lifecycle=`, `one-shot` by default, and the workload identity from `nvx_identity=UID:GID` or from both `nvx_workload_uid=` and `nvx_workload_gid=`, and refuses a mode or an identity given more than once. Cold boots reject double quotes and a standalone `--` token, which the VM control console cannot represent, wherever Linux reads whitespace around the `--`, as at a vertical tab or the `0xa0` in `à`. With or without `--mount` shares, cold boots refuse, before the launch and with `--dry-run` too, a kernel command line beyond its 1024-byte budget: the text and the tokens that NVX renders, the bootstrap tokens that OpenVMM appends for the shares, if any, and a NUL. A restore refuses it. |
| `--restore-snapshot NAME` | none | Restore the snapshot `NAME` of `--store-dir`, which [`snapshot capture`](#snapshot-capture) published, in place of a cold boot, as described below. A raw OpenVMM snapshot directory is refused. |
| `--store-dir PATH` | none | The named snapshot store of `--restore-snapshot`, which a restore requires. |
| `--state-dir PATH` | none | The directory of a restore's sandbox, which a restore requires: one that does not exist, outside the store, on the store's filesystem. The run creates it, and removes it once it ends. A cold boot refuses it. |
Expand Down
5 changes: 5 additions & 0 deletions nvx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1607,6 +1607,11 @@ next cold boot removes the VM directory that one that was terminated left.
lowers, with its DNS server, egress, forwards, and published listeners; a
snapshot with a NIC needs `--network-profile` with them, and one without
refuses them.
- A cold boot refuses, before it launches anything and with `--dry-run` too, a
kernel command line beyond `COMMAND_LINE_BUDGET`, the 1024 bytes that
OpenVMM leaves to it, whether or not it has `--mount` shares, as `sandbox`
does: the tokens that `run` renders and the text of `--cmdline`, the
bootstrap tokens that OpenVMM appends for the shares, if any, and a NUL.
- A cold boot binds each `--mount` from the export's aggregate at
`/run/nvx/hostfs/root`. The shares' guest targets must be absolute, must not
overlap each other or the guest's reserved paths, such as `/run`, and must
Expand Down
34 changes: 23 additions & 11 deletions nvx/src/host/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -730,17 +730,29 @@ fn cold_vm_config(
}),
filesystem,
};
if let Some(export) = &config.filesystem {
let line = config.kernel_command_line().map_err(error_with_cause)?;
if line.len() + export_tokens(export).len() + 1 > COMMAND_LINE_BUDGET {
return Err(Exit::error(
ErrorCode::Unsupported,
format!(
"the --mount shares and --cmdline exceed the {COMMAND_LINE_BUDGET}-byte budget \
of the kernel command line; attach fewer shares or use shorter targets"
),
));
}
// OpenVMM leaves `COMMAND_LINE_BUDGET` to the line that the run renders, shares or not, as to
// a sandbox's: past it, the tokens that OpenVMM appends can overflow the kernel's line.
let line = config.kernel_command_line().map_err(error_with_cause)?;
let shares = config
.filesystem
.as_ref()
.map_or(0, |export| export_tokens(export).len());
if line.len() + shares + 1 > COMMAND_LINE_BUDGET {
let (subject, advice) = if config.filesystem.is_some() {
(
"the --mount shares and --cmdline exceed",
"attach fewer shares or use shorter targets",
)
} else {
("--cmdline exceeds", "use shorter kernel parameters")
};
return Err(Exit::error(
ErrorCode::Unsupported,
format!(
"{subject} the {COMMAND_LINE_BUDGET}-byte budget of the kernel command line; \
{advice}"
),
));
}
config.check_command_line().map_err(error_with_cause)?;
Ok(config)
Expand Down
27 changes: 27 additions & 0 deletions nvx/src/host/cli/run/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,33 @@ fn cold_share_command_lines_fit_the_kernel_budget_to_the_byte() {
}
}

#[test]
fn cold_command_lines_without_shares_fit_the_kernel_budget_to_the_byte() {
let mut options = Options::default();
let rules = options.network.egress_rules().unwrap();
let base = cold_config(&options, &rules).unwrap();
assert!(base.filesystem.is_none());
// The caller's text joins the run's own tokens after a space, and a NUL ends the line.
let room = COMMAND_LINE_BUDGET - base.kernel_command_line().unwrap().len() - 2;
options.cmdline = "x".repeat(room);
let fitting = cold_config(&options, &rules).unwrap();
assert_eq!(
fitting.kernel_command_line().unwrap().len() + 1,
COMMAND_LINE_BUDGET
);
options.cmdline.push('x');
let refused = cold_config(&options, &rules).err();
assert!(
matches!(
&refused,
Some(Exit::Error { code: ErrorCode::Unsupported, message })
if message == "--cmdline exceeds the 1024-byte budget of the kernel command line; \
use shorter kernel parameters"
),
"{refused:?}"
);
}

#[test]
fn cold_command_lines_that_hide_the_appended_devices_are_refused() {
// Linux ends its parameters at a `--` after a vertical tab or the byte 0xa0, which ends
Expand Down
14 changes: 14 additions & 0 deletions nvx/tests/cli/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,7 @@ fn sandbox_refusals() -> Vec<Refusal> {
fn run_refusals() -> Vec<Refusal> {
let targets = "each target must be an absolute non-root path";
let budget = &["--mount", "--cmdline", "1024"][..];
let no_share_budget = &["--cmdline exceeds the 1024-byte budget"][..];
let overflow = crate::openvmm::two_share_command_line_room() + 1;
let two_shares = |cmdline: &str| {
run_dry(&[
Expand Down Expand Up @@ -1613,6 +1614,19 @@ fn run_refusals() -> Vec<Refusal> {
]),
budget,
),
// Without shares, the budget holds all the same, before a dry run and a launch alike.
refusal(
"run: long command line without shares",
"unsupported",
run_dry(&["--cmdline", &"x".repeat(1100)]),
no_share_budget,
),
refusal(
"run: launch of a long command line without shares",
"unsupported",
["run".to_owned(), "--cmdline".to_owned(), "x".repeat(1100)],
no_share_budget,
),
refusal(
"run: missing OpenVMM override",
"artifact-missing",
Expand Down
Loading