You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
openvmm: clock-token validation misses Linux byte whitespace #1145
The microVM time-ABI command-line guard accepts some clock parameters that Linux subsequently parses, allowing the boot command line to override clock settings the guard is intended to reject.
In vmm_core/virt/src/time_abi/mod.rs, check_command_line_clock_tokens scans Unicode characters and splits tokens using Rust ASCII whitespace:
let mut tokens = Vec::new();
let mut start = None;
let mut in_quote = false;
for (offset, c) in cmdline.char_indices() {
if c == '"' {
in_quote = !in_quote;
}
if c.is_ascii_whitespace() && !in_quote {
if let Some(start) = start.take() {
tokens.push(&cmdline[start..offset]);
}
Rust's check excludes vertical tab (0x0b). Linux's byte-level isspace also recognizes 0xa0, which can appear inside a valid UTF-8 character. Linux therefore finds a parameter boundary where this guard sees none.
Trigger
Place tsc_early_khz=1000000 after console=hvc0 separated by a vertical tab. The guard accepts the line instead of returning E_CMDLINE_CLOCK_TOKEN. A UTF-8 character whose final byte is 0xa0, followed by the prohibited parameter, produces the same mismatch.
Fix
fix.patch tokenizes bytes using Linux's whitespace set: 0x09..=0x0d, space and 0xa0. It preserves quoting, hyphen/underscore-equivalent parameter names, and the -- delimiter after which arguments belong to init. Error formatting uses lossy UTF-8 conversion because a byte delimiter can split a character.
Patch against OpenVMM 998b9f2402050cd16d1faa897bc831ef1434be48. Save the contents below as fix.patch and run git apply fix.patch.
fix.patch
diff --git a/vmm_core/virt/src/time_abi/mod.rs b/vmm_core/virt/src/time_abi/mod.rs
--- a/vmm_core/virt/src/time_abi/mod.rs
+++ b/vmm_core/virt/src/time_abi/mod.rs
@@ -382,23 +382,31 @@
/// Rejects a kernel command line that sets a [`CLOCK_TOKENS`] parameter
/// (`E_CMDLINE_CLOCK_TOKEN`).
///
-/// It follows the kernel's parsing: parameters are separated by unquoted
-/// whitespace, `-` and `_` are equivalent in names, a parameter may be
-/// quoted as a whole, and parsing stops at the `--` delimiter, after which
-/// arguments belong to init.
+/// It follows the kernel's parsing of the line's bytes: parameters are
+/// separated by unquoted whitespace as the kernel's `isspace` reads it, `-`
+/// and `_` are equivalent in names, a parameter may be quoted as a whole, and
+/// parsing stops at the `--` delimiter, after which arguments belong to init.
pub fn check_command_line_clock_tokens(cmdline: &str) -> Result<(), TimeAbiError> {
- fn normalized(name: &str) -> impl Iterator<Item = u8> + '_ {
- name.bytes().map(|b| if b == b'-' { b'_' } else { b })
- }
-
+ fn normalized(name: &[u8]) -> impl Iterator<Item = u8> + '_ {
+ name.iter().map(|&b| if b == b'-' { b'_' } else { b })
+ }
+
+ /// Whether the kernel reads the byte `b` as whitespace: its `isspace`
+ /// (lib/ctype.c), which is `\t`, `\n`, `\v`, `\f`, `\r`, space, and 0xa0
+ /// (Latin-1's no-break space, also a byte of many UTF-8 characters).
+ fn kernel_isspace(b: u8) -> bool {
+ matches!(b, 0x09..=0x0d | b' ' | 0xa0)
+ }
+
+ let cmdline = cmdline.as_bytes();
let mut tokens = Vec::new();
let mut start = None;
let mut in_quote = false;
- for (offset, c) in cmdline.char_indices() {
- if c == '"' {
+ for (offset, &b) in cmdline.iter().enumerate() {
+ if b == b'"' {
in_quote = !in_quote;
}
- if c.is_ascii_whitespace() && !in_quote {
+ if kernel_isspace(b) && !in_quote {
if let Some(start) = start.take() {
tokens.push(&cmdline[start..offset]);
}
@@ -412,19 +420,26 @@
for token in tokens {
let unquoted = token
- .strip_prefix('"')
- .map_or(token, |rest| rest.strip_suffix('"').unwrap_or(rest));
- if unquoted == "--" {
+ .strip_prefix(b"\"")
+ .map_or(token, |rest| rest.strip_suffix(b"\"").unwrap_or(rest));
+ if unquoted == b"--" {
break;
}
- let name = unquoted.split_once('=').map_or(unquoted, |(name, _)| name);
+ let name = unquoted
+ .iter()
+ .position(|&b| b == b'=')
+ .map_or(unquoted, |equals| &unquoted[..equals]);
if CLOCK_TOKENS
.iter()
- .any(|clock| normalized(name).eq(normalized(clock)))
+ .any(|clock| normalized(name).eq(normalized(clock.as_bytes())))
{
+ // A split at 0xa0 can end a token inside a character.
return Err(TimeAbiError::new(
TimeAbiCode::CmdlineClockToken,
- format!("kernel command line sets the clock parameter '{token}'"),
+ format!(
+ "kernel command line sets the clock parameter '{}'",
+ String::from_utf8_lossy(token)
+ ),
));
}
}
@@ -582,6 +597,138 @@
}
}
+ /// Regression test of BUG-13: the kernel's `isspace` (lib/ctype.c) also
+ /// counts VT (0x0b) and the byte 0xa0, the second byte of U+00A0, U+00E0
+ /// and U+0120. The kernel parses the clock parameter as a parameter of
+ /// each of these command lines, so the check rejects them. Before the fix
+ /// the check split the line's characters at ASCII whitespace and accepted
+ /// them.
+ #[test]
+ fn clock_tokens_after_kernel_whitespace_are_rejected() {
+ for cmdline in [
+ "console=hvc0\u{0b}tsc_early_khz=1000000",
+ "console=hvc0\u{a0}lapic_timer_hz=1",
+ "console=hvc0\u{e0}lapic_timer_hz=1",
+ "console=hvc0\u{120}lapic_timer_hz=1",
+ "console=hvc0\u{120}tsc-early-khz",
+ ] {
+ assert!(cmdline.bytes().any(|b| b == 0x0b || b == 0xa0));
+ assert_eq!(
+ check_command_line_clock_tokens(cmdline).unwrap_err().code,
+ TimeAbiCode::CmdlineClockToken,
+ "{cmdline:?}"
+ );
+ }
+ // The token is named in the message even when 0xa0 splits a character.
+ let error = check_command_line_clock_tokens("x\u{e0}tsc_early_khz=1").unwrap_err();
+ assert_eq!(
+ error.message,
+ "kernel command line sets the clock parameter 'tsc_early_khz=1'"
+ );
+ }
+
+ /// The check as it was before BUG-13's fix, kept to compare with: it split
+ /// the line's characters at ASCII whitespace.
+ fn check_command_line_clock_tokens_before_the_fix(cmdline: &str) -> Result<(), TimeAbiError> {
+ fn normalized(name: &str) -> impl Iterator<Item = u8> + '_ {
+ name.bytes().map(|b| if b == b'-' { b'_' } else { b })
+ }
+
+ let mut tokens = Vec::new();
+ let mut start = None;
+ let mut in_quote = false;
+ for (offset, c) in cmdline.char_indices() {
+ if c == '"' {
+ in_quote = !in_quote;
+ }
+ if c.is_ascii_whitespace() && !in_quote {
+ if let Some(start) = start.take() {
+ tokens.push(&cmdline[start..offset]);
+ }
+ } else if start.is_none() {
+ start = Some(offset);
+ }
+ }
+ if let Some(start) = start {
+ tokens.push(&cmdline[start..]);
+ }
+
+ for token in tokens {
+ let unquoted = token
+ .strip_prefix('"')
+ .map_or(token, |rest| rest.strip_suffix('"').unwrap_or(rest));
+ if unquoted == "--" {
+ break;
+ }
+ let name = unquoted.split_once('=').map_or(unquoted, |(name, _)| name);
+ if CLOCK_TOKENS
+ .iter()
+ .any(|clock| normalized(name).eq(normalized(clock)))
+ {
+ return Err(TimeAbiError::new(
+ TimeAbiCode::CmdlineClockToken,
+ format!("kernel command line sets the clock parameter '{token}'"),
+ ));
+ }
+ }
+ Ok(())
+ }
+
+ /// BUG-13's fix changes only lines with a VT or 0xa0 byte: on every
+ /// command line of up to four fragments over clock names in both
+ /// spellings, quotes, ASCII and other whitespace, `--`, `=` and multi-byte
+ /// characters, except those with a VT or 0xa0 byte, the check decides as
+ /// before the fix, with the same error code and message.
+ #[test]
+ fn clock_token_check_matches_the_code_before_the_fix() {
+ let fragments = [
+ "tsc_early_khz",
+ "tsc-early-khz",
+ "lapic_timer_hz",
+ "lapic-timer_hz",
+ "x",
+ "=1",
+ "=",
+ "\"",
+ " ",
+ "\t",
+ "\x0b",
+ "--",
+ "\u{e9}",
+ "\u{e0}",
+ ];
+ let mut lines = vec![String::new()];
+ let mut last = vec![String::new()];
+ for _ in 0..4 {
+ let mut next = Vec::new();
+ for prefix in &last {
+ for fragment in fragments {
+ next.push(format!("{prefix}{fragment}"));
+ }
+ }
+ lines.extend(next.iter().cloned());
+ last = next;
+ }
+ let (mut accepted, mut rejected) = (0, 0);
+ for line in &lines {
+ if line.bytes().any(|b| b == 0x0b || b == 0xa0) {
+ continue;
+ }
+ let after = check_command_line_clock_tokens(line);
+ let before = check_command_line_clock_tokens_before_the_fix(line);
+ match (after, before) {
+ (Ok(()), Ok(())) => accepted += 1,
+ (Err(after), Err(before)) => {
+ assert_eq!(after.code, before.code, "{line:?}");
+ assert_eq!(after.message, before.message, "{line:?}");
+ rejected += 1;
+ }
+ (after, before) => panic!("{line:?}: {after:?} != {before:?}"),
+ }
+ }
+ assert!(accepted > 0 && rejected > 0, "{accepted} {rejected}");
+ }
+
#[test]
fn test_hooks_parse() {
let hooks = TimeAbiTestHooks::parse(&[
Activity
tangruize commentedon Nov 1, 2026
Proposed patch
Patch against OpenVMM
998b9f2402050cd16d1faa897bc831ef1434be48. Save the contents below asfix.patchand rungit apply fix.patch.fix.patchopenvmm: pin the clock-token check's split at Linux's whitespace
virt: split clock-token command lines at every Linux whitespace byte
virt: split clock-token command lines at every Linux whitespace byte