Repository navigation
mod_cache_socache: bound header parser to the cached entry length - #849
arshsmith1 wants to merge 4 commits into
Conversation
|
The fix looks correct. I reproduced the body length underflow with a real httpd and a truncated socache entry: trunk fails to complete the response ( Could we add a regression test using a deliberately truncated cache entry (e.g. with socache DBM)? Separately, a truncated entry is still served as a complete 200 response with an empty body. That should probably be addressed independently. |
|
Added Agreed on the truncated entry being served as a 200 with an empty body. I'd rather keep this PR to the underflow and look at rejecting short entries in a separate one. |
|
Thanks for adding the test. I verified it against a real httpd with SDBM: it fails consistently on trunk, including in an ASan build, and passes with the fix. One small issue: the final assertions also pass on a cache MISS. Could you check that The changes entry could also describe the user-visible fix rather than the implementation details, e.g. "mod_cache_socache: Prevent invalid response lengths when reading truncated cache entries." |
|
Good point on the MISS. The last request now also asserts |
|
Thanks @arshsmith1 — the fix itself looks right. The three A few things before this can go in:
|
Cache a static file through socache DBM, then cut the stored SDBM record short so it ends on the CR of the request headers' final CRLF, and check that recalling it on the same connection still completes.
Assert X-Cache reports a HIT for the request that recalls the truncated entry too, so the test can't silently pass on a MISS without exercising it, and reword the CHANGES entry to describe the user-visible effect.
… fails to start The bare assertion on apache_restart() gives no hint why httpd refused the configuration, and the suite's error_log is overwritten by later suites before the CI artifact is collected.
a48b596 to
9e9f886
Compare
|
Rebased onto trunk and force-pushed, so On CI: the last run that got as far as executing, 44369630003, did run the test rather than skip it. Description rewritten too: it now describes the lookahead as a stale byte read inside the |
read_array()andread_table()parse a cached entry retrieved from the socache store. Each loop is guarded by*slider < buffer_len, but after matching a CR they do(*slider)++and then readbuffer[*slider]to test for the following LF without re-checking that bound.The retrieve buffer is sized to
CacheSocacheMaxSizeandbuffer_lenis always smaller than that, so the lookahead stays inside the allocation: it reads a stale byte left over from an earlier entry read into the same recycled buffer. When the CR is the last byte of the datum and that stale byte is LF,*sliderends up atbuffer_len + 1.open_entity()then computes the body length asbuffer_len - sliderin anapr_size_t, which underflows to ~SIZE_MAX, and hands it toapr_bucket_pool_create(). Recalling the entry streams from well past the end of the retrieved data.Bounded each of the three post-CR LF lookaheads (once in
read_array(), twice inread_table()) with*slider < buffer_len, so the parse position never moves past the end of the datum and the subtraction cannot underflow. Well-formed records parse exactly as before.test/modules/cache/test_002_socache_truncated.pycaches a static file through adbm:socache store, rewrites the SDBM record so it ends on the CR of the request headers' final CRLF, and recalls it on the same keep-alive connection so the recycled buffer still holds the LF from the previous full hit. It skips where the default APR DBM is not SDBM, since it edits the.pagfile directly.(see
SECURITY.mdandhttps://www.apache.org/security/#reporting-a-vulnerability).
APLOGNO()tag;numbers are assigned by a committer at merge time (see
docs/log-message-tags/README).changes-entries/*.txtfile is included,following the template in
README.CHANGES(not needed otherwise).test/modules/xxxdirectory matching themodules/xxxmodule source,or
test/modules/corefor core server changes. On Unix, verify thesepass locally with e.g.
make check-pytest PYTEST_DIRS=test/modules/xxx.