]> git.kaiwu.me - nginx.git/commit
Avoid duplicate subrequest finalization
authorRoman Arutyunyan <arut@nginx.com>
Mon, 29 Jun 2026 17:49:27 +0000 (21:49 +0400)
committerRoman Arutyunyan <arutyunyan.roman@gmail.com>
Wed, 15 Jul 2026 17:20:38 +0000 (21:20 +0400)
commitddde692db11ab8238e9ca661007f64c9f6d764d2
tree50a5fc71a883b49b40a44b0b6a9728174aca70e3
parentb99f804ad38a60ceb07bc429598d5b2c4e70e336
Avoid duplicate subrequest finalization

Previously, if a subrequest was posted twice, it could be finalized in
both calls, excessively reducing r->main->count and potentially leading
to a use-after-free.

The fix is to avoid posting a request if it's already posted.  Also,
as a hardening measure, r->write_event_handler is now reset to a no-op
handler during active subrequest finalization.

The problem manifests itself in ngx_http_ssi_filter_module during
unbuffered proxying.  If a subrequest is created for an SSI include
statement while the main request has some data postponed by another
include, this subrequest becomes double-posted when the main request
data is flushed.  The first post comes from ngx_http_subrequest() and
the second one comes from ngx_http_postpone_filter().  In case of a
quick subrequest finalization, the above mentioned problem happens.

Reported by P4P3R-HAK.
src/http/ngx_http_request.c