Skip to content
Race condition Write-up Advanced

CVE-2020-7460: FreeBSD Kernel Privilege Escalation

A time-of-check to time-of-use flaw in the 32-bit sendmsg() system call allowed an unprivileged user to modify control message lengths after validation, causing a kernel heap overflow. An attacker could exploit this to overwrite an mbuf's function pointer and execute kernel code, escalating to root.

thezdi.com

Published on thezdi.com

The goal is to achieve kernel code execution on FreeBSD starting from an unprivileged user, using a TOCTOU vulnerability present in the 32-bit sendmsg() system call. This vulnerability has been assigned CVE-2020-7460 and affects all FreeBSD kernels since 2014.

The author, on thezdi.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 validated the total length of control messages in a first loop, but then copied the data in a second loop without revalidating, allowing userland to change the lengths in between (a TOCTOU race).

Impact

An unprivileged local user could escalate to root, but only on 64-bit FreeBSD systems; 32-bit platforms are not vulnerable.

What the attacker needed

Local unprivileged access; 64-bit FreeBSD kernel; ability to run a 32-bit binary

The fix

The vulnerability was fixed in FreeBSD; users should upgrade to a supported branch dated after the correction date and reboot.

How it was found

  1. Create a contiguous block of valid cmsghdr structures.
  2. Spawn a thread that repeatedly calls sendmsg() with the block.
  3. Spawn another thread that repeatedly increases and then restores the last cmsg_len field.
  4. Wait for the race to trigger a kernel heap overflow.
  5. Use UDP send/receive to allocate and free mbufs, shaping the heap.
  6. Overwrite an mbuf's ext_free pointer and trigger its deallocation to start a ROP chain.

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 bug in the FreeBSD operating system kernel, the core part that controls everything. The kernel checked the size of some data, but then used it later without rechecking, so a program could change the size in between and cause the kernel to write too much data into a small buffer. That overflow let the attacker take control of the kernel and become the all-powerful root user.

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.