Skip to content

Commit c2569aa

Browse files
michaelpqreshke
authored andcommitted
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 e7b45e2 commit c2569aa

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
@@ -1526,10 +1526,10 @@ SELCT 1/0;<!-- this typo is intentional -->
15261526

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

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

16141615
<para>

src/interfaces/libpq/fe-connect.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3168,16 +3168,13 @@ PQconnectPoll(PGconn *conn)
31683168
{
31693169
/*
31703170
* Server failure of some sort, such as failure to
3171-
* fork a backend process. We need to process and
3172-
* report the error message, which might be formatted
3173-
* according to either protocol 2 or protocol 3.
3174-
* Rather than duplicate the code for that, we flip
3175-
* into AWAITING_RESPONSE state and let the code there
3176-
* deal with it. Note we have *not* consumed the "E"
3177-
* byte here.
3171+
* fork a backend process. Don't bother retrieving
3172+
* the error message; we should not trust it as the
3173+
* server has not been authenticated yet.
31783174
*/
3179-
conn->status = CONNECTION_AWAITING_RESPONSE;
3180-
goto keep_going;
3175+
appendPQExpBuffer(&conn->errorMessage,
3176+
libpq_gettext("server sent an error response during SSL exchange\n"));
3177+
goto error_return;
31813178
}
31823179
else
31833180
{

0 commit comments

Comments
 (0)