Fix use-after-free in BIO_C_SET_SSL callback
authorDr. Matthias St. Pierre <matthias.st.pierre@ncp-e.com>
Wed, 6 May 2020 15:24:13 +0000 (17:24 +0200)
committerDr. Matthias St. Pierre <matthias.st.pierre@ncp-e.com>
Thu, 7 May 2020 17:18:09 +0000 (19:18 +0200)
Since the BIO_SSL structure was renewed by `ssl_free(b)/ssl_new(b)`,
the `bs` pointer needs to be updated before assigning to `bs->ssl`.

Thanks to @suishixingkong for reporting the issue and providing a fix.

Closes #10539

Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/11746)

ssl/bio_ssl.c

index b44ec3e5e1e52f7bdb4d0b61c4d07401d54becc0..ca364fd14fd56336e3c8a823b0bea8404cf3d89d 100644 (file)
@@ -284,6 +284,7 @@ static long ssl_ctrl(BIO *b, int cmd, long num, void *ptr)
             ssl_free(b);
             if (!ssl_new(b))
                 return 0;
+            bs = BIO_get_data(b);
         }
         BIO_set_shutdown(b, num);
         ssl = (SSL *)ptr;