8000 config: enforce required fields after parsing (ProtoJSON missing-field crash) by newkpl · Pull Request #391 · google/nsjail · GitHub
[go: up one dir, main page]

Skip to content

config: enforce required fields after parsing (ProtoJSON missing-field crash) - #391

Open
newkpl wants to merge 1 commit into
google:masterfrom
newkpl:fix/protojson-required-fields
Open

newkpl wants to merge 1 commit into
google:masterfrom
newkpl:fix/protojson-required-fields

Conversation

@newkpl
@newkpl newkpl commented Nov 13, 2026
Copy link
Copy Markdown

NsJailConfig's Exe.path is a required proto2 field, but config::parseFile() never checks IsInitialized() on the parsed config, and the ProtoJSON path (util::JsonStringToMessage) — unlike TextFormat — does not enforce required fields.

A ProtoJSON config such as {"execBin": {"arg0": "ARG0ONLY"}} therefore reaches parseInternal() with has_exec_bin=1, has_path=0, arg_size=0, where nsj->argv[0] = njc.exec_bin().arg0() writes into an empty std::vector → deterministic SEGV (null dereference in the libstdc++ string assignment), reproduced 3/3 at HEAD (d1d9af3) with an ASan-instrumented build: SEGV on unknown address 0x000000000000, top frame config::parseInternal ← config::parseFile ← cmdline::parseArgs ← main. Also reproduced in a plain (non-sanitizer) micro-repro of the exact code shape (SIGSEGV, rc=139).

A sibling variant (args present, no path) does not crash but silently overwrites argv[0], and setupArgv() then promotes it to the executed program — wrong-program execution from a malformed config.

Fix:

  1. parseFile(): require IsInitialized() after either successful parse branch, rejecting any config missing required fields on both paths — this fixes the whole missing-required-field class, not just this one field.
  2. parseInternal(): apply arg0 only when the argv vector is non-empty (defense in depth at the exact UB site).

Verification: with this patch, both JSON attack variants are cleanly rejected ("Config file ... is missing required fields", rc=255, no sanitizer report), and valid TextFormat/ProtoJSON control configs behave unchanged. TextFormat twins of the attack configs were already rejected by the parser, confirming the JSON path was the gap.

Severity is low/hardening: the config file is operator-supplied; impact is a launcher crash or wrong-program execution from a malformed config. No sandbox-boundary, privilege, or jailed-process impact.

Disclosure: this patch was prepared with AI assistance; the crash, the sibling variant, and the fix were all reproduced and verified on local builds before submission.

@google-cla
google-cla Bot commented Nov 13, 2026
Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@newkpl
newkpl commented Nov 13, 2026
Copy link
Copy Markdown
Author

CLA signed (Google Individual CLA, GitHub username newkpl) — rechecking the CLA status.

@newkpl newkpl closed this Nov 13, 2026
@newkpl newkpl reopened this Nov 13, 2026

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.

1 participant

0