Skip to content
Access control Write-up Advanced

Coredump Creation

The Linux kernel allows a child process of a setuid program to create a root-owned core dump if the setuid program drops privileges and then executes a child. An attacker can exploit this to write a core file containing a logrotate configuration into /etc/logrotate.d, leading to arbitrary code execution as root.

alephsecurity.com

Published on alephsecurity.com

During our Apport research we exploited Ubuntu’s crash handler, and following that, we decided to once again audit the coredump creation code. But this time, we chose to focus on a more general different target, rather than a specific crash handler.

The author, on alephsecurity.com

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 sets the dumpable attribute of a process based on the credentials at exec time, but child processes of setuid programs inherit a dumpable state that allows core dumps even when the child runs with root privileges.

Impact

An attacker with limited sudo rights could execute arbitrary commands as root by writing a malicious logrotate configuration via a core dump; the exploit is not possible in default sudo configurations of popular distributions.

What the attacker needed

Sudo configured to allow a specific command; ability to set environment variables; ability to set resource limits; logrotate installed and active

The fix

Set /proc/sys/kernel/core_pattern to an absolute safe directory and add pam_limits.so to sudo's PAM configuration with RLIMIT_CORE set to 0.

How it was found

  1. Set the XAUTHORITY environment variable to contain a logrotate configuration.
  2. Change the current directory to /etc/logrotate.d.
  3. Set the RLIMIT_CORE resource limit to unlimited.
  4. Set RLIMIT_CPU to 0 or send SIGQUIT to the parent process to crash the child.
  5. Execute the permitted sudo command (e.g., /usr/bin/true).
  6. Repeat the exploit until a core file is created in /etc/logrotate.d.

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.

When a program crashes, Linux can save its memory to a file called a core dump. Normally, programs that run with extra privileges (setuid programs) do not create core dumps to avoid leaking secrets. This research found that if such a program starts another program after dropping its privileges, the child can still create a core dump owned by root. An attacker can abuse this to place a malicious file in a system directory, which later gets executed with high privileges.

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.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

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.