Skip to content

Commit

Permalink
Modify compression code so it avoids using ex_data free functions. This
Browse files Browse the repository at this point in the history
stops applications that call CRYPTO_free_all_ex_data() prematurely leaking
memory.
  • Loading branch information
snhenson committed Jan 13, 2010
1 parent 97438f3 commit 1b31b5a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
9 changes: 9 additions & 0 deletions CHANGES
Expand Up @@ -881,6 +881,15 @@


Changes between 0.9.8l (?) and 0.9.8m (?) [xx XXX xxxx] Changes between 0.9.8l (?) and 0.9.8m (?) [xx XXX xxxx]


*) Modify compression code so it frees up structures without using the
ex_data callbacks. This works around a problem where some applications
call CRYPTO_free_all_ex_data() before application exit (e.g. when
restarting) then use compression (e.g. SSL with compression) later.
This results in significant per-connection memory leaks and
has caused some security issues including CVE-2008-1678 and
CVE-2009-4355.
[Steve Henson]

*) Add option SSL_OP_LEGACY_SERVER_CONNECT which will allow clients to *) Add option SSL_OP_LEGACY_SERVER_CONNECT which will allow clients to
connect (but not renegotiate) with servers which do not support RI. connect (but not renegotiate) with servers which do not support RI.
Until RI is more widely deployed this option is enabled by default. Until RI is more widely deployed this option is enabled by default.
Expand Down
17 changes: 7 additions & 10 deletions crypto/comp/c_zlib.c
Expand Up @@ -136,15 +136,6 @@ struct zlib_state


static int zlib_stateful_ex_idx = -1; static int zlib_stateful_ex_idx = -1;


static void zlib_stateful_free_ex_data(void *obj, void *item,
CRYPTO_EX_DATA *ad, int ind,long argl, void *argp)
{
struct zlib_state *state = (struct zlib_state *)item;
inflateEnd(&state->istream);
deflateEnd(&state->ostream);
OPENSSL_free(state);
}

static int zlib_stateful_init(COMP_CTX *ctx) static int zlib_stateful_init(COMP_CTX *ctx)
{ {
int err; int err;
Expand Down Expand Up @@ -188,6 +179,12 @@ static int zlib_stateful_init(COMP_CTX *ctx)


static void zlib_stateful_finish(COMP_CTX *ctx) static void zlib_stateful_finish(COMP_CTX *ctx)
{ {
struct zlib_state *state =
(struct zlib_state *)CRYPTO_get_ex_data(&ctx->ex_data,
zlib_stateful_ex_idx);
inflateEnd(&state->istream);
deflateEnd(&state->ostream);
OPENSSL_free(state);
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_COMP,ctx,&ctx->ex_data); CRYPTO_free_ex_data(CRYPTO_EX_INDEX_COMP,ctx,&ctx->ex_data);
} }


Expand Down Expand Up @@ -402,7 +399,7 @@ COMP_METHOD *COMP_zlib(void)
if (zlib_stateful_ex_idx == -1) if (zlib_stateful_ex_idx == -1)
zlib_stateful_ex_idx = zlib_stateful_ex_idx =
CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_COMP, CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_COMP,
0,NULL,NULL,NULL,zlib_stateful_free_ex_data); 0,NULL,NULL,NULL,NULL);
CRYPTO_w_unlock(CRYPTO_LOCK_COMP); CRYPTO_w_unlock(CRYPTO_LOCK_COMP);
if (zlib_stateful_ex_idx == -1) if (zlib_stateful_ex_idx == -1)
goto err; goto err;
Expand Down

0 comments on commit 1b31b5a

Please sign in to comment.