Repository navigation
Bound the declared length of PostgreSQL messages parsed before authentication - #130462
Conversation
…tication `PasswordMessage`, `SASLInitialResponse` and `SASLResponse` are parsed before the client is authenticated, so the frame length they declare is chosen by a client the server does not trust yet. The payload is parsed inside a buffer that ends at that length, but the length itself was unbounded, so a client could make the server buffer a payload that never completes. Bound it by 10000 bytes, the limit the startup message already applies to the same phase, and reuse one constant for both. Cover the three messages in the stateless PostgreSQL protocol test.
|
Workflow [PR], commit [f578568] Summary: ✅
AI ReviewSummaryPR #130462, reviewed at Missing context / blind spots
Final VerdictStatus: ✅ Approve. No code changes requested; full regression execution remains subject to the normal CI checks. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units11 translation units recompiled, 50 s compile time in total, 11 of them have a recent master baseline. |
tiandiwonder
left a comment
There was a problem hiding this comment.
Currently we use 10000 for the following scenarios, which are different limits in postgresql, but it's good to go.
MAX_STARTUP_PACKET_LENGTH = 10000; // for startup message
PG_MAX_AUTH_TOKEN_LENGTH = 65535; // for password length
PG_MAX_SASL_MESSAGE_LENGTH = 1024; // for SASL message
Backport #130462 to 26.8: Bound the declared length of PostgreSQL messages parsed before authentication
Backport #130462 to 26.10: Bound the declared length of PostgreSQL messages parsed before authentication
Backport #130462 to 26.9: Bound the declared length of PostgreSQL messages parsed before authentication
Backport #130462 to 26.3: Bound the declared length of PostgreSQL messages parsed before authentication
…greSQL messages parsed before authentication
…greSQL messages parsed before authentication
…tgreSQL messages parsed before authentication
…sages parsed before authentication
…sages parsed before authentication
…sages parsed before authentication
…ssages parsed before authentication
Related: #116998
Every frontend message of the PostgreSQL protocol is parsed inside a buffer that ends at the length
the message declares, so a field can no longer grow past the end of its own frame. The declared
length itself, however, was unbounded for the messages that are parsed before the client is
authenticated:
PasswordMessage,SASLInitialResponseandSASLResponseare read into memory infull, and the client that declares their length is not trusted yet. A client could therefore
announce the
Int32maximum and make the server buffer a payload it never finishes sending.This bounds the declared length of those three messages by 10000 bytes, the limit that
receiveStartupMessagealready applies to the startup message, which is parsed in the same phase.FrontMessage::deserializePayloadtakes the limit as a parameter and rejects a larger declaredlength before any payload is read, and
max_startup_message_sizenow uses the same constantinstead of repeating the value.
The stateless PostgreSQL protocol test covers all three messages, both at the
Int32maximum andjust above the limit, plus the SCRAM final response that requires a well-formed client-first message
before it can be reached.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Messages of the PostgreSQL wire protocol that are parsed before authentication are now bounded by the server, so a client can no longer make the server buffer a payload that it never sends.
Workflow [PR]
Sync PR [sync-upstream/pr/130462]
Version info
26.11.1.2018-master(included in26.11and later)