Marcus Huewe c0a58e034d Do not free a session before calling the remove_session_cb
If the remove_session_cb accesses the session's data (for instance,
via SSL_SESSION_get_protocol_version), a potential use after free
can occur. For this, consider the following scenario when adding
a new session via SSL_CTX_add_session:

- The session cache is full
  (SSL_CTX_sess_number(ctx) > SSL_CTX_sess_get_cache_size(ctx))
- Only the session cache has a reference to ctx->session_cache_tail
  (that is, ctx->session_cache_tail->references == 1)

Since the cache is full, remove_session_lock is called to remove
ctx->session_cache_tail from the cache. That is, it
SSL_SESSION_free()s the session, which free()s the data. Afterwards,
the free()d session is passed to the remove_session_cb. If the callback
accesses the session's data, we have a use after free.

The free before calling the callback behavior was introduced in
commit e4612d02c53cccd24fa97b08fc01250d1238cca1 ("Remove sessions
from external cache, even if internal cache not used.").

CLA: trivial

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6222)
2018-06-07 13:08:07 +01:00
..
2017-10-18 16:05:06 +01:00
2017-05-02 09:44:43 +01:00
2018-04-17 15:18:40 +02:00
2017-08-03 10:48:00 +01:00
2018-03-20 13:08:46 +00:00
2018-05-14 17:43:19 +01:00
2018-02-13 13:59:25 +00:00
2018-03-20 13:08:46 +00:00
2018-03-27 16:25:08 -04:00
2018-03-20 13:08:46 +00:00
2017-12-14 15:06:37 +00:00
2018-05-29 13:16:04 +01:00
2016-11-13 16:24:02 -05:00
2018-06-07 09:48:49 +01:00
2018-05-15 10:02:59 +01:00
2018-06-07 10:58:35 +01:00