Skip to content

kernel_version: allow "." before the vendor suffix - #472

Open
nobbs wants to merge 1 commit into
cyphar:mainfrom
nobbs:fix/kernel-version-dot-suffix
Open

nobbs wants to merge 1 commit into
cyphar:mainfrom
nobbs:fix/kernel-version-dot-suffix

Conversation

@nobbs

@nobbs nobbs commented Nov 17, 2026

Copy link
Copy Markdown

Fixes #471.

Summary

parse_kernel_version cut the release string at the first character that was neither a digit nor ., so 6.18.52.mshv1-2.azl3 (Azure Linux guest kernel on AKS Pod Sandboxing / Kata) became 6.18.52. and failed on the empty trailing component. host_kernel_version() then panics and runc aborts container startup.

 suffix starts at the first byte that is
-  not a digit and not "."
+  not a digit and not ".", or
+  a "." followed by an ASCII letter

Stray dots that the existing tests reject on purpose (42.12., 4.10.-default, 1..3) are still rejected.

Evidence

New test parse_kernel_version_with_dot_suffix, run in rust:1.99-trixie:

parse_kernel_version("6.18.52.mshv1-2.azl3") == Some(6.18.52)
parse_kernel_version("6.18.52-mshv1-2.azl3") == Some(6.18.52)
parse_kernel_version("5.4.0.custom")         == Some(5.4.0)
parse_kernel_version("4.19.112.x86_64")      == Some(4.19.112)
parse_kernel_version("2.6.16.48.foo.1")      == Some(2.6.16.48)
  • Before: cargo test --lib utils::kernel_version → 15 passed; 1 failed (parse_kernel_version_with_dot_suffix)
    After: 16 passed; 0 failed; cargo fmt --check and cargo clippy --all-targets clean.

Merge Danger

Door: two-way

Blast Radius: narrow

Only changes which release strings parse; strings that parsed before give the same result. Releases of the form X.Y.Z.<letter>… now parse instead of panicking.

Some kernels separate their vendor suffix from the version with a "."
rather than a "-". For instance, the Azure Linux guest kernel used by
AKS Pod Sandboxing (Kata Containers) reports "6.18.52.mshv1-2.azl3".
Previously we only stripped the suffix at the first character that was
neither a digit nor a ".", which left a trailing empty component
("6.18.52.") that failed to parse, causing host_kernel_version() to
panic and runc to abort container startup.

So, also treat a "." followed by a letter as the start of the suffix.
Other stray dots ("42.12.", "4.10.-default", "1..3") are still rejected
as malformed.

Fixes cyphar#471

Signed-off-by: Alexej Disterhoft <alexej@disterhoft.de>
Copilot AI balanced review requested due to automatic review settings November 17, 2026 10:28

This comment was marked as spam.

@cyphar cyphar added the llm-generated Used to tag LLM-generated issues or PRs, which some maintainers may choose to de-prioritise. label Nov 22, 2026
Comment on lines 129 to 136
let kver = kver_str
.split('.')
.map(|num| match num {
"" => None, // version components must be non-empty
_ => num.parse().ok(), // version components must be valid numbers
})
.collect::<Option<Vec<_>>>()
.map(KernelVersion);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a better solution would be to still dot-split the version and just cut it off at the first invalid component instead of making the split-determination more complicated. I'll push a version of this (as well as a patch that removes the stupid expect that triggered the crash).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llm-generated Used to tag LLM-generated issues or PRs, which some maintainers may choose to de-prioritise.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Kernel version parsing rejects releases with a dot before the vendor suffix

3 participants