From: Arran Cudbard-Bell Date: Mon, 28 Mar 2022 19:31:42 +0000 (-0600) Subject: Fix failures in OpenSSL 3.0 with custom logging BIOs X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=253f8057db17b4a45f983eb2c9f1f4f6531dc2c6;p=thirdparty%2Ffreeradius-server.git Fix failures in OpenSSL 3.0 with custom logging BIOs Apparently the create callbacks need to call BIO_set_init() otherwise all operations on the BIO will fail. This isn't documented anywhere. --- diff --git a/src/lib/tls/bio.c b/src/lib/tls/bio.c index 8177f87d7a1..a9ac84523c9 100644 --- a/src/lib/tls/bio.c +++ b/src/lib/tls/bio.c @@ -375,6 +375,11 @@ int fr_tls_bio_init(void) tls_bio_talloc_meth = BIO_meth_new(BIO_get_new_index() | BIO_TYPE_SOURCE_SINK, "fr_tls_bio_dbuff_t"); if (unlikely(!tls_bio_talloc_meth)) return -1; + /* + * If BIO_meth_set_create is ever used here be sure to call + * BIO_set_init(bio, 1); in the create callbacks else all + * operations on the BIO will fail. + */ BIO_meth_set_write(tls_bio_talloc_meth, _tls_bio_talloc_write_cb); BIO_meth_set_puts(tls_bio_talloc_meth, _tls_bio_talloc_puts_cb); BIO_meth_set_read(tls_bio_talloc_meth, _tls_bio_talloc_read_cb); diff --git a/src/lib/tls/log.c b/src/lib/tls/log.c index d26be319a3b..d1b9ad4123c 100644 --- a/src/lib/tls/log.c +++ b/src/lib/tls/log.c @@ -555,9 +555,10 @@ void tls_log_clear(void) /** Increment the bio meth reference counter * */ -static int tls_log_request_bio_create_cb(UNUSED BIO *bio) +static int tls_log_request_bio_create_cb(BIO *bio) { atomic_fetch_add(&tls_request_log_ref, 1); + BIO_set_init(bio, 1); return 1; } @@ -638,18 +639,20 @@ static int tls_log_request_bio_puts_cb(BIO *bio, char const *in) /** Decrement the bio meth reference counter * */ -static int tls_log_request_bio_free_cb(UNUSED BIO *bio) +static int tls_log_request_bio_free_cb(BIO *bio) { atomic_fetch_sub(&tls_request_log_ref, 1); + BIO_set_init(bio, 0); return 1; } /** Increment the bio meth reference counter * */ -static int tls_log_global_bio_create_cb(UNUSED BIO *bio) +static int tls_log_global_bio_create_cb(BIO *bio) { atomic_fetch_add(&tls_global_log_ref, 1); + BIO_set_init(bio, 1); return 1; } @@ -720,9 +723,10 @@ static int tls_log_global_bio_puts_cb(BIO *bio, char const *in) /** Decrement the bio meth reference counter * */ -static int tls_log_global_bio_free_cb(UNUSED BIO *bio) +static int tls_log_global_bio_free_cb(BIO *bio) { atomic_fetch_sub(&tls_global_log_ref, 1); + BIO_set_init(bio, 0); return 1; }