Skip to content

Conversation

theStack
Copy link
Contributor

@theStack theStack commented Apr 17, 2020

The fuzz test http_request calls the following two internal libevent functions:

  • evhttp_parse_firstline_
  • evhttp_parse_headers_

Before libevent 2.1.1 however, internal functions names didn't end with an underscore (see libevent commit libevent/libevent@8ac3c4c and Changelog for 2.1.1.-alpha when the change was first mentioned) hence the build fails with a linking error.
This PR adds a preprocessor workaround to the test that checks for the libevent version (via _EVENT_NUMERIC_VERSION LIBEVENT_VERSION_NUMBER) and creates wrapper functions mapping to naming scheme without underscore in case the version is older than 2.1.1.

Tested with Ubuntu Xenial 16.04.6 LTS and clang-8.

@fanquake fanquake added the Tests label Apr 17, 2020
@laanwj
Copy link
Member

laanwj commented Apr 17, 2020

It's kind of bizarre that we're calling private functions in the first place—there's no guarantee they keep existing at all or with the same signature which we hard-code here.
I guess the only reason that this is acceptable is because this is not production code but only a fuzzer.
Thanks for the workaround anyhow, this makes sure xenial with libevent 2.0.21 can compile the fuzzers.
(though I wouldn't actually recommend spending time fuzzing libevent 2.0.21, it's 8 years old)

{
return evhttp_parse_headers(r, b);
}
#else
extern "C" int evhttp_parse_firstline_(struct evhttp_request*, struct evbuffer*);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @practicalswift Can this fuzzer be adjusted to remove evhttp_parse_firstline_?

Copy link
Contributor

@practicalswift practicalswift Apr 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that I know of but if someone can come up with a less "bizarre" solution than the one I wrote that would be awesome :) We should avoid calling private functions if possible.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ideally, fuzzing libevent's internals belongs in libevent and not in our code. But I don't think it's a big problem to have it like this.

Copy link
Contributor

@practicalswift practicalswift Apr 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@laanwj Just to clarify: the reason for the calls to the internal functions is not to fuzz libevent's internals but to be able to do HTTPRequest http_request{evreq, true}; where the evhttp_request object is initialized/created in a way resembling the real-world attack surface. Let me know if you can think of a way to do that without calling internal functions - that would be great but I couldn't find a way to do it :)


Context:

    HTTPRequest http_request{evreq, true};
    const HTTPRequest::RequestMethod request_method = http_request.GetRequestMethod();
    (void)RequestMethodString(request_method);
    (void)http_request.GetURI();
    (void)http_request.GetHeader("Host");

@maflcko
Copy link
Member

maflcko commented Apr 17, 2020

Travis fails, so this can't be merged in its current form

@theStack theStack force-pushed the 20200417-fuzz-http-req-workaround-for-older-libevent branch from a9f657c to b75a128 Compare April 17, 2020 16:15
@theStack
Copy link
Contributor Author

Travis fails, so this can't be merged in its current form

My fault, I used an internal define from event-config.h for checking the version (named differently later) instead of LIBEVENT_VERSION_NUMBER that is defined in event.h. Force-pushed.

Before libevent 2.1.1, internal functions names didn't end with an underscore.
@theStack theStack force-pushed the 20200417-fuzz-http-req-workaround-for-older-libevent branch from b75a128 to 6f8b498 Compare April 17, 2020 17:00
@theStack
Copy link
Contributor Author

Travis still fails in two instances due to functional tests not passing, (obviously) unrelated to this change.

@hebasto
Copy link
Member

hebasto commented Apr 17, 2020

Travis still fails in two instances due to functional tests not passing, (obviously) unrelated to this change.

Restarted.

Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 6f8b498, tested on xenial:

$ ./configure --enable-fuzz --with-sanitizers=fuzzer,address,undefined CC=clang-8 CXX=clang++-8
$ make

@maflcko maflcko merged commit 895c71e into bitcoin:master Apr 17, 2020
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Apr 18, 2020
6f8b498 fuzz: http_request workaround for libevent < 2.1.1 (Sebastian Falbesoner)

Pull request description:

  The fuzz test `http_request` calls the following two internal libevent functions:
  * `evhttp_parse_firstline_`
  * `evhttp_parse_headers_`

  Before libevent 2.1.1 however, internal functions names didn't end with an underscore (see libevent commit libevent/libevent@8ac3c4c and [Changelog for 2.1.1.-alpha](https://github.com/libevent/libevent/blob/master/ChangeLog#L1830) when the change was first mentioned) hence the build fails with a linking error.
  This PR adds a preprocessor workaround to the test that checks for the libevent version (via ~`_EVENT_NUMERIC_VERSION`~ `LIBEVENT_VERSION_NUMBER`) and creates wrapper functions mapping to naming scheme without underscore in case the version is older than 2.1.1.

  Tested with Ubuntu Xenial 16.04.6 LTS and clang-8.

ACKs for top commit:
  hebasto:
    ACK 6f8b498, tested on xenial:

Tree-SHA512: 3b9e0147b8aea22e417d418e3b6d4905f5be131c2b0ae4b0f8b9411c5606d2e22f1b23e1ecc6980ecab907c61404de09e588aae1ac43cf70cf9e8d006bbdee73
@theStack theStack deleted the 20200417-fuzz-http-req-workaround-for-older-libevent branch December 1, 2020 09:55
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jan 21, 2021
Summary:
```
Before libevent 2.1.1, internal functions names didn't end with an
underscore.
```

Backport of core [[bitcoin/bitcoin#18682 | PR18682]].

Depends on D9000.

Test Plan:
  ninja bitcoin-fuzzers
I can't test the fix since I have no system with an old enough libevent
that match our minimum requirements.

Reviewers: #bitcoin_abc, PiRK

Reviewed By: #bitcoin_abc, PiRK

Differential Revision: https://reviews.bitcoinabc.org/D9001
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants