Reject CancelRequestPacket having unexpected length.
authorNoah Misch <[email protected]>
Sat, 21 Jan 2023 14:08:00 +0000 (06:08 -0800)
committerNoah Misch <[email protected]>
Sat, 21 Jan 2023 14:08:04 +0000 (06:08 -0800)
When the length was too short, the server read outside the allocation.
That yielded the same log noise as sending the correct length with
(backendPID,cancelAuthCode) matching nothing.  Change to a message about
the unexpected length.  Given the attacker's lack of control over the
memory layout and the general lack of diversity in memory layouts at the
code in question, we doubt a would-be attacker could cause a segfault.
Hence, while the report arrived via [email protected], this is not
a vulnerability.  Back-patch to v11 (all supported versions).

Andrey Borodin, reviewed by Tom Lane.  Reported by Andrey Borodin.

src/backend/postmaster/postmaster.c

index 70c7cc70befea06786999ade08966e1036789bc2..18c19eea80cc43986a34048444bd7d2d6e6d10ae 100644 (file)
@@ -2014,6 +2014,13 @@ ProcessStartupPacket(Port *port, bool ssl_done, bool gss_done)
 
    if (proto == CANCEL_REQUEST_CODE)
    {
+       if (len != sizeof(CancelRequestPacket))
+       {
+           ereport(COMMERROR,
+                   (errcode(ERRCODE_PROTOCOL_VIOLATION),
+                    errmsg("invalid length of startup packet")));
+           return STATUS_ERROR;
+       }
        processCancelRequest(port, buf);
        /* Not really an error, but we don't want to proceed further */
        return STATUS_ERROR;