tor/src/ext
Tobias Stoeckmann 9ce0bdd226 Prevent double free on huge files with 32 bit.
The function compat_getdelim_ is used for tor_getline if tor is compiled
on a system that lacks getline and getdelim. These systems should be
very rare, considering that getdelim is POSIX.

If this system is further a 32 bit architecture, it is possible to
trigger a double free with huge files.

If bufsiz has been already increased to 2 GB, the next chunk would
be 4 GB in size, which wraps around to 0 due to 32 bit limitations.

A realloc(*buf, 0) could be imagined as "free(*buf); return malloc(0);"
which therefore could return NULL. The code in question considers
that an error, but will keep the value of *buf pointing to already
freed memory.

The caller of tor_getline() would free the pointer again, therefore
leading to a double free.

This code can only be triggered in dirserv_read_measured_bandwidths
with a huge measured bandwith list file on a system that actually
allows to reach 2 GB of space through realloc.

It is not possible to trigger this on Linux with glibc or other major
*BSD systems even on unit tests, because these systems cannot reach
so much memory due to memory fragmentation.

This patch is effectively based on the penetration test report of
cure53 for curl available at https://cure53.de/pentest-report_curl.pdf
and explained under section "CRL-01-007 Double-free in aprintf() via
unsafe size_t multiplication (Medium)".
2019-04-10 12:46:27 +03:00
..
curve25519_donna Rectify include paths (automated) 2018-06-21 13:14:14 -04:00
ed25519 Fix (and make consistent) the use of OpenBSD preprocessor macro tests 2019-01-09 08:51:57 -05:00
keccak-tiny Rectify include paths (automated) 2018-06-21 13:19:00 -04:00
mulodi Rectify include paths (automated) 2018-06-21 13:14:14 -04:00
rust@aa37fb84fb update tor-rust-dependencies submodule 2018-05-16 09:16:47 -04:00
timeouts Fixup timing wheel warnings related to recent WHEEL_BIT change. 2018-04-17 12:45:53 -04:00
trunnel Bump copyright date to 2019. 2019-01-16 12:32:32 -05:00
byteorder.h Fix (and make consistent) the use of OpenBSD preprocessor macro tests 2019-01-09 08:51:57 -05:00
csiphash.c Remove non-windows system includes from compat.h and util.h 2018-06-29 12:21:52 -04:00
getdelim.c Prevent double free on huge files with 32 bit. 2019-04-10 12:46:27 +03:00
ht.h Bump copyright date to 2019. 2019-01-16 12:32:32 -05:00
include.am Add the compatibility definition for getdelim.c from netbsd. 2018-07-10 10:14:24 -04:00
Makefile.nmake Clean up the MVSC nmake files so they work again. 2014-09-09 10:27:05 -04:00
OpenBSD_malloc_Linux.c Rectify include paths (automated) 2018-06-21 13:14:14 -04:00
README Raise libevent dependency to 2.0.10-stable or newer 2016-07-04 12:40:09 +02:00
readpassphrase.c Don't call the system toupper or tolower. 2016-04-05 23:22:28 -04:00
siphash.h On shutdown, mark openssl as uninitialized. 2018-01-11 13:00:15 -05:00
strlcat.c Move strlcpy and strlcat into src/ext too 2012-10-12 17:14:28 -04:00
strlcpy.c Move strlcpy and strlcat into src/ext too 2012-10-12 17:14:28 -04:00
tinytest_demo.c Replace operators used as macro arguments with OP_XX macros 2014-11-12 13:28:07 -05:00
tinytest_macros.h Fix numerous type errors in the unit tests 2014-05-08 13:08:13 -04:00
tinytest.c Merge branch 'maint-0.3.4' 2018-09-13 11:46:04 -04:00
tinytest.h Upgrade to the latest version of tinytest. 2014-03-06 18:06:08 -05:00
tor_queue.h Silence spurious clang warnings 2014-10-30 22:34:46 +11:00
tor_queue.txt Add a copy of the queue(3) manpage to the git repository. 2012-10-30 19:16:15 -04:00
tor_readpassphrase.h Don't call the system toupper or tolower. 2016-04-05 23:22:28 -04:00

OpenBSD_malloc_Linux.c:

    The OpenBSD malloc implementation, ported to Linux.  Used only when
    --enable-openbsd-malloc is passed to the configure script.

strlcat.c
strlcpy.c

    Implementations of strlcat and strlcpy, the more sane replacements
    for strcat and strcpy.  These are nonstandard, and some libc
    implementations refuse to add them for religious reasons.

ht.h

    An implementation of a hash table in the style of Niels Provos's
    tree.h.  Shared with Libevent.

tinytest.[ch]
tinytest_demos.c
tinytest_macros.h

    A unit testing framework. https://github.com/nmathewson/tinytest

tor_queue.h

    A copy of sys/queue.h from OpenBSD.  We keep our own copy rather
    than using sys/queue.h, since some platforms don't have a
    sys/queue.h, and the ones that do have diverged in incompatible
    ways.  (CIRCLEQ or no CIRCLEQ? SIMPLQ or STAILQ?)  We also rename
    the identifiers with a TOR_ prefix to avoid conflicts with
    the system headers.

curve25519_donna/*.c

    A copy of Adam Langley's curve25519-donna mostly-portable
    implementations of curve25519.

csiphash.c
siphash.h

    Marek Majkowski's implementation of siphash 2-4, a secure keyed
    hash algorithm to avoid collision-based DoS attacks against hash
    tables.

trunnel/*.[ch]

    Headers and runtime code for Trunnel, a system for generating
    code to encode and decode binary formats.

ed25519/ref10/*

    Daniel Bernsten's portable ref10 implementation of ed25519.
    Public domain.

ed25519/donna/*

    Andrew Moon's semi-portable ed25519-donna implementation of
    ed25519. Public domain.

keccak-tiny/

    David Leon Gil's portable Keccak implementation. CC0.

readpassphrase.[ch]

    Portable readpassphrase implementation from OpenSSH portable, version
    6.8p1.

timeouts/

    William Ahern's hierarchical timer-wheel implementation. MIT license.

mulodi/

    Contains an overflow-checking 64-bit signed integer multiply
    from LLVM's compiler_rt.  For some reason, this is missing from
    32-bit libclang in many places. Dual licensed MIT-license and
    BSD-like license; see mulodi/LICENSE.TXT.