pgsql: Distrust external OpenSSL clients; clear err queue

Поиск
Список
Период
Сортировка
От Peter Eisentraut
Тема pgsql: Distrust external OpenSSL clients; clear err queue
Дата
Msg-id E1aoatN-0004ZK-2U@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Distrust external OpenSSL clients; clear err queue

OpenSSL has an unfortunate tendency to mix per-session state error
handling with per-thread error handling.  This can cause problems when
programs that link to libpq with OpenSSL enabled have some other use of
OpenSSL; without care, one caller of OpenSSL may cause problems for the
other caller.  Backend code might similarly be affected, for example
when a third party extension independently uses OpenSSL without taking
the appropriate precautions.

To fix, don't trust other users of OpenSSL to clear the per-thread error
queue.  Instead, clear the entire per-thread queue ahead of certain I/O
operations when it appears that there might be trouble (these I/O
operations mostly need to call SSL_get_error() to check for success,
which relies on the queue being empty).  This is slightly aggressive,
but it's pretty clear that the other callers have a very dubious claim
to ownership of the per-thread queue.  Do this is both frontend and
backend code.

Finally, be more careful about clearing our own error queue, so as to
not cause these problems ourself.  It's possibly that control previously
did not always reach SSLerrmessage(), where ERR_get_error() was supposed
to be called to clear the queue's earliest code.  Make sure
ERR_get_error() is always called, so as to spare other users of OpenSSL
the possibility of similar problems caused by libpq (as opposed to
problems caused by a third party OpenSSL library like PHP's OpenSSL
extension).  Again, do this is both frontend and backend code.

See bug #12799 and https://bugs.php.net/bug.php?id=68276

Based on patches by Dave Vitek and Peter Eisentraut.

From: Peter Geoghegan <pg@bowt.ie>

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/7c7d4fddab82dc756d8caa67b1b31fcdde355aab

Modified Files
--------------
src/backend/libpq/be-secure-openssl.c    | 70 ++++++++++++++++++++---------
src/interfaces/libpq/fe-secure-openssl.c | 77 ++++++++++++++++++++++----------
2 files changed, 102 insertions(+), 45 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: pgsql: Add BSD authentication method.
Следующее
От: Tom Lane
Дата:
Сообщение: pgsql: Fix unstable regression test output.