Harden log pager execution with LESSSECURE#197
Open
calh wants to merge 1 commit intogdraheim:masterfrom
Open
Conversation
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.
Motivation
logsubcommand previously launchedlesswith the inherited environment which allows shell escapes or external helper execution (viaLESSOPEN/LESSCLOSE) and can lead to privilege escalation when run with elevated permissions.Description
files/docker/systemctl3.pyinSystemctlJournal.tail_log_fileto setLESSSECURE=1before invoking the pager.LESSOPENandLESSCLOSEfrom the child environment to avoid executing external helper scripts.os.spawnvpe/os.execvpe(instead ofspawnvp/execvp) so the sanitized environment is applied when startingless.--no-pager,--follow, and--linescode paths and only harden the interactive pager branch.Testing
python -m py_compile files/docker/systemctl3.pywhich succeeded.python files/docker/systemctl3.py --helpwhich produced usage output successfully.Criticality: high (attack path: high)
Status: new
Summary:
Introduced a new log subcommand that spawns
lesswithout secure mode, enabling a pager escape to root when the command is run with elevated privileges.This commit adds a
logsubcommand that spawns external viewers for service logs. When no--no-pageris used, it invokes/usr/bin/lessdirectly viaos.spawnvpwithout settingLESSSECUREor otherwise disabling less’s shell escape features. If an unprivileged user is permitted to runsystemctl log <unit>with elevated privileges (a common sudoers pattern for log viewing), they can drop into a root shell via less’s!command or LESSOPEN/LESSCLOSE, resulting in privilege escalation. Mitigations include settingLESSSECURE=1, using a non-interactive viewer, or always forcing--no-pagerwhen privileged.Validation:
Rubric:
systemctl log(artifacts/output.txt).Attack-path analysis:
Final: high | Decider: model_decided | Matrix severity: medium | Policy adjusted: medium
Rationale: Kept high: the code path is in the core runtime and results in straightforward root shell access when
systemctl logis delegated via sudo (a common operational pattern). While local-only and configuration-dependent, the impact is full privilege escalation with no in-code mitigation (no LESSSECURE).Likelihood: medium - Exploitation is local-only and depends on a sudoers rule or equivalent privilege delegation for
systemctl log; this is plausible but configuration-dependent.Impact: high - If run with elevated privileges, less’s shell escape allows arbitrary commands as root, compromising container processes and filesystem.
Assumptions:
systemctl log <unit>for log viewing./usr/bin/lessand pager use is not disabled (--no-pagernot set).systemctl logwith elevated privileges (sudoers or equivalent)--no-pager)/usr/bin/lessis presentPath:
[user] -> [sudoers systemctl log] -> [systemctl3 log_unit_from] -> [less !] -> [root shell]
Narrative:
systemctl3.py defines LESS_CMD as
/usr/bin/lessandlog_unit_fromuses os.spawnvp to execute it whenever paging is enabled (lines 165–167 and 2156–2173). There is no code settingLESSSECUREor otherwise disabling less shell escapes. If a non-root user is allowed to runsystemctl logwith elevated privileges (a common sudoers pattern for log viewing), they can use less’s escape (!or LESSOPEN) to execute commands as root, resulting in local privilege escalation.Controls:
--no-pagerdisables the less invocationBlindspots:
systemctl logis delegated.