[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.
- 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:
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:
char* hostname = malloc(32);
memset(hostname, 0, 32);
//hostname[0] = 'x';
If you uncomment the last line, it will not crash.
Guido
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
- Build libevent with AddressSanitizer enabled.
- Place the supplied resolver configuration and proof-of-concept source in the source directory.
- Compile the proof-of-concept against the built library with AddressSanitizer.
- 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.