Skip to content

Commit e6c9454

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 28301cd commit e6c9454

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

doc/src/sgml/protocol.sgml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,10 +1527,10 @@ SELCT 1/0;<!-- this typo is intentional -->
15271527

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

16051605
<para>
16061606
The frontend should also be prepared to handle an ErrorMessage
1607-
response to GSSENCRequest from the server. This would only occur if
1608-
the server predates the addition of <acronym>GSSAPI</acronym> encryption
1609-
support to <productname>PostgreSQL</productname>. In this case the
1610-
connection must be closed, but the frontend might choose to open a fresh
1611-
connection and proceed without requesting <acronym>GSSAPI</acronym>
1612-
encryption.
1607+
response to GSSENCRequest from the server. The frontend should not display
1608+
this error message to the user/application, since the server has not been
1609+
authenticated
1610+
(<ulink url="https://www.postgresql.org/support/security/CVE-2024-10977/">CVE-2024-10977</ulink>).
1611+
In this case the connection must be closed, but the frontend might choose
1612+
to open a fresh connection and proceed without requesting
1613+
<acronym>GSSAPI</acronym> encryption.
16131614
</para>
16141615

16151616
<para>

src/interfaces/libpq/fe-connect.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3081,16 +3081,13 @@ PQconnectPoll(PGconn *conn)
30813081
{
30823082
/*
30833083
* Server failure of some sort, such as failure to
3084-
* fork a backend process. We need to process and
3085-
* report the error message, which might be formatted
3086-
* according to either protocol 2 or protocol 3.
3087-
* Rather than duplicate the code for that, we flip
3088-
* into AWAITING_RESPONSE state and let the code there
3089-
* deal with it. Note we have *not* consumed the "E"
3090-
* byte here.
3084+
* fork a backend process. Don't bother retrieving
3085+
* the error message; we should not trust it as the
3086+
* server has not been authenticated yet.
30913087
*/
3092-
conn->status = CONNECTION_AWAITING_RESPONSE;
3093-
goto keep_going;
3088+
appendPQExpBuffer(&conn->errorMessage,
3089+
libpq_gettext("server sent an error response during SSL exchange\n"));
3090+
goto error_return;
30943091
}
30953092
else
30963093
{

0 commit comments

Comments
 (0)