Summary
A flaw in OpenWrt's hotplug_call environment filtering allows an attacker to inject a controlled PATH variable into hotplug scripts.
Because PATH is not correctly stripped, an attacker who can influence the hotplug environment may redirect which binaries are executed by privileged procd-invoked scripts, potentially leading to privilege escalation.
Affected context
This vulnerability affects OpenWrt-based systems where:
- The procd hotplug mechanism invokes scripts from
/etc/hotplug.d/* - Environment variables supplied to hotplug_call are expected to be filtered before script execution
- Downstream scripts rely on the system PATH rather than using fully qualified executable paths
The issue arises because the PATH variable from the caller's environment is not removed as intended, even when scripts execute with elevated privileges.
Exploit preconditions
- Attack surface: Hotplug events processed by procd and related subsystems that use hotplug_call
- Required access: Ability to influence or set environment variables for processes that trigger hotplug_call (e.g., via controlled services, scripts, or interfaces that emit hotplug events)
- Trigger point: Execution of hotplug scripts under
/etc/hotplug.dwhere PATH determines which binaries are run - Why exploitation is possible: The filtering logic compares full environment strings such as
PATH=/some/valueagainst the literal"PATH"usingstrcmpinstead ofstrncmp, causing the filter to miss the PATH variable entirely and allowing untrusted values to reach privileged scripts.
Why this happens
The root cause is a flawed environment sanitization routine in hotplug_call, where the code attempts to strip sensitive environment variables but performs an incorrect comparison.
Instead of comparing only the variable name portion ("PATH") of each environment string, the implementation uses strcmp on the full string (e.g., "PATH=/usr/bin"), which never matches the bare "PATH" token.
This logic error maps to CWE-187: Partial Comparison, and it leads to a violation of CWE-269: Improper Privilege Management, because privileged scripts inherit untrusted PATH values that can alter which executables are run.
Conceptually, this is an environment-variable injection issue, where assumptions about sanitized context do not hold due to a subtle string comparison bug.
Potential impact
- Attackers may control which binaries are executed by privileged hotplug scripts by pointing PATH to attacker-controlled directories.
- Malicious or trojaned binaries placed in accessible locations may be executed with elevated privileges.
- System integrity may be compromised through unauthorized configuration changes or code execution.
- Subsequent lateral movement or persistence could be established using the elevated context of the affected scripts.
General mitigation guidance
Effective mitigation focuses on hardening environment handling and reducing reliance on inherited state:
- Treat all environment variables as untrusted, especially in privileged or system service contexts.
- Implement strict environment sanitization: explicitly whitelist variables that are allowed, rather than blacklisting a few sensitive names.
- Use correct string handling for variable name comparison (e.g., comparing up to the
=delimiter) to avoid partial or failed matches. - In privileged scripts, prefer fully qualified executable paths instead of relying on PATH resolution, and avoid modifying PATH unless strictly necessary.
- Run procd-invoked scripts with the minimum necessary privileges and, where possible, in restricted or sandboxed execution contexts.
How teams detect issues like this
Detection can rely on a combination of code- and behavior-focused techniques:
- Static analysis and code review: Flag patterns where environment variables are filtered using full-string comparisons instead of separating variable names and values; pay special attention to checks against strings like
"PATH","LD_PRELOAD", and similar. - Configuration and script review: Examine hotplug and other privileged scripts for reliance on inherited PATH, and for executions that omit fully qualified paths.
- Runtime monitoring: Observe for anomalous PATH values in processes spawned by procd or other system daemons; baseline normal PATH usage and alert on unexpected directories or user-writable paths.
- Policy enforcement: Use CI policies or security checks that require explicit environment sanitization for privileged components and discourage ad-hoc environment forwarding.

