Repository navigation
Conversation
When --max_cpus is larger than the number of available CPUs, initCpu() used to log a warning and return success WITHOUT setting any CPU affinity mask. The sandbox then ran on all available CPUs, silently defeating the user-requested CPU cap. Fix: convert LOG_W to LOG_E and return false so nsjail aborts loudly instead of launching with a less-restrictive cap than requested. Repro (before fix): $ nsjail --max_cpus 9999 -- /usr/bin/bash -c 'taskset -p $$' [W] initCpu(): Number of requested CPUs is bigger than ... pid 1's current affinity mask: 3f # all 6 CPUs, not 9999 Repro (after fix): $ nsjail --max_cpus 9999 -- /usr/bin/bash -c 'taskset -p $$' [E] initCpu(): Number of requested CPUs is bigger than ... [F] runChild(): Launching child process failed $ # nsjail exits 255 Runtime-verified on nsjail HEAD (f100fd9) on 6-core Linux. Matches the same 'fail closed on user-requested cap violation' pattern as the merged PRs google#283, google#284, google#285 (and PR google#310 / fail-closed-setsid by carrerasdarren-cell). A silent downgrade of a user-requested cap is the same family of defect as a silent zero-filter seccomp launch (PR google#285).
Contributor
Author
|
Following up on this PR — it's been open for two weeks without review. The change is narrow (two lines, one file) and introduces no behavior change for valid configurations; it follows the same silent-downgrade hardening pattern as #285, which was merged on 2026-08-26. Please let me know if any changes are needed, or if this can be reviewed when convenient. |
Contributor
Author
|
Hi, just checking in on this. It's been open since Sep 3. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When
--max_cpusis larger than the number of available CPUs,initCpu()used to log a warning and return success WITHOUT setting any CPU affinity mask. The sandbox then ran on all available CPUs, silently defeating the user-requested CPU cap. Convert the warning to an error and fail closed so nsjail aborts loudly instead of launching with a less-restrictive cap than requested.Repro (before fix)
Repro (after fix)
Runtime-verified on nsjail HEAD (f100fd9) on 6-core Linux.
Fix
if (nsj->njc.max_cpus() > available_cpus) { - LOG_W( + LOG_E( "Number of requested CPUs is bigger than number of available CPUs (%zu > %zu)", (size_t)nsj->njc.max_cpus(), available_cpus); - return true; + return false; }2 insertions, 2 deletions.
cpu.cconly. No behavior change for valid operator use cases.Impact
Defense-in-depth hardening. A silent downgrade of a user-requested resource cap is the same family of defect as the silent zero-filter seccomp launch fixed in PR #285. Same threat model: the user requested a stronger isolation than nsjail actually delivered, and nsjail reported success.
Notes