1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-11-12 23:56:13 +01:00
github.com_openSUSE_osc/osc
Marcus Huewe b730f880cf Disable ssl session resumption
The old code could potentially yield to a use-after-free situation,
which results in UB. For this, consider the following scenario, where
osc performs several HTTPS requests (assumption: the server supports
ssl session resumption):

- HTTPS Request 1:
  * a new SSL *s connection is established, which also creates a new
    SSL_SESSION *ss => ss->references == 1
  * once the handshake is done, the ss is put into the session cache
    (see ssl_update_cache) => ss->references == 2
  - osc saves the session ss in a class variable
  - s is SSL_free()d, which calls SSL_SESSION_free => ss->references == 1

- HTTPS Request 2:
  * setup a new SSL *s connection that reuses the saved session ss
    => ss->references == 2
  * once the handshake is done, ssl_update_cache is called, which is a
    NOP, because s->hit == 1 (that is, the session was resumed)
  * osc saves the session ss in a class variable
  * s is SSL_free()d, which calls SSL_SESSION_free => ss->references == 1

...

> 2 hours later (see tls1_default_timeout)

...

- HTTPS Request 256:
  * setup a new SSL *s connection that reuses the saved session ss
    => ss->references == 2
  * once the handshake is done, ssl_update_cache is called, but is
    _no_ NOP anymore
  * ssl_update_cache flushes the session cache (this is done every
    255/256 (depending on the way we count) connections) => ss is
    SSL_SESSION_free()d => ss->references == 1
  * osc saves the session ss in a class variable
  * s is SSL_free()d, which calls SSL_SESSION_free:
    since ss->references == 1, ss is eventually free()d

- HTTPS Request 257:
  * setup a new SSL *s connection that reuses the saved session ss

Since ss does not exist anymore, the remaining program execution is UB.

(Note: SSL_free(...) is _NOT_ called, if M2Crypto 0.29 is used.
M2Crypto 0.30 calls SSL_free(...) again.)

Due to a bug in OpenSSL_1_1_0h (see openssl commit 8e405776858) the
scenario from above can be triggered with exactly 2 HTTPS requests (the
SSL_SESSION is not cached, because we configured SSL_VERIFY_PEER, but
no sid_ctx was set). This is fixed in openssl commit c4fa1f7fc01.

In order to reliably reuse a session, we probably need to listen to the
session cache changes. Such callbacks could be registered via
SSL_CTX_sess_set_new_cb and/or SSL_CTX_sess_set_remove_cb, but both
functions are not provided by M2Crypto. Another idea is to directly utilize
the session cache, but this also has to be implemented in M2Crypto first.
Yet another approach is to retrieve the session via SSL_get1_session, which
increases the session's refcnt, but this also needs to be implemented in
M2Crypto first (if we choose to use this approach, we also have to make
sure that we eventually free the session manually...).

Fixes: #398 ("SIGSEGV on \"osc commit\"")
2018-05-08 14:32:33 +02:00
..
util Fix and simplify util.safewriter.SafeWriter 2018-03-09 16:55:56 +01:00
__init__.py add vim mode lines to avoid evil tab characters :-) 2010-02-25 09:53:45 +01:00
.gitignore convert svn:ignore to gitignore 2009-12-03 19:19:53 +01:00
babysitter.py Cleanup babysitter a bit 2017-10-06 13:25:25 +02:00
build.py always run build using --statistics. I could have made this 2018-04-27 15:01:09 +02:00
checker.py Resolve PEP8 issue W291 2014-08-12 15:01:16 +02:00
cmdln.py Allow to override man-page date 2017-06-17 17:40:42 +02:00
commandline.py Fix typo in "osc revert" help 2018-05-03 16:16:38 +02:00
conf.py give a hint which package to install to get CA certificates 2018-01-26 09:46:52 +01:00
core.py Merge branch 'fix_newline_in_verbose' of https://github.com/lethliel/osc 2018-05-03 09:57:02 +02:00
fetch.py Container support: use multiple container extensions when checking the cache 2017-08-02 11:02:14 +02:00
meter.py python3 compatibility: print function 2013-04-16 10:51:41 +02:00
OscConfigParser.py - OscConfigParser: added "proper" parameter to the has_option method 2014-06-04 15:29:50 +02:00
oscerr.py Fix "args" handling in class PackageNotInstalled 2016-09-09 13:14:35 +02:00
oscssl.py Disable ssl session resumption 2018-05-08 14:32:33 +02:00
oscsslexcp.py - remove shebang line to make rpmlint happy 2010-03-21 22:57:06 +01:00