Hacktricks-skills cgroup-security-analyzer
Analyze Linux cgroups for security assessment, privilege escalation opportunities, and resource limit analysis. Use this skill whenever the user mentions cgroups, control groups, container resource limits, Linux process isolation, systemd slices, or wants to audit container security configurations. Also trigger when investigating potential privilege escalation paths through cgroup manipulation, analyzing /proc/self/cgroup output, or examining /sys/fs/cgroup settings.
git clone https://github.com/abelrguezr/hacktricks-skills
skills/linux-hardening/privilege-escalation/docker-security/cgroups/SKILL.MDCGroup Security Analyzer
A skill for analyzing Linux Control Groups (cgroups) to identify security configurations, resource limits, and potential privilege escalation vectors.
What This Skill Does
This skill helps you:
- Parse and interpret cgroup configurations from
and/proc/self/cgroup/sys/fs/cgroup - Identify resource limits (memory, CPU, PIDs, devices) that may be exploitable
- Detect cgroup v1 vs v2 configurations and their security implications
- Find potential privilege escalation paths through cgroup manipulation
- Analyze container isolation effectiveness
When to Use This Skill
Use this skill when:
- You need to understand what cgroups a process belongs to
- You're auditing container security or resource limits
- You're investigating privilege escalation opportunities
- You need to parse
or/proc/self/cgroup
output/sys/fs/cgroup - You're analyzing systemd slice configurations
- You want to check if cgroup limits can be bypassed or exploited
Quick Start
View Current Process Cgroups
# See which cgroups your current shell belongs to cat /proc/self/cgroup # For a specific process cat /proc/<PID>/cgroup
Analyze Cgroup Configuration
Use the bundled scripts to automate analysis:
# Full cgroup security analysis ./scripts/analyze-cgroups.sh # Check specific cgroup limits ./scripts/check-cgroup-limits.sh <cgroup-path> # Parse cgroup output and explain it ./scripts/parse-cgroup-output.sh
Understanding Cgroup Output
Cgroup v1 Format
Each line in
/proc/self/cgroup follows this pattern:
<controller-number>:<controller-names>:<hierarchy-path>
Example:
12:rdma:/ 11:net_cls,net_prio:/ 10:perf_event:/ 9:cpuset:/ 8:cpu,cpuacct:/user.slice 7:blkio:/user.slice 6:memory:/user.slice 5:pids:/user.slice/user-1000.slice/session-2.scope 4:devices:/user.slice 3:freezer:/ 2:hugetlb:/testcgroup 1:name=systemd:/user.slice/user-1000.slice/session-2.scope 0::/user.slice/user-1000.slice/session-2.scope
Key observations:
- Lines 2-12: cgroups v1 controllers (each number = different controller)
- Line 1: cgroups v1 management (systemd, no controller)
- Line 0: cgroups v2 (unified hierarchy, no controllers listed)
- Paths like
: systemd-managed user sessions/user.slice - Paths like
: system services/system.slice
Cgroup v2 Format
On cgroups v2-only systems, you'll see only line 0:
0::/user.slice/user-1000.slice/session-2.scope
The unified hierarchy is at
/sys/fs/cgroup/unified or /sys/fs/cgroup.
Security-Relevant Cgroup Controllers
Memory Controller
Files to check:
- Current memory usagememory.current
- Memory limit ("max" means unlimited)memory.max
- Memory threshold for throttlingmemory.high
Security implications:
- Unlimited memory (
) can lead to DoSmax - Memory limits can be exploited for resource exhaustion attacks
- Check if limits are inherited from parent cgroups
PID Controller
Files to check:
- Current process countpids.current
- Maximum processes allowedpids.max
Security implications:
- Low PID limits can cause fork bombs to fail
- Unlimited PIDs allow process flooding
- Can be used to detect container escape attempts
CPU Controller
Files to check:
- CPU usage statisticscpu.stat
- CPU time limitscpu.max
- CPU scheduling prioritycpu.weight
Security implications:
- CPU limits can be bypassed in some configurations
- Weight settings affect process priority
- Can detect resource-intensive malicious processes
Devices Controller
Files to check:
- Allowed device accessdevices.list
Security implications:
- Critical for container security
- Overly permissive device access enables escapes
- Check for
,/dev/mem
access/dev/kmem
Common Privilege Escalation Vectors
1. Cgroup Root Access
The root cgroup allows direct process placement, bypassing systemd:
# Check if you can write to root cgroup echo $$ > /sys/fs/cgroup/cgroup.procs
Risk: If writable, you can remove processes from systemd management.
2. Subtree Control Manipulation
Child cgroups can enable controllers not present in parents:
# Check subtree control cat cgroup.subtree_control # Enable controllers (requires root) echo "+cpu +pids" > cgroup.subtree_control
Risk: Misconfigured subtree control can allow privilege escalation.
3. Resource Limit Bypass
Limits may be inherited from parent cgroups:
# Check parent limits cat /sys/fs/cgroup/memory.max cat /sys/fs/cgroup/user.slice/memory.max
Risk: Parent limits may be more restrictive than child limits.
4. Device Access
Check device permissions:
cat /sys/fs/cgroup/devices.list
Risk: Access to
/dev/mem, /dev/kmem, or /dev/sda can enable escapes.
Analysis Workflow
Step 1: Identify Cgroup Version
# Check for v2 unified hierarchy ls -la /sys/fs/cgroup/ # If you see 'unified' or only line 0 in /proc/self/cgroup, it's v2 # If you see multiple numbered lines, it's v1 or hybrid
Step 2: Map Current Cgroups
# Get your cgroup paths cat /proc/self/cgroup | grep -v '^0::' | cut -d: -f3 | sort -u # For each path, check the cgroup directory for path in $(cat /proc/self/cgroup | cut -d: -f3 | sort -u); do echo "=== $path ===" ls -la /sys/fs/cgroup/$path/ 2>/dev/null done
Step 3: Check Resource Limits
# Memory cat /sys/fs/cgroup/memory.max 2>/dev/null || echo "No memory limit" # PIDs cat /sys/fs/cgroup/pids.max 2>/dev/null || echo "No PID limit" # CPU cat /sys/fs/cgroup/cpu.max 2>/dev/null || echo "No CPU limit"
Step 4: Identify Security Issues
Look for:
values (unlimited resources)max- Writable cgroup.procs files
- Permissive device lists
- Missing controllers in expected cgroups
- Inherited limits from parent cgroups
Scripts Reference
analyze-cgroups.sh
Performs a comprehensive cgroup security analysis:
- Identifies cgroup version
- Lists all cgroups for current process
- Checks resource limits
- Identifies potential security issues
check-cgroup-limits.sh <cgroup-path>
Checks specific limits for a cgroup path:
- Memory limits
- PID limits
- CPU limits
- Device access
parse-cgroup-output.sh
Parses
/proc/self/cgroup output and explains:
- Each controller
- Hierarchy structure
- Security implications
Best Practices
- Always check parent cgroups - Limits may be inherited
- Verify cgroup version - v1 and v2 have different security models
- Check device access - Critical for container escapes
- Look for writable files - cgroup.procs, subtree_control
- Understand systemd integration - Many cgroups are managed by systemd
References
- Current process cgroup membership/proc/self/cgroup
- Cgroup filesystem interface/sys/fs/cgroup/
- Process list for a cgroupcgroup.procs
- Thread list for a cgroupcgroup.threads
- Controller enablement for child cgroupscgroup.subtree_control
Troubleshooting
"Permission denied" when accessing cgroup files
You need root privileges to modify cgroups. Reading is usually allowed.
Cgroup path doesn't exist
The cgroup may have been removed or the process moved. Check
/proc/<pid>/cgroup for the current state.
"max" value in limit files
This means unlimited. Check parent cgroups for inherited limits.
Multiple cgroup versions
Systems can run v1 and v2 concurrently. Check both
/sys/fs/cgroup/ and /sys/fs/cgroup/unified/.