Skip to content
Memory corruption Write-up Advanced

Exploiting a heap overflow in the FreeBSD wi-fi stack

A heap overflow in the FreeBSD Wi-Fi stack occurs because the MeshId option length is not validated before a memcpy into a fixed-size buffer. An attacker within Wi-Fi range can send a crafted beacon frame to overwrite kernel memory and potentially execute arbitrary code in the kernel.

thezdi.com

Published on thezdi.com

Our goal is to achieve kernel remote code execution on a target FreeBSD system using a heap overflow vulnerability in the Wi-Fi stack of the FreeBSD kernel. This vulnerability has been assigned CVE-2022-23088 and affects all FreeBSD versions since 2009, along with many FreeBSD derivatives such as pfSense and OPNsense.

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

Likely the lack of a length check on the MeshId information element before copying it into a fixed-size buffer in the scan entry structure.

Impact

An attacker within Wi-Fi range could execute arbitrary code in the kernel, leading to a full system compromise, as demonstrated by injecting a kernel implant.

What the attacker needed

Attacker within Wi-Fi range; target scanning for Wi-Fi networks; no authentication required

The fix

The vulnerability was fixed by adding a sanity check on the MeshId option length before the memcpy.

How it was found

  1. Send a beacon frame with an oversized MeshId option to trigger the heap overflow.
  2. Use the overflow to overwrite the se_ies data and len fields, creating a write-what-where primitive.
  3. Send a second corrective beacon frame to set ies->data to NULL and ies->len to 0 to avoid a crash.
  4. Use the primitive to write an implant at physical address 0x1000 via the direct map.
  5. Overwrite an L3 page table entry to map kernel text as writable and the implant as executable.
  6. Patch the beginning of sta_input() to jump to the implant, then send a final corrective frame.

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 your computer scans for Wi-Fi networks, it listens to small messages called beacon frames that nearby routers broadcast. This bug is like a router sending a beacon with a field that says 'I am very long' but the computer doesn't check the length before copying it into a small box, so it spills over and corrupts other data. An attacker nearby can use this to take control of the computer's core system (the kernel).

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.