Skip to content

Commit 7b49707

Browse files
committed
libpq: Bail out during SSL/GSS negotiation errors
This commit changes libpq so that errors reported by the backend during the protocol negotiation for SSL and GSS are discarded by the client, as these may include bytes that could be consumed by the client and write arbitrary bytes to a client's terminal. A failure with the SSL negotiation now leads to an error immediately reported, without a retry on any other methods allowed, like a fallback to a plaintext connection. A failure with GSS discards the error message received, and we allow a fallback as it may be possible that the error is caused by a connection attempt with a pre-11 server, GSS encryption having been introduced in v12. This was a problem only with v17 and newer versions; older versions discard the error message already in this case, assuming a failure caused by a lack of support for GSS encryption. Author: Jacob Champion Reviewed-by: Peter Eisentraut, Heikki Linnakangas, Michael Paquier Security: CVE-2024-10977 Backpatch-through: 12
1 parent 088692b commit 7b49707

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

doc/src/sgml/protocol.sgml

+11-10
Original file line numberDiff line numberDiff line change
@@ -1521,10 +1521,10 @@ SELCT 1/0;<!-- this typo is intentional -->
15211521

15221522
<para>
15231523
The frontend should also be prepared to handle an ErrorMessage
1524-
response to SSLRequest from the server. This would only occur if
1525-
the server predates the addition of <acronym>SSL</acronym> support
1526-
to <productname>PostgreSQL</productname>. (Such servers are now very ancient,
1527-
and likely do not exist in the wild anymore.)
1524+
response to SSLRequest from the server. The frontend should not display
1525+
this error message to the user/application, since the server has not been
1526+
authenticated
1527+
(<ulink url="https://www.postgresql.org/support/security/CVE-2024-10977/">CVE-2024-10977</ulink>).
15281528
In this case the connection must
15291529
be closed, but the frontend might choose to open a fresh connection
15301530
and proceed without requesting <acronym>SSL</acronym>.
@@ -1597,12 +1597,13 @@ SELCT 1/0;<!-- this typo is intentional -->
15971597

15981598
<para>
15991599
The frontend should also be prepared to handle an ErrorMessage
1600-
response to GSSENCRequest from the server. This would only occur if
1601-
the server predates the addition of <acronym>GSSAPI</acronym> encryption
1602-
support to <productname>PostgreSQL</productname>. In this case the
1603-
connection must be closed, but the frontend might choose to open a fresh
1604-
connection and proceed without requesting <acronym>GSSAPI</acronym>
1605-
encryption.
1600+
response to GSSENCRequest from the server. The frontend should not display
1601+
this error message to the user/application, since the server has not been
1602+
authenticated
1603+
(<ulink url="https://www.postgresql.org/support/security/CVE-2024-10977/">CVE-2024-10977</ulink>).
1604+
In this case the connection must be closed, but the frontend might choose
1605+
to open a fresh connection and proceed without requesting
1606+
<acronym>GSSAPI</acronym> encryption.
16061607
</para>
16071608

16081609
<para>

src/interfaces/libpq/fe-connect.c

+6-9
Original file line numberDiff line numberDiff line change
@@ -3056,16 +3056,13 @@ PQconnectPoll(PGconn *conn)
30563056
{
30573057
/*
30583058
* Server failure of some sort, such as failure to
3059-
* fork a backend process. We need to process and
3060-
* report the error message, which might be formatted
3061-
* according to either protocol 2 or protocol 3.
3062-
* Rather than duplicate the code for that, we flip
3063-
* into AWAITING_RESPONSE state and let the code there
3064-
* deal with it. Note we have *not* consumed the "E"
3065-
* byte here.
3059+
* fork a backend process. Don't bother retrieving
3060+
* the error message; we should not trust it as the
3061+
* server has not been authenticated yet.
30663062
*/
3067-
conn->status = CONNECTION_AWAITING_RESPONSE;
3068-
goto keep_going;
3063+
appendPQExpBuffer(&conn->errorMessage,
3064+
libpq_gettext("server sent an error response during SSL exchange\n"));
3065+
goto error_return;
30693066
}
30703067
else
30713068
{

0 commit comments

Comments
 (0)