Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a5cc4c6

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 ca19f88 commit a5cc4c6

File tree

2 files changed

+21
-34
lines changed

2 files changed

+21
-34
lines changed

doc/src/sgml/protocol.sgml

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

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

16201620
<para>
16211621
The frontend should also be prepared to handle an ErrorMessage
1622-
response to GSSENCRequest from the server. This would only occur if
1623-
the server predates the addition of <acronym>GSSAPI</acronym> encryption
1624-
support to <productname>PostgreSQL</productname>. In this case the
1625-
connection must be closed, but the frontend might choose to open a fresh
1626-
connection and proceed without requesting <acronym>GSSAPI</acronym>
1627-
encryption.
1622+
response to GSSENCRequest from the server. The frontend should not display
1623+
this error message to the user/application, since the server has not been
1624+
authenticated
1625+
(<ulink url="https://www.postgresql.org/support/security/CVE-2024-10977/">CVE-2024-10977</ulink>).
1626+
In this case the connection must be closed, but the frontend might choose
1627+
to open a fresh connection and proceed without requesting
1628+
<acronym>GSSAPI</acronym> encryption.
16281629
</para>
16291630

16301631
<para>

src/interfaces/libpq/fe-connect.c

+10-24
Original file line numberDiff line numberDiff line change
@@ -3512,22 +3512,12 @@ PQconnectPoll(PGconn *conn)
35123512
{
35133513
/*
35143514
* Server failure of some sort, such as failure to
3515-
* fork a backend process. We need to process and
3516-
* report the error message, which might be formatted
3517-
* according to either protocol 2 or protocol 3.
3518-
* Rather than duplicate the code for that, we flip
3519-
* into AWAITING_RESPONSE state and let the code there
3520-
* deal with it. Note we have *not* consumed the "E"
3521-
* byte here.
3515+
* fork a backend process. Don't bother retrieving
3516+
* the error message; we should not trust it as the
3517+
* server has not been authenticated yet.
35223518
*/
3523-
conn->status = CONNECTION_AWAITING_RESPONSE;
3524-
3525-
/*
3526-
* Don't fall back to a plaintext connection after
3527-
* reading the error.
3528-
*/
3529-
conn->failed_enc_methods |= conn->allowed_enc_methods & (~conn->current_enc_method);
3530-
goto keep_going;
3519+
libpq_append_conn_error(conn, "server sent an error response during SSL exchange");
3520+
goto error_return;
35313521
}
35323522
else
35333523
{
@@ -3611,13 +3601,9 @@ PQconnectPoll(PGconn *conn)
36113601
{
36123602
/*
36133603
* Server failure of some sort, possibly protocol
3614-
* version support failure. We need to process and
3615-
* report the error message, which might be formatted
3616-
* according to either protocol 2 or protocol 3.
3617-
* Rather than duplicate the code for that, we flip
3618-
* into AWAITING_RESPONSE state and let the code there
3619-
* deal with it. Note we have *not* consumed the "E"
3620-
* byte here.
3604+
* version support failure. Don't bother retrieving
3605+
* the error message; we should not trust it anyway as
3606+
* the server has not authenticated yet.
36213607
*
36223608
* Note that unlike on an error response to
36233609
* SSLRequest, we allow falling back to SSL or
@@ -3626,8 +3612,8 @@ PQconnectPoll(PGconn *conn)
36263612
* response might mean that we are connecting to a
36273613
* pre-v12 server.
36283614
*/
3629-
conn->status = CONNECTION_AWAITING_RESPONSE;
3630-
goto keep_going;
3615+
libpq_append_conn_error(conn, "server sent an error response during GSS encryption exchange");
3616+
CONNECTION_FAILED();
36313617
}
36323618

36333619
/* mark byte consumed */

0 commit comments

Comments
 (0)