Implement /proc/sys/user/max_user_namespaces - #14847
Open
copybara-service[bot] wants to merge 1 commit into
Open
copybara-service[bot] wants to merge 1 commit into
copybara-service[bot] wants to merge 1 commit into
Conversation
copybara-service
Bot
force-pushed
the
test/cl984162914
branch
5 times, most recently
from
September 19, 2026 05:10
1c975d5 to
2491027
Compare
Fixes #11210. This adds `/proc/sys/user/max_user_namespaces` and actually enforces it, rather than just exposing a readable value. The motivation is bubblewrap's `--disable-userns` (which flatpak enables by default): it writes a low limit to this file and then expects a following `unshare(CLONE_NEWUSER)` to fail. As discussed on the issue, a read-only value isn't enough — the limit has to be enforced. Each user namespace now tracks its limit plus a count of the descendant user namespaces charged to it. Creating a namespace charges the creating namespace and every ancestor up to the root; if any of them is already at its limit, creation fails with `ENOSPC` and the partial accounting is rolled back. (The nesting-depth limit keeps returning `EUSERS` as before.) The count is released when the namespace's nsfs inode is dropped, so it's held for exactly the namespace's lifetime. The file reads and writes the caller's own namespace limit and rejects negative values. There's a unit test covering the charging, rollback and release logic, and a syscall test for the file itself. I also ran it end-to-end against a `runsc` built from this branch to reproduce the bubblewrap sequence — logs in a comment below. cc @EtiennePerot FUTURE_COPYBARA_INTEGRATE_REVIEW=#13539 from mayur-tolexo:feat/proc-sys-user-max-user-namespaces d54b5da PiperOrigin-RevId: 984162914
copybara-service
Bot
force-pushed
the
test/cl984162914
branch
from
September 19, 2026 06:08
2491027 to
d09f157
Compare
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.
Implement /proc/sys/user/max_user_namespaces
Fixes #11210.
This adds
/proc/sys/user/max_user_namespacesand actually enforces it, rather than just exposing a readable value. The motivation is bubblewrap's--disable-userns(which flatpak enables by default): it writes a low limit to this file and then expects a followingunshare(CLONE_NEWUSER)to fail. As discussed on the issue, a read-only value isn't enough — the limit has to be enforced.Each user namespace now tracks its limit plus a count of the descendant user namespaces charged to it. Creating a namespace charges the creating namespace and every ancestor up to the root; if any of them is already at its limit, creation fails with
ENOSPCand the partial accounting is rolled back. (The nesting-depth limit keeps returningEUSERSas before.) The count is released when the namespace's nsfs inode is dropped, so it's held for exactly the namespace's lifetime. The file reads and writes the caller's own namespace limit and rejects negative values.There's a unit test covering the charging, rollback and release logic, and a syscall test for the file itself. I also ran it end-to-end against a
runscbuilt from this branch to reproduce the bubblewrap sequence — logs in a comment below.cc @EtiennePerot
FUTURE_COPYBARA_INTEGRATE_REVIEW=#13539 from mayur-tolexo:feat/proc-sys-user-max-user-namespaces d54b5da