Skip to content
Memory corruption Write-up Advanced

CVE-2023-4039: GCC's -fstack-protector fails to guard dynamic stack allocations on ARM64

GCC's stack smashing protection on ARM64 fails to guard dynamically sized stack allocations, so a contiguous overflow of a variable-length array or alloca buffer can overwrite the saved return address without detection. An attacker could exploit such overflows to control execution flow, but the issue is a mitigation weakness and not directly exploitable.

Tom Hebb Follow

Published on rtx.meta.security

GCC’s stack smashing protection, which keeps attackers from exploiting stack buffer overflow bugs in code it compiles, has no effect when the vulnerable buffer is a variable-length array or alloca() allocation and the target architecture is 64-bit ARM. This issue is a mitigation weakness and is not exploitable…

Tom Hebb, Red Team X, on rtx.meta.security

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, GCC's AArch64 backend places dynamically sized stack allocations below the saved registers and stack guard, so a contiguous overflow of such an allocation reaches the saved return address without altering the guard.

Impact

An attacker who can trigger a contiguous stack buffer overflow of a dynamically sized local variable in code compiled by GCC for ARM64 could overwrite the saved return address and control execution flow, bypassing stack smashing protection.

What the attacker needed

Code compiled with GCC for ARM64; a contiguous stack buffer overflow bug; dynamic stack allocation (VLA or alloca)

The fix

A fix is available on GCC's mailing list and should be incorporated by distributors of GCC or ARM64 binaries compiled with GCC.

How it was found

  1. Compile a C program with a variable-length array using GCC for AArch64 with -fstack-protector-all.
  2. Run the program under QEMU with debugging enabled, passing a small size for the dynamic allocation.
  3. Send a payload that overflows the dynamic buffer and overwrites the saved frame pointer and return address.
  4. Attach a debugger and continue; observe a crash with the program counter set to the attacker-controlled address.

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 has a bug that lets an attacker write too much data into a local buffer, a compiler feature called a stack guard is supposed to notice and stop the program. On 64-bit ARM, GCC places the guard in a spot that dynamic buffers can overflow past without touching it, so the guard never fires. This means programs compiled with that protection are still vulnerable to certain buffer overflows.

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.