Repository navigation
mod_cache_socache: bound header parser to the cached entry length - #849
arshsmith1 wants to merge 2 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. |
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.
|
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." |
read_array() and read_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.len = buffer_len - slider(apr_size_t), which underflows to ~SIZE_MAX and is handed to apr_bucket_pool_create() for the body bucket, so recalling the entry streams an out-of-bounds read to the client.Bounded each of the three post-CR LF lookaheads (once in read_array, twice in read_table) with
*slider < buffer_len, so the parse position never moves past the end of the datum and the body-length subtraction cannot underflow. Output is unchanged for well-formed records.Reachable when the socache provider hands back a malformed record (for example a shared or remote mod_socache_memcache / mod_socache_redis store). Verified with an AddressSanitizer reproducer of read_table plus the open_entity body handling: unpatched, read_table returns success with slider = buffer_len + 1 and the body read trips ASAN (heap-buffer-overflow READ); with the patch slider stays at buffer_len, len is 0, and there is no OOB. The whole file also compiles clean under -Wall with the change.
A pyhttpd test is not included: the defect needs a malformed entry in the socache store, which the test framework cannot inject against the in-process providers, so the ASAN reproducer above exercises it 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.