Skip to content

fix(unikraft): Quote env vars and args on the kernel command line - #1211

Open
arshil42 wants to merge 2 commits into
urunc-dev:mainfrom
arshil42:fix/unikraft-quote-args
Open

arshil42 wants to merge 2 commits into
urunc-dev:mainfrom
arshil42:fix/unikraft-quote-args

Conversation

@arshil42

Copy link
Copy Markdown

Description

Unikraft splits its kernel command line into arguments with uk_argnparse (lib/ukargparse/argparse.c), which separates arguments at whitespace and treats ', " and \ as special characters. urunc joined the environment variables (env.vars=[ ... ]) and the command arguments with spaces as they were, so, as shown in #1103:

  • URUNC=hello world reached the guest as URUNC=hello;
  • URUNC={"level":"info"} reached it as URUNC={level:info};
  • URUNC=don't left an unmatched quote, and the guest did not start;
  • the arguments -g "daemon off;" reached it as -g, daemon, off;.

This puts every value that contains whitespace, a quote or a backslash in single quotes. Inside single quotes uk_argnparse keeps every character as it is, including " and \. A single quote in the value ends the quoted part, is added as \' (outside quotes a backslash makes the next character literal) and starts a new quoted part, so don't becomes 'don'\''t'. Values without such characters are not changed, so existing command lines stay the same. uk_argnparse is the same from 0.14.0 to 0.21.0, so this works for the versions before 0.16.1 too.

On hyperlight-unikraft, the command is passed as the value of one --guest-exec option instead of on the kernel command line, so it is left as it was there.

What this does not change, as discussed in #1103: a ] at the end of an environment variable still ends the env.vars list (a Unikraft rule), and empty arguments are still dropped by uk_argnparse.

The first commit adds me to .github/contributors.yaml. It is the same commit as in #1210, so the two PRs merge cleanly in either order.

Related issues

How was this tested?

On Ubuntu (WSL2, x86_64), in a fresh clone of the branch:

  • New pkg/unikontainers/unikernels/unikraft_args_test.go:
    • TestQuoteUnikraftArg covers plain values, spaces, tabs, double quotes (the JSON value from the issue), a single quote (don't) and a backslash;
    • TestUnikraftCommandStringQuotesEnvAndArgs checks the full command line for the env value and the -g "daemon off;" arguments from the issue;
    • TestUnikraftHyperlightCommandIsNotQuoted checks that --guest-exec is unchanged.
  • I checked the quoting against the uk_argnparse source linked above, case by case.
  • go test ./pkg/unikontainers/unikernels/ ./pkg/unikontainers/hypervisors/ passes.
  • golangci-lint run with v2.15.0 (the version used by make lint) over the whole repository: 0 issues.
  • commitlint and cspell with the configs in .github/linters: no issues.
  • This branch and fix(unikraft): Use the container's subnet mask in netdev.ip #1210 merge without conflicts, and the tests pass on the result.

I could not run the e2e tests: this machine has no KVM or containerd setup.

LLM usage

Claude Opus 5.5 (claude-opus-5-5, through Claude Code) was used to read the Unikraft parser, write the change and the tests, and draft this description. I reviewed the changes and ran the tests above before opening the PR.

Checklist

  • I have read the contribution guide.
  • The linter passes locally (make lint).
  • The e2e tests of at least one tool pass locally (make test_ctr, make test_nerdctl, make test_docker, make test_crictl).
  • If LLMs were used: I have read the llm policy.

Signed-off-by: Arshil Ahmed <194646586+arshil42@users.noreply.github.com>
Unikraft splits its kernel command line into arguments with a parser
that separates them at whitespace and treats quotes and backslashes as
special characters. urunc joined the environment variables and the
command arguments with spaces as they were, so a value with a space was
split, quotes were removed, and an unmatched single quote kept the guest
from starting.

Put every value that contains whitespace, a quote or a backslash in
single quotes, inside which the parser keeps every character as it is,
and write each single quote in it as '\''. Other values do not change.
On hyperlight-unikraft the command is passed as one --guest-exec option,
so it stays as it was there.

Fixes: urunc-dev#1103
Signed-off-by: Arshil Ahmed <194646586+arshil42@users.noreply.github.com>
@netlify

netlify Bot commented Nov 17, 2026

Copy link
Copy Markdown

👷 Deploy request for urunc pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 5a6cf47

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unikraft env and args with spaces or quotes get mangled

1 participant