Summary
The chmod implementation in uutils coreutils fails to canonicalize target paths when enforcing the --preserve-root safety flag, only checking for a literal "/" path.
This allows users to use path variants or symbolic links to bypass protection and run destructive recursive permission changes against the root filesystem, potentially rendering the system unusable.
Affected context
This vulnerability arises in environments using the uutils coreutils implementation of chmod with the --preserve-root option, typically to protect against accidental or destructive recursive operations on "/".
The issue is present when chmod accepts non-canonical representations of the root directory—such as paths containing ".." segments or symbolic links that resolve to "/"—without normalizing or resolving those paths before enforcing the safety check.
It primarily affects systems where users or automation scripts rely on --preserve-root as a safety net while performing recursive permission changes on large directory trees.
Exploit preconditions
- Attack surface: Local command-line usage of uutils coreutils chmod (interactive sessions, scripts, or automated jobs).
- Required access: Ability to execute chmod with recursive flags and specify paths that resolve to the root filesystem; typically standard user or administrative shell access.
- Trigger point: Invocation of
chmod -R(or similar recursive options) with--preserve-rooton a path that is not literally/but resolves to/via path traversal (/../) or symlinks. - Why exploitation is possible: The implementation validates only the literal string of the target path against
/, without canonicalizing it or resolving symbolic links. As a result, different textual representations of the same root location bypass the safeguard intended by--preserve-root.
Why this happens
The underlying bug is a path validation flaw consistent with CWE-22: Improper Limitation of a Pathname to a Restricted Directory.
Instead of performing canonicalization (resolving .., . and symbolic links) and then verifying whether the final resolved path is the root directory, the code checks only whether the provided path string equals /.
This allows logically equivalent paths, such as /../ or symlinked paths that ultimately refer to /, to slip past the protection logic.
Conceptually, the implementation trusts the syntactic form of the path rather than its semantic, resolved location in the filesystem tree, breaking the invariant that --preserve-root should prevent recursive operations on the root.
Potential impact
- Recursive removal of permissions (e.g.,
chmod -R 000) across the root filesystem may occur. - System services and binaries can become inaccessible due to misconfigured permissions.
- Login shells and user home directories may become unreadable, causing system-wide logon failures.
- Automated processes and cron jobs may fail en masse, leading to effective denial of service.
- Recovery might require booting from external media and manual permission restoration or full system reinstallation.
General mitigation guidance
Mitigation should focus on ensuring that path-based safety mechanisms operate on resolved, canonical paths rather than raw input strings.
Recommended defensive patterns include:
- Canonicalizing all filesystem paths before applying safety checks, including resolution of
.and..segments and symbolic links. - Implementing root-preservation logic that verifies whether the resolved path is within a set of disallowed directories (e.g.,
/, critical system mount points) before performing recursive operations. - Designing CLI safety flags as secure-by-default, treating ambiguous or unresolvable paths conservatively (i.e., refuse to proceed instead of assuming safety).
- Applying the principle of least privilege to recursive permission changes: limit the scope of operations to known-safe subtrees rather than broad paths that might resolve to
/. - Encouraging operational practices that avoid running bulk
chmod -Rcommands at the filesystem root and instead target narrowly scoped paths.
How teams detect issues like this
Detection efforts should aim both at code-level issues and operational misuse patterns:
- Use static analysis or code review to flag path comparisons that rely on raw string equality (e.g.,
path == "/") instead of operating on normalized, resolved paths. - Add tests and policies ensuring that any "preserve root" or safety-guard functionality canonicalizes paths and handles symlinks explicitly.
- Monitor shell histories, automation scripts, and CI/CD pipelines for risky patterns like
chmod -Ron top-level or dynamically constructed paths, especially when coupled with safety flags that might be assumed to be robust. - Incorporate regression tests that exercise corner-case paths (e.g.,
/../, symlink chains to/) whenever filesystem safety features are modified. - Optional tooling such as linters or command-wrappers can enforce guardrails by rejecting dangerous invocations (e.g., recursive chmod near
/) regardless of the underlying implementation.

