Skip to content
Race condition Write-up Advanced

Four Bytes of Power: exploiting CVE-2021-26708 in the Linux kernel

Five race condition bugs in the Linux kernel's virtual socket implementation allowed an unprivileged local user to trigger a use-after-free, leading to local privilege escalation. The exploit bypassed SMEP and SMAP on Fedora 33 Server.

a13xp0p0v.github.io

Published on a13xp0p0v.github.io

CVE-2021-26708 is assigned to five race condition bugs in the virtual socket implementation of the Linux kernel. I discovered and fixed them in January 2021.

The author, on a13xp0p0v.github.io

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 copied a pointer to the virtual socket transport into a local variable before acquiring the socket lock, so a concurrent connect() could free the transport and leave the local pointer dangling.

Impact

An unprivileged local user could escalate to root on Fedora 33 Server, bypassing SMEP and SMAP, though the exploit relies on winning a race and on kernel warnings being readable via /dev/kmsg.

What the attacker needed

Local unprivileged user account; kernel with CONFIG_VSOCKETS and CONFIG_VIRTIO_VSOCKETS; at least two CPUs; read access to /dev/kmsg

The fix

The fix moves the assignment of the transport pointer to after the socket lock is acquired, and it was merged upstream and backported to stable trees.

How it was found

  1. Create an AF_VSOCK socket, which loads the vulnerable kernel modules.
  2. Start a thread that calls setsockopt() with SO_VM_SOCKETS_BUFFER_SIZE and a changing size value.
  3. In a second thread, call connect() twice with different svm_cid values to change the transport and free the old one.
  4. The setsockopt() thread then uses the stale transport pointer and writes four controlled bytes to freed memory.
  5. Spray the freed 64-byte slab with msg_msg objects to corrupt the security pointer.
  6. Use the corrupted security pointer to free a chosen msg_msg, then overwrite it with a crafted payload for arbitrary read.

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.

A race condition is when two parts of a program try to use the same thing at the same time, and the order they run in causes a mistake. Here, one thread changed a socket's transport while another thread was still using the old transport, so the kernel wrote to memory that had already been freed. An attacker with a normal user account could use this to take full control of the machine.

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.