Linux Local Privilege Escalation via SUID /proc/pid/mem Write
A flaw in the Linux kernel's /proc/pid/mem permission checks allowed a local attacker to write to the memory of a setuid process, enabling privilege escalation to root. The exploit used a race condition with self_exec_id and a non-PIE su binary to inject shellcode.
blog.zx2c4.com
Published on blog.zx2c4.com
Introducing Mempodipper, an exploit for CVE-2012-0056. /proc/pid/mem is an interface for reading and writing, directly, process memory by seeking around with the same addresses as the process's virtual memory space. In 2.6.39, the protections against unauthorized access to /proc/pid/mem were deemed sufficient, and so…
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
The kernel's permission check for writing to /proc/pid/mem relied on a self_exec_id that could be bypassed by forking and execing in a child process, and the check_mem_permission function allowed writing to self without sufficient restrictions.
What the attacker needed
Local access to the system; Linux kernel >=2.6.39; setuid binary not compiled with PIE; ability to execute code
How it was found
- Fork a child process and exec a new process in the child.
- In the child, open /proc/<parent-pid>/mem to get a file descriptor for the parent's memory.
- Pass the file descriptor from the child back to the parent via a Unix domain socket.
- In the parent, use dup2 to assign the memory file descriptor to stderr.
- Resolve the address of exit@plt in the su binary (e.g., using objdump).
- Seek to the appropriate offset in memory and exec su with shellcode as an argument to write and execute the shellcode.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
This is a local privilege escalation bug in the Linux kernel. The /proc/pid/mem file lets programs read and write another process's memory, but the kernel's permission checks were flawed. An attacker with a normal account could trick a setuid program (which runs with root privileges) into writing attacker-controlled data into its own memory, then execute that data to gain root access.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.