Skip to content

Implement /proc/sys/user/max_user_namespaces - #14847

Open
copybara-service[bot] wants to merge 1 commit into
masterfrom
test/cl984162914
Open

copybara-service[bot] wants to merge 1 commit into
masterfrom
test/cl984162914

Conversation

@copybara-service

Copy link
Copy Markdown

Implement /proc/sys/user/max_user_namespaces

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

@copybara-service copybara-service Bot added the exported Issue was exported automatically label Sep 19, 2026
@copybara-service
copybara-service Bot force-pushed the test/cl984162914 branch 5 times, most recently from 1c975d5 to 2491027 Compare September 19, 2026 05:10
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

exported Issue was exported automatically

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement /proc/sys/user/max_user_namespaces ?

1 participant