Skip to content
DoS Write-up Intermediate

Recursion kills: The story behind CVE-2024-8176 in libexpat

A vulnerability in libexpat allowed an attacker to supply XML with deeply nested entity references, causing recursive function calls that overflow the stack and crash the process. This resulted in a denial of service.

blog.hartwork.org

Published on blog.hartwork.org

Expat 2.7.0 has been released earlier today. I will make this a more detailed post than usual because in many ways there is more to tell about this release than the average libexpat release: there is a story this time.

Sebastian Pipping, on blog.hartwork.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 XML parser used recursion to resolve nested entity references without a depth limit, so attacker-controlled input could exhaust the call stack.

Impact

An attacker could cause a denial of service by crashing the application; the text notes that stack clashing was considered a theoretical possibility but denial of service was the realistic impact.

What the attacker needed

Ability to supply XML input to a libexpat-based parser

The fix

The vulnerability was fixed in Expat 2.7.0 by removing recursion, with the main fix authored by Berkay Eren Ürün at Siemens.

How it was found

  1. Create an XML document that defines a chain of thousands of general entities, each referring to the previous one.
  2. Use the final entity inside character data, an attribute value, or via parameter entities.
  3. Feed the document to a program using libexpat, such as the xmlwf tool.
  4. Observe a segmentation fault due to stack overflow.

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.

XML files can define shortcuts called entities that refer to other entities. If those references form a very long chain, the parser keeps calling itself deeper and deeper until it runs out of memory for function calls, which crashes the program. This means a malicious XML file can stop a service from working.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.