Commit Graph

763 Commits

Author SHA1 Message Date
Rozhuk Ivan
8b3bf44f49 Fix build with libressl 3.4.0+
SSL will become opaque in LibreSSL 3.4.x, hence the code reaching inside
it will result in build breakage.
SSL_set0_rbio() now available in libressl.
2021-11-10 00:32:18 +03:00
Mészáros Mihály
a19bc7c464 Revert by hand merge PR825 in favor PR755 more simple solution 2021-09-22 13:32:34 +02:00
Mészáros Mihály
b5a597836b Merge branch 'master' into fix_sqlite_shutdown_race 2021-09-22 11:12:41 +02:00
Mészáros Mihály
82e74935db
Merge pull request #825 from whereby/argggh/no-sqlite3-shutdown
dbd_sqlite: Don't shutdown sqlite3 db during init
2021-09-22 10:59:16 +02:00
Giacomo Vacca
8aded3556e Issue #699 Return codes for prom server 2021-09-21 17:26:48 +02:00
Arne Georg Gisnås Gleditsch
8d66122d91 dbd_sqlite: Don't shutdown sqlite3 db during init
Ref https://www.sqlite.org/c3ref/initialize.html:

    The sqlite3_initialize() interface is threadsafe, but
    sqlite3_shutdown() is not.

We currently call `sqlite3_shutdown` from all threads as part of
`sqlite_init_multithreaded`, and this has been observed to have
adversarial effects during startup if many threads receive their first
inbound request at the same time. The apparent motivation behind
calling shutdown is to make the subsequent calls to `sqlite3_config`
succeed, since these ordinarily return SQLITE_MISUSE if called
multiple times. However, this function is also documented to not be
thread safe, so introduce a barrier that ensures we only initialize
once over all threads.
2021-09-20 16:33:25 +02:00
Mészáros Mihály
6492f51a63
Merge pull request #767 from ggalperi/patch-1
Fix server->log_binding usage
2021-06-17 12:57:45 +02:00
Mark Hills
713bbefd5e Fix a segfault when a TLS context is not used
If the configuration contains entries such as:

  no-tlsv1
  no-tlsv1_1

then the SSL context is NULL. The previous code was simple enough that it
handled this case; the new code needs to deal with it explicitly.

[*] https://github.com/coturn/coturn/issues/770
2021-06-15 23:44:02 +02:00
Mészáros Mihály
7ad04a37d6 Not send SOFTWARE attr, if no_sotware_attribute on 2021-06-05 22:10:31 +02:00
Mészáros Mihály
708b83ea78 RESPONSE_ORIGIN attribute only if rfc5780 is on 2021-06-05 22:10:31 +02:00
Mészáros Mihály
54ef051844 Disable stun backward compatibility 2021-06-05 22:10:31 +02:00
Mészáros Mihály
eda11698f0 Add option no-rfc5780
To avoid any amplifiaction STUN binding attacks.
2021-06-05 22:10:31 +02:00
Mészáros Mihály
8c9622ad18 Add a check, don't SSL_CTX_up_ref a null pointer
This cause segmentation failure. Regression..
2021-06-05 22:10:31 +02:00
Mészáros Mihály
88f5119e1b Include ssl.h 2021-06-05 22:10:31 +02:00
ggalperi
0ac3fda6dd
Fix server->log_binding usage
The server->log_binding ptr should be dereferenced
2021-05-14 16:34:52 -04:00
Mészáros Mihály
d90c689c99
Merge pull request #739 from hills/ssl-reload-crashes
SSL reload has hidden bugs which cause crashes
2021-05-07 21:10:18 +02:00
Serhii Charykov
0f7ff3ec4a Change sqlite_init_multithreaded return type to void
to satisfy pthread_once() interface because
previously return from sqlite_init_multithreaded
was not used
2021-04-26 23:47:11 +03:00
Serhii Charykov
2d12ad4f29 Refactor code 2021-04-26 23:34:24 +03:00
Serhii Charykov
34e18533cf Fix sqlite3_config call only once before using any other sqlite utilities 2021-04-26 22:19:16 +03:00
Serhii Charykov
0b709a05b7 Remove sqlite3_shutdown()
Because:
1. According to sqlite3 docs sqlite3_initialize() and sqlite3_shutdown() are not must to be invoked
2. sqlite3_initialize() is never called explicilty
3. sqlite3_shutdown() is not threadsafe and sqlite_init_multithreaded is not called holding a lock
4. According to docs all connections must be closed before invoking sqlite3_shutdown() but they are not (from the different threads).

Possible issue:
sqlite3_config must be called before sqlite3_initialize() or after sqlite3_shutdown() (and only once?)
2021-04-26 21:36:28 +03:00
KangLin
9f6defdac4 CMake: add -Wno-deprecated-declarations 2021-03-29 07:22:12 -07:00
KangLin
2110991cd6 CMake: add turnadmin 2021-03-28 21:32:47 -07:00
KangLin
73da474804 CMake: add runtime install 2021-03-28 20:19:15 -07:00
Mark Hills
8f1908d7bd A use-after-free can occur on the SSL_ctx on a busy system
When openssl_load_certificates() is called as a result of USR2
signal, it has the effect of SSL_free() on certificates.

But pointers to these certificates are borrowed by the ioa_engines
where they are used for new connections.

The tls_mutex when loading the certificates does not prevent this use
because it's released before despatching asynchronous events to each
ioa_engine asking them to pick up the new SSL context.

So there is a race; if a new connection arrives quickly after
openssl_load_certificates() but before the tls_ctx_update_ev.

This patch resolves this using OpenSSL's own fine grained locking.
The ioa_engines now 'copy' the SSL context (actually a refcounted copy)
2021-03-23 16:02:06 +00:00
Mark Hills
da5cda7761 Do not take a copy of the SSL context
When SSL certificates are renewed during runtime (via SIGUSR2),
e->dtls_ctx is replaced with a context based on the new certificate.
But this code continues to operate on its own borrowed pointer.

This is clearly visible using valgrind, but the bug is subtle and not
always noticed at runtime, possibly due to some fortunate re-use of
memory.

At the point of SSL_new():

==28413== Thread 5:
==28413== Invalid read of size 8
==28413==    at 0x4F6198F: SSL_new (in /lib/libssl.so.1.1)
==28413==    by 0x137A72: dtls_server_input_handler (dtls_listener.c:291)
==28413==    by 0x137A72: handle_udp_packet (dtls_listener.c:443)
==28413==    by 0x138153: udp_server_input_handler (dtls_listener.c:728)
==28413==    by 0x4FC499E: ??? (in /usr/lib/libevent_core-2.1.so.7.0.0)
==28413==    by 0x4FC50AF: event_base_loop (in /usr/lib/libevent_core-2.1.so.7.0.0)
==28413==    by 0x121F34: run_events (netengine.c:1579)
==28413==    by 0x121F34: run_general_relay_thread (netengine.c:1707)
==28413==    by 0x40517B6: start (pthread_create.c:195)
==28413==    by 0x40538EF: ??? (clone.s:22)
==28413==  Address 0x49a75e0 is 0 bytes inside a block of size 1,024 free'd
==28413==    at 0x48A074F: free (vg_replace_malloc.c:540)
==28413==    by 0x4F5F6F1: SSL_CTX_free (in /lib/libssl.so.1.1)
==28413==    by 0x11CEC4: set_ctx (mainrelay.c:3104)
==28413==    by 0x11D233: openssl_load_certificates (mainrelay.c:3173)
==28413==    by 0x11D328: reload_ssl_certs (mainrelay.c:3190)
==28413==    by 0x4FC4601: ??? (in /usr/lib/libevent_core-2.1.so.7.0.0)
==28413==    by 0x4FC50AF: event_base_loop (in /usr/lib/libevent_core-2.1.so.7.0.0)
==28413==    by 0x122582: run_events (netengine.c:1579)
==28413==    by 0x122582: run_listener_server (netengine.c:1603)
==28413==    by 0x110BB8: main (mainrelay.c:2536)
==28413==  Block was alloc'd at
==28413==    at 0x489F72A: malloc (vg_replace_malloc.c:309)
==28413==    by 0x4DFA2C6: CRYPTO_zalloc (in /lib/libcrypto.so.1.1)
==28413==    by 0x4F5F79E: SSL_CTX_new (in /lib/libssl.so.1.1)
==28413==    by 0x11CA80: set_ctx (mainrelay.c:2875)
==28413==    by 0x11D233: openssl_load_certificates (mainrelay.c:3173)
==28413==    by 0x110A19: openssl_setup (mainrelay.c:3139)
==28413==    by 0x110A19: main (mainrelay.c:2396)
==28413==
2021-03-23 16:02:06 +00:00
Mark Hills
bdf27616ba Do not mutate something which the DTLS listener server does not own
Multiple DTLS listener servers are created, and server->dtls_ctx is
the same object shared between them.

Set these callbacks once, and logically this is at the point where the
SSL context is created.
2021-03-23 16:02:06 +00:00
Mészáros Mihály
31c936d51d
Merge pull request #721 from KangLin/cmake
Add to support cmake
2021-03-23 09:31:59 +01:00
Mészáros Mihály
6a5d067d7c
Merge pull request #703 from hills/no-stdout-log
Restore no_stdout_log behaviour
2021-03-23 09:18:17 +01:00
Mészáros Mihály
2204778ce1 Replace keep-address-family with allocation-default-address-family 2021-03-12 23:05:18 +01:00
Mészáros Mihály
e2c99c6803 Remove extra new line in error 2021-03-11 22:15:22 +01:00
KangLin
677e5dc5d3 Add cmake 2021-02-26 09:02:50 +08:00
Mark Hills
9bcc898b05 Restore no_stdout_log behaviour
In commit 599a61ee this was removed, by accident it could seem.
2021-01-25 09:31:47 +00:00
Mészáros Mihály
e5d4e62dec Fix typo "finsihed" reported by Felipe Cecagno 2021-01-14 15:14:53 +01:00
Mészáros Mihály
cc637d2db9 Uneccessary semicolon 2021-01-14 15:06:53 +01:00
brevilo
a52df6cafb
Define OPENSSL_VERSION_1_1_1 on systems where it doesn't (yet) exist
Otherwise preprocessor logic will fail and cause incompatible pointer type issues (by using wrong callback API)
2021-01-13 01:54:25 +01:00
Mészáros Mihály
abfe1fd08d Merge branch 'advisory-fix-1' CVE-2020-26262 2021-01-10 20:59:14 +01:00
Mészáros Mihály
104ab83f09 Automatically notify systemd if compiled 2021-01-10 20:57:43 +01:00
Mészáros Mihály
e367fabb0e Fix typo 2021-01-10 17:20:40 +01:00
Mészáros Mihály
c1437902e2 Remove earlier deleted function definitions 2021-01-10 10:43:36 +01:00
Mészáros Mihály
f1d946c1b4 Refactoring Prometheus
* Fix c++ support
* Simplify: Remove session id/allocation
2021-01-10 00:32:49 +00:00
Mészáros Mihály
a28fee8cde Fix typo in acme 2021-01-08 09:19:33 +00:00
Mészáros Mihály
2edc14a193 Fixes #601 2021-01-07 21:38:43 +00:00
Mészáros Mihály
13082beae8 Fixes #600 2021-01-07 21:31:12 +00:00
Mészáros Mihály
9fcd86f3cc Fixes #621 2021-01-07 21:25:27 +00:00
Mészáros Mihály
ef7916842d Add systemd notification support 2021-01-07 17:51:34 +00:00
Mészáros Mihály
5b13fdd37b Fix: Read log options in first pass. Fixes #602 2021-01-07 10:33:14 +00:00
Mészáros Mihály
50ebef7a3f Fix g++ 2 errors and many warnings
Resolves #661 #654
2021-01-05 21:47:50 +00:00
Mészáros Mihály
288c486676
Merge pull request #672 from jelmd/acme_fix
fix acme wrt. security, redundancy, consistency
2021-01-05 11:42:03 +01:00
Mészáros Mihály
6ce463e8e2 Removed wiki, due it was outdated and redundant. 2021-01-05 09:57:16 +00:00
Mészáros Mihály
27b261eb58 Disable binding logging to avoid DoS attack
* Add new option log-binding
2021-01-05 09:55:55 +00:00