Skip to content

tmpfs: Clear security.capability xattr on write#13112

Merged
copybara-service[bot] merged 2 commits intomasterfrom
test/cl911628845
May 7, 2026
Merged

tmpfs: Clear security.capability xattr on write#13112
copybara-service[bot] merged 2 commits intomasterfrom
test/cl911628845

Conversation

@copybara-service
Copy link
Copy Markdown

tmpfs: Clear security.capability xattr on write

When a non-privileged user writes to a file on tmpfs, Linux clears both the setuid/setgid mode bits and the security.capability xattr via file_remove_privs. The mode bit clearing was already implemented through ClearSUIDAndSGID in the pwrite path, but the xattr removal was missing, so file capabilities survived content replacement. An unprivileged user could overwrite a capability-bearing binary and execute it with the retained privileges.

The fix adds a KillPriv method on SimpleExtendedAttributes that removes security.capability without permission checks (matching Linux's cap_inode_killpriv, where the kernel is the actor), and calls it from the tmpfs pwrite path alongside the existing ClearSUIDAndSGID.

The gofer filesystem is not affected because it explicitly blocks security.* xattr writes to the host filesystem.

Fixes #13063

FUTURE_COPYBARA_INTEGRATE_REVIEW=#13072 from shayonj:fix-cap-survive-write 72063bf

When a non-privileged user writes to a file on tmpfs, Linux clears both
the setuid/setgid mode bits and the security.capability xattr via
file_remove_privs. The mode bit clearing was already implemented through
ClearSUIDAndSGID, but the xattr removal was missing, so file
capabilities survived content replacement. An unprivileged user could
overwrite a capability-bearing binary and execute it with the retained
privileges.

Fixes #13063
@copybara-service copybara-service Bot added the exported Issue was exported automatically label May 7, 2026
@copybara-service copybara-service Bot force-pushed the test/cl911628845 branch 4 times, most recently from a7f6e0d to b45941b Compare May 7, 2026 16:58
@copybara-service copybara-service Bot merged commit d4d9d66 into master May 7, 2026
@copybara-service copybara-service Bot deleted the test/cl911628845 branch May 7, 2026 17:39
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.

File Capabilities Survive Non-Root Rewrite

2 participants