Skip to content

mod_proxy_fcgi, mod_brotli: Fix NULL deref when a FastCGI backend sends data after an early empty FCGI_STDOUT record - #1008

Open
arturobernalg wants to merge 2 commits into
apache:trunkfrom
arturobernalg:fix/bz66168-brotli-proxy-fcgi-eos
Open

arturobernalg wants to merge 2 commits into
apache:trunkfrom
arturobernalg:fix/bz66168-brotli-proxy-fcgi-eos

Conversation

@arturobernalg

Copy link
Copy Markdown
Member

Some FastCGI backends (PHP-FPM hitting PHP bug #72185, for one) emit a zero-length FCGI_STDOUT record too early and then keep sending STDOUT data afterwards. mod_proxy_fcgi treated the empty record as end of stream and sent an EOS bucket down the output filter chain, but kept reading and forwarding the backend's later STDOUT data as if it were new content.

A filter that tears down its internal state on EOS and never removes itself from the chain -- mod_brotli's encoder, in this case -- gets invoked again with that stale (destroyed) state and crashes with a NULL pointer dereference, killing the worker process and all other connections it was handling.

This fixes it at both ends: mod_proxy_fcgi now discards FastCGI STDOUT data received after the stream-ending empty record instead of forwarding it (logging a one-time warning, APLOGNO 10682), and mod_brotli now removes itself from the output filter chain as soon as it sees EOS, matching the defensive pattern mod_deflate already uses, so it can never be invoked again for the same request regardless of the cause.

Reproduced with a minimal FastCGI responder (no PHP needed) that sends the same malformed record sequence PHP-FPM does, confirmed the crash on an unpatched build (AH00051, exit signal Segmentation fault), and added a pytest regression test (test/modules/proxy/test_08_fcgi_eos.py) that fails the same way without the fix and passes with it.

BZ: https://bz.apache.org/bugzilla/show_bug.cgi?id=66168


[x] This PR does not report or address a security vulnerability (see SECURITY.md and https://www.apache.org/security/#reporting-a-vulnerability).
[x] Code follows the httpd style guide.
[x] New log messages (level debug or higher) use an empty APLOGNO() tag.
[x] If the change is user-visible, a changes-entries/*.txt file is included.
[x] Test cases based on pyhttpd are included.

@arturobernalg
arturobernalg force-pushed the fix/bz66168-brotli-proxy-fcgi-eos branch 2 times, most recently from 7735483 to 228724e Compare November 18, 2026 15:00
data after its own premature, stream-ending empty FCGI_STDOUT record.

Some backends (PHP-FPM hitting PHP bug #72185, for one) emit a
zero-length FCGI_STDOUT record too early and keep sending STDOUT data
afterwards. mod_proxy_fcgi treated the empty record as end of stream,
sent an EOS bucket down the filter chain, but kept forwarding the
backend's later STDOUT data as if it were new content. A filter that
tears down internal state on EOS and never removes itself from the
chain -- mod_brotli's encoder, in this case -- gets invoked again with
that stale state and crashes.

Discard FastCGI STDOUT data received after the stream-ending record
instead of forwarding it, and have mod_brotli remove itself from the
output filter chain once it has seen EOS so it can never be invoked
again for the same request regardless of the cause.

PR: https://bz.apache.org/bugzilla/show_bug.cgi?id=66168
@arturobernalg
arturobernalg force-pushed the fix/bz66168-brotli-proxy-fcgi-eos branch from 228724e to 10dfd60 Compare November 18, 2026 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant