Skip to content
Race condition Write-up Advanced

CVE-2013-0871: Linux arbitrary kernel-mode code execution

A race condition in the Linux kernel's ptrace implementation allowed a local attacker to corrupt the kernel stack and execute arbitrary code in kernel mode. The flaw involved modifying a traced process's registers while it was exiting, overwriting the saved return address on the stack.

seclists.org

Published on seclists.org

A race conditon in ptrace can lead to kernel stack corruption and arbitrary kernel-mode code execution.

The author, on seclists.org

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

Likely the kernel did not properly synchronise register writes via PTRACE_SETREGS with the traced process's exit path, so the write landed on a stack frame that no longer held the full register set.

Impact

A local attacker could achieve arbitrary kernel-mode code execution, potentially taking full control of the system.

What the attacker needed

Local access to the system; ability to use ptrace; ability to create real-time processes

The fix

The issue was fixed by three kernel commits from Oleg Nesterov.

How it was found

  1. Attach to a child process with ptrace and set tracing options.
  2. Stop the child at a syscall entry and read its registers.
  3. Start a high-priority real-time process pinned to the same CPU to control scheduling.
  4. Kill the child process while it is exiting.
  5. Write the child's registers with PTRACE_SETREGS, overwriting the saved return address on the kernel stack.

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.

The Linux kernel is the core of the operating system. A race condition is a bug where two things happen at the same time in an unexpected order, causing a mess. Here, a program that watches another program (ptrace) could change its saved state at the wrong moment, letting an attacker take over the computer's core.

What is Race condition?

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.

Similar reports

View all

Same bug class and techniques, clearest first.

Race conditions

The lesson behind this report.

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.