Repository navigation
fix out-of-bounds read in mod_proxy_html metafix - #783
arshsmith1 wants to merge 4 commits into
Conversation
|
The fix looks correct. I reproduced both out-of-bounds reads with a real httpd ( Could you add a regression test? There are no mod_proxy_html tests yet. A case with the meta tag at the very end of the body would do, although without ASan or a guard page it may also pass on trunk. |
Serve documents through mod_proxy_html with ProxyHTMLMeta on: a well-formed http-equiv tag is lifted into a response header, and a tag at the very end of the body is handled without reading past it.
|
Added |
|
Thanks for the test. I checked it locally: with a guard page after the mapped file, both cases crash on trunk and pass with the fix. |
test_004 is already used in test/modules/filters on trunk.
|
Renamed it to |
|
Thanks @arshsmith1. The out-of-bounds read is real — the hand-written scans after the regex match run against the raw, non-NUL-terminated bucket buffer, and the bounds you added close both the http-equiv name scan and the Two things block it as-is, plus a nit:
|
…l without the fix metafix() could still reach apr_table_setn(r->headers_out, "", content) once the scans were bounded: with <meta content=x http-equiv> at the end of the buffer the header-name scan stops at end with q == p, leaving an empty name while content is non-empty. check_header() then rejects it and the request turns into a 500. Skip the match when the name is empty. The test now sets EnableMMAP Off so the body is read into an allocated buffer, where the over-read is caught under ASan, and adds the empty-name case above. Rename the test functions to test_filters_010_* to match the file.
|
Good catches, both. Pushed:
|
metafix scans the backend response buffer for a header name and content value, but buf comes straight from apr_bucket_read and is not NUL terminated while the scans have no bound against buf+len. A backend body whose tag lands at the end of the bucket (with ProxyHTMLMeta on) walks past the buffer, reading adjacent heap and copying it into a response header name. Bound every scan in metafix to buf+len so a tag at the buffer boundary stops cleanly.