Skip to content
Memory corruption Disclosed report Intermediate

[tor] libevent dns OOB read

The libevent DNS search-list code reads one byte before a buffer when the supplied base name is empty, because it indexes the last character without checking the length. On ASAN-protected builds this out-of-bounds read triggers a crash.

guido Follow

Originally disclosed on HackerOne

  • Triaged in 42 days
  • Fixed in 4 months
  • Paid in 8 days
  • Disclosed after 20 months

The DNS code of Libevent contains this rather obvious OOB read:

C
3122 static char *
3123 search_make_new(const struct search_state *const state, int n, const char *const base_name) {
3124     const size_t base_len = strlen(base_name);
3125     const char need_to_append_dot = base_name[base_len - 1] == '.' ? 0 : 1;

If the length of base_name is 0, then line 3125 reads 1 byte before the buffer. This will trigger a crash on ASAN-protected builds.

To reproduce:

Build libevent with ASAN:

$ CFLAGS='-fomit-frame-pointer -fsanitize=address' ./configure && make -j4

Put the attached resolv.conf and poc.c in the source directory and then do:

$ gcc -fsanitize=address -fomit-frame-pointer poc.c .libs/libevent.a
$ ./a.out
=================================================================
==22201== ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60060000efdf at pc 0x4429da bp 0x7ffe1ed47300 sp 0x7ffe1ed472f8
READ of size 1 at 0x60060000efdf thread T0

This happens because I create a zero-length string in poc.c:

C
    char* hostname = malloc(32);
    memset(hostname, 0, 32);
    //hostname[0] = 'x';

If you uncomment the last line, it will not crash.

Guido

The original report as published on HackerOne, by guido. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The code computes the last index as length minus one without checking that the length is greater than zero, so an empty string causes a read one byte before the buffer.

Impact

The out-of-bounds read causes a crash on ASAN-protected builds; the report does not claim any impact beyond that.

What the attacker needed

Empty base name passed to DNS search code; ASAN-protected build to observe crash

How it was found

  1. Build libevent with AddressSanitizer enabled.
  2. Place the supplied resolver configuration and proof-of-concept source in the source directory.
  3. Compile the proof-of-concept against the built library with AddressSanitizer.
  4. Run the resulting binary and observe the heap-buffer-overflow report.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A program stores text in a block of memory and reads characters by position. If the text is empty, asking for its 'last character' points just before the block, which is memory the program should not read. Here that mistake causes a crash in a debugging build, though the report does not show anything worse than a crash.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More by guido

View all

49 more disclosed reports, best first.

More from Tor

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.