]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix race condition with BIO methods initialization in libpq with threads
authorMichael Paquier <michael@paquier.xyz>
Mon, 27 Nov 2023 00:40:49 +0000 (09:40 +0900)
committerMichael Paquier <michael@paquier.xyz>
Mon, 27 Nov 2023 00:40:49 +0000 (09:40 +0900)
commit8984480b545dcd8d09d8b877d71d9eae0b3bcb92
treea0d0a1b17bc93fd71f89a19976a1a8facd503f12
parent9033e7019821d9ca9e931e2a70e79b9b401c5f01
Fix race condition with BIO methods initialization in libpq with threads

The libpq code in charge of creating per-connection SSL objects was
prone to a race condition when loading the custom BIO methods needed by
my_SSL_set_fd().  As BIO methods are stored as a static variable, the
initialization of a connection could fail because it could be possible
to have one thread refer to my_bio_methods while it is being manipulated
by a second concurrent thread.

This error has been introduced by 8bb14cdd33de, that has removed
ssl_config_mutex around the call of my_SSL_set_fd(), that itself sets
the custom BIO methods used in libpq.  Like previously, the BIO method
initialization is now protected by the existing ssl_config_mutex, itself
initialized earlier for WIN32.

While on it, document that my_bio_methods is protected by
ssl_config_mutex, as this can be easy to miss.

Reported-by: Willi Mann
Author: Willi Mann, Michael Paquier
Discussion: https://postgr.es/m/e77abc4c-4d03-4058-a9d7-ef0035657e04@celonis.com
Backpatch-through: 12
src/interfaces/libpq/fe-secure-openssl.c