Skip UID elevation for non-root users to preserve capabilities#495
Closed
xroche wants to merge 1 commit into
Closed
Skip UID elevation for non-root users to preserve capabilities#495xroche wants to merge 1 commit into
xroche wants to merge 1 commit into
Conversation
xroche
force-pushed
the
fix/capability-loss-uid-override
branch
2 times, most recently
from
February 27, 2026 12:02
4a3f974 to
842e217
Compare
xroche
marked this pull request as ready for review
February 27, 2026 12:02
The UID round-trip in open_proc_maps() and open_proc_comm() clears all process capabilities when the caller is non-root. The kernel zeroes the permitted, effective, and ambient sets whenever every UID becomes nonzero after at least one was zero (capabilities(7), "Effect of user ID changes on capabilities"). Guard both call sites with is_root(). Fixes DataDog#494 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
xroche
force-pushed
the
fix/capability-loss-uid-override
branch
from
March 16, 2026 11:47
842e217 to
d883137
Compare
Collaborator
|
Sorry for the late reply, I think the fix needs to be slightly more subtle, I'll post something. |
Collaborator
|
closing in favour of #509 |
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.
What does this PR do?
Fixes #494
Guards the UID elevation in
open_proc_maps()andopen_proc_comm()withis_root()so non-root users skip it entirely.Motivation
When ddprof runs as a non-root user with file capabilities (
cap_perfmon,cap_sys_ptrace, etc.), profiling a target that owns different file capabilities (e.g. nginx withcap_net_bind_service) triggers a UID round-trip through 0 inopen_proc_maps(). On the way back (setresuid(1000, 1000, -1)), the kernel permanently clears all capabilities from the permitted, effective, and ambient sets.This is documented in capabilities(7) under "Effect of user ID changes on capabilities":
The rule exists because the kernel treats the transition "was root, now isn't" as a credential downgrade and drops everything. See
cap_emulate_setxuid()inkernel/security/commoncap.c(called fromsetresuid).For root users the round-trip is safe: the saved-set-user-ID stays 0, so the condition never fires. For non-root users the elevation is also pointless: reading a non-dumpable process's
/proc/<pid>/mapsrequiresCAP_SYS_PTRACEregardless of UID.Additional Notes
Rebased on current main. Simplified test compared to v1.
How to test the change?
The new
user_override_caps-uttest verifies that a faileduser_override(0, 0)call (the non-root CI case) does not destroy existing capabilities.To reproduce the full bug path manually: