Commit Graph

127 Commits

Author SHA1 Message Date
Tobias Brunner 1496991078 leak-detective: Whitelist leaks that occur on Debian buster 2020-09-03 15:24:37 +02:00
Tobias Brunner 0f141fb095 soup: Use soup_session_new() to avoid deprecation warning
There are a ton of libsoup/GLib-related "leaks" that we can't whitelist
and with leak detective active there is a delay that interestingly doesn't
happen with soup_session_sync_new(), so tests failed with a timeout (actually
they hung due to the lock in the fetcher manager).
On Travis, the curl plugin is used for the tests, so that's not an issue
there (and without LD the tests complete quickly and successfully).
2020-02-05 10:49:35 +01:00
Tobias Brunner 6051d9b5e4 botan: Replace deprecated FFI function calls
Several "wrapper" functions have been marked deprecated with 2.11.0.
2019-07-02 11:35:21 +02:00
Tobias Brunner 6fc90cea74 leak-detective: Whitelist functions added in OpenSSL 1.1.1 2018-11-30 15:35:01 +01:00
Tobias Brunner 8eea28063d leak-detective: Use hashtable to cache ignored/whitelisted backtraces
Checking for whitelisted functions in every backtrace is not very
efficient.  And because OpenSSL 1.1 does no proper cleanup anymore until
the process is terminated there are now a lot more "leaks" to ignore.
For instance, in the openssl-ikev2/rw-cert scenario, just starting and
stopping the daemon (test vectors are checked) now causes 3594 whitelisted
leaks compared to the 849 before.  This prolonged the shutdown of the
daemon on each guest in every scenario, amounting to multiple seconds of
additional runtime for every affected scenario.  But even with this
patch there is still some overhead, compared to running the scenarios on
jessie.
2018-11-06 12:27:16 +01:00
Tobias Brunner 0f7055b22c leak-detective: Whitelist additional OpenSSL functions used by libcurl 2018-11-06 12:27:01 +01:00
Tobias Brunner 4bcc4bacd4 botan: Add support for Ed25519 keys 2018-10-26 11:06:45 +02:00
Tobias Brunner 472efd3809 leak-detective: Add an option to ignore frees of unknown memory blocks
This also changes how unknown/corrupted memory is handled in the free()
and realloc() hooks in general.

Incorporates changes provided by Thomas Egerer who ran into a similar
issue.
2018-09-12 16:25:00 +02:00
Tobias Brunner c064a5288e leak-detective: Whitelist some Botan functions
Due to the mangled C++ function names it's tricky to be more specific.  The
"leaked" allocations are from a static hashtable containing EC groups.

There is another leak caused by the locking allocator singleton
(triggered by the first function that uses it, usually initialization of
 a cipher, but could be a hasher in other test runners), but we can avoid
that with a Botan config option.
2018-09-12 16:25:00 +02:00
Tobias Brunner 1b67166921 Unify format of HSR copyright statements 2018-05-23 16:32:53 +02:00
Andreas Steffen 29e1c58643 leak-detective: Whitelisted memory leaks in FHH IMCs and IMVs 2017-05-29 10:59:04 +02:00
Tobias Brunner 95f9fa82d5 leak-detective: Whitelist thread ID getter
In case an external thread calls into our code and logs messages, a thread
object is allocated that will never be released.  Even if we try to clean
up the object via thread value destructor there is no guarantee that the
thread actually terminates before we check for leaks, which seems to be the
case for the Ada Tasking threads.
2016-09-20 16:26:05 +02:00
Tobias Brunner fd2ade9935 leak-detective: Whitelist functions of the Ada runtime related to Tasking 2016-09-20 16:26:05 +02:00
Tobias Brunner 0b5d490e33 leak-detective: Whitelist some glib/libsoup functions
Some of these are pretty broad, so maybe an alternative option is to
not use the soup plugin in the openssl-ikev2/rw-suite-b* scenarios.  But
the plugin is not tested anywhere else so lets go with this for now.
2016-09-20 16:22:08 +02:00
Tobias Brunner f44e0efb11 leak-detective: Whitelist leak in libldap 2016-09-20 15:36:14 +02:00
Tobias Brunner 505c318701 leak-detective: Try to properly free allocations after deinitialization
If a function we whitelist allocates memory while leak detective is enabled
but only frees it after LD has already been disabled, free() will get called
with invalid pointers (not pointing to the actually allocated memory by LD),
which will cause checks in the C library to fail and the program to crash.
This tries to detect such cases and calling free with the correct pointer.
2016-06-29 11:09:38 +02:00
Tobias Brunner c1410cb045 openssl: Whitelist OPENSSL_init_crypto() and others in leak detective
Lots of static data is allocated in this function, which isn't freed until
the library is unloaded (we can't call OPENSSL_cleanup() as initialization
would fail when calling it again later).  When enabling the leak
detective the test runner eventually crashes as all the data allocated during
initialization has an invalid size when freed after leak detective has been
unloaded.
2016-06-29 11:09:38 +02:00
Tobias Brunner e0c59faa68 leak-detective: Make sure to actually call malloc() from calloc() hook
Newer versions of GCC are too "smart" and replace a call to malloc(X)
followed by a call to memset(0,X) with a call co calloc(), which obviously
results in an infinite loop when it does that in our own calloc()
implementation.  Using `volatile` for the variable storing the total size
prevents the optimization and we actually call malloc().
2016-06-15 16:21:47 +02:00
Tobias Brunner 8f1806605d leak-detective: Whitelist __fprintf_chk as seen on newer systems 2016-06-15 11:21:39 +02:00
Andreas Steffen c87f428836 leak-detective: added _IO_file_doallocate to whitelist 2016-04-24 23:34:44 +02:00
Andreas Steffen b12c53ce77 Use standard unsigned integer types 2016-03-24 18:52:48 +01:00
Tobias Brunner e4d2c9f187 leak-detective: Use passed callback to report leaks
This prevented `stroke memusage` from reporting the leaks on the
console.  Instead, they were sent to the callbacks set up by libstrongswan.

Fixes a426851f63 ("leak-detective: Use callback functions to report
leaks and usage information").
2015-04-20 11:22:55 +02:00
Martin Willi d72817491d leak-detective: Whitelist gcrypt_plugin_create()
gcry_check_version() does not free statically allocated resources. However,
we can't whitelist it in some versions, as it is not a resolvable symbol name.
Instead, whitelist our own plugin constructor function.
2015-04-15 14:38:42 +02:00
Martin Willi 6eaec1e349 leak-detective: Whitelist libssl SSL_COMP_get_compression_methods()
This function is called by libcurl initialization with SSL, and uses
a static allocation of compression algorithms not freed.
2014-09-24 11:35:59 +02:00
Martin Willi 922ee2c529 windows: Add a common Windows header for platform specific wrappers
Include some more basic system headers in utils.h, so we can use that common
header on the different platforms.
2014-06-03 12:24:34 +02:00
Tobias Brunner adc1157487 leak-detective: LEAK_DETECTIVE_DISABLE completely disables LD
If lib->leak_detective is non-null some code parts (e.g. the plugin
loader) assume LD is actually used.
2014-04-03 09:44:26 +02:00
Tobias Brunner ba10cd3c7f utils: Move thread-safe strerror replacement to a separate file
For some utils _GNU_SOURCE might be needed but that conflicts with the
signature of strerror_r(3).
2014-02-24 12:04:10 +01:00
Tobias Brunner 8dc6e71632 lib: All settings use configured namespace 2014-02-12 14:34:32 +01:00
Thomas Egerer b351acfed6 leak_detective: Assign return value of realloc to buf
If realloc return a pointer value different from the value to be
reallocated, a double free can occur in this context.

Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
2014-02-10 17:23:54 +01:00
Martin Willi 56866ecf3d leak-detective: Call {gm,local}time_r() to allocate static buffer
On OS X Mavericks, these functions use a static allocation and are hard
to whitelist using other means.
2013-11-06 10:30:59 +01:00
Martin Willi ef6d78d6ef leak-detective: Register OS X specific hooks just once
If we initialize libstrongswan more than once in the same process, we may
not register the hooks twice.
2013-11-06 10:30:59 +01:00
Martin Willi f192526c3f leak-detective: Reset leak list during cleanup
This resets leak detective state should it get created/destroyed more than once.
2013-11-06 10:30:59 +01:00
Martin Willi a426851f63 leak-detective: Use callback functions to report leaks and usage information
This is more flexible than printing reports to a FILE.
2013-11-06 10:30:59 +01:00
Andreas Steffen 7bda0f0c8b Added tzset memory leak to whitelist 2013-08-28 22:51:17 +02:00
Martin Willi 1e54e40f5d leak-detective: remove hdr entry when reallocating zero bytes 2013-07-12 20:00:16 +02:00
Martin Willi c93cf85356 leak-detective: print total of allocated/leaked bytes in usage/report 2013-07-12 20:00:14 +02:00
Martin Willi 81959e6406 leak-detective: add a usage threshold option based on the number of allocations 2013-07-10 17:28:45 +02:00
Martin Willi 82d0317be6 leak-detective: set_state() only affects the calling thread
The only user (bfd backtraces) is fine with that, and we really should not
mess the enable flag while doing allocations with other threads.
2013-07-10 17:28:32 +02:00
Martin Willi f960b39061 leak-detective: take a copy of backtrace while printing traces
As we don't want to hold the lock, we must make sure backtraces keep valid
while printing them.
2013-07-10 17:28:24 +02:00
Martin Willi 3b26f04cf4 leak-detective: remove hdr from the allocation list during realloc()
If realloc moves an allocation, the original allocation gets freed. We
therefore must remove the hdr from the list, as it is invalid. We can add it
afterwards once it has been updated, allowing us to unlock the list during
reallocation.
2013-07-10 16:37:08 +02:00
Martin Willi 092550b03a leak-detective: (re-)whitelist some OpenSSL functions
Some static allocations in plugins won't get freed, because in the test case
process the plugins are not destroyed. If a plugin would clean up allocations
done while just using the plugin, these show up as leak in the child process,
letting tests fail.
2013-06-21 10:53:23 +02:00
Tobias Brunner f5f7053bcd leak-detective: Resolve hooked functions during initialization
If uses of dlopen(), e.g. when loading plugins, produce errors an error
string could get allocated dynamically.  At this point realloc() might not
yet be resolved and when dlsym() is later called by leak detective to do
so the error string might get freed while leak detective is disabled and
real_free() will be called with a pointer into one of leak detective's
memory blocks instead of a pointer to the block itself, causing a SIGSEGV.
2013-06-11 15:48:26 +02:00
Tobias Brunner 01e15ab5c7 Add getter for the number of leaks to leak_detective_t 2013-06-11 11:03:13 +02:00
Tobias Brunner 651d5ab8e7 openssl: Properly cleanup OpenSSL library 2013-05-08 15:02:40 +02:00
Martin Willi d8f6f0c01c leak-detective: add support for OS X by hooking default malloc zone 2013-05-06 15:15:24 +02:00
Martin Willi 50fbd32472 leak-detective: remove unused malloc call counters 2013-05-06 15:15:24 +02:00
Martin Willi 3117824f55 leak-detective: align allocations on both 32 and 64-bit systems to 32 bytes 2013-05-06 15:15:24 +02:00
Martin Willi 7e3f6299d5 leak-detective: call tzset() explicitly before enabling leak detective
tzset() is hard to whitelist on some systems, as there is no symbol involved.
Call tzset() explicitly before initialization to avoid false positives.
2013-05-06 15:15:24 +02:00
Martin Willi 17211b6b9a leak-detective: override malloc functions instead of using deprecated hooks
malloc hooks have become deprecated, and their use has always been problematic,
especially in multi-threaded applications. Replace the functionality by
overriding all malloc functions and query the system allocator functions
using dlsym() with RTLD_NEXT.
2013-05-06 15:15:24 +02:00
Andreas Steffen c9418d4fd3 added getpwuid_r and initgroups to whitelist 2013-03-03 09:04:49 +01:00