Skip to content

fix out-of-bounds read in mod_proxy_html metafix - #783

Open
arshsmith1 wants to merge 2 commits into
apache:trunkfrom
arshsmith1:proxy-html-metafix-bounds
Open

arshsmith1 wants to merge 2 commits into
apache:trunkfrom
arshsmith1:proxy-html-metafix-bounds

Conversation

@arshsmith1

Copy link
Copy Markdown
Contributor

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.

@arturobernalg

Copy link
Copy Markdown
Member

The fix looks correct. I reproduced both out-of-bounds reads with a real httpd (ProxyHTMLMeta On, PROXY_HTML_FORCE) serving a 4096-byte file that ends with the meta tag, with a guard page mapped right after the file. On trunk, <meta http-equiv> and <meta content='0;url=/x http-equiv=Refresh> at the end of the body crash the child with SIGSEGV. With this PR applied they no longer do, and well-formed meta tags are handled as before.

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.
@arshsmith1

Copy link
Copy Markdown
Contributor Author

Added test/modules/filters/test_004_proxy_html_meta.py. It serves 4096-byte documents ending in each of your two tags through mod_proxy_html (ProxyHTMLMeta On, PROXY_HTML_FORCE) and checks they come back 200 with no header lifted, plus a well-formed tag that should still turn into a response header. It skips when mod_proxy_html isn't built. As you said, without ASan or a guard page the end-of-body cases may pass on trunk too. I haven't been able to run it on a Unix build yet, so CI will be the first run.

@arturobernalg

Copy link
Copy Markdown
Member

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.
One small thing: test_004 is already taken in test/modules/filters. Could you rename the new test to test_010_proxy_html_meta.py?

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.

2 participants