https://github.com/postgres/postgres
Revision af9c5c074f7a0f6688351ef4e973707a26ccd1ea authored by Heikki Linnakangas on 02 February 2015, 15:09:15 UTC, committed by Heikki Linnakangas on 02 February 2015, 15:09:31 UTC
If any error occurred while we were in the middle of reading a protocol
message from the client, we could lose sync, and incorrectly try to
interpret a part of another message as a new protocol message. That will
usually lead to an "invalid frontend message" error that terminates the
connection. However, this is a security issue because an attacker might
be able to deliberately cause an error, inject a Query message in what's
supposed to be just user data, and have the server execute it.

We were quite careful to not have CHECK_FOR_INTERRUPTS() calls or other
operations that could ereport(ERROR) in the middle of processing a message,
but a query cancel interrupt or statement timeout could nevertheless cause
it to happen. Also, the V2 fastpath and COPY handling were not so careful.
It's very difficult to recover in the V2 COPY protocol, so we will just
terminate the connection on error. In practice, that's what happened
previously anyway, as we lost protocol sync.

To fix, add a new variable in pqcomm.c, PqCommReadingMsg, that is set
whenever we're in the middle of reading a message. When it's set, we cannot
safely ERROR out and continue running, because we might've read only part
of a message. PqCommReadingMsg acts somewhat similarly to critical sections
in that if an error occurs while it's set, the error handler will force the
connection to be terminated, as if the error was FATAL. It's not
implemented by promoting ERROR to FATAL in elog.c, like ERROR is promoted
to PANIC in critical sections, because we want to be able to use
PG_TRY/CATCH to recover and regain protocol sync. pq_getmessage() takes
advantage of that to prevent an OOM error from terminating the connection.

To prevent unnecessary connection terminations, add a holdoff mechanism
similar to HOLD/RESUME_INTERRUPTS() that can be used hold off query cancel
interrupts, but still allow die interrupts. The rules on which interrupts
are processed when are now a bit more complicated, so refactor
ProcessInterrupts() and the calls to it in signal handlers so that the
signal handlers always call it if ImmediateInterruptOK is set, and
ProcessInterrupts() can decide to not do anything if the other conditions
are not met.

Reported by Emil Lenngren. Patch reviewed by Noah Misch and Andres Freund.
Backpatch to all supported versions.

Security: CVE-2015-0244
1 parent 8d412e0
History
Tip revision: af9c5c074f7a0f6688351ef4e973707a26ccd1ea authored by Heikki Linnakangas on 02 February 2015, 15:09:15 UTC
Be more careful to not lose sync in the FE/BE protocol.
Tip revision: af9c5c0
File Mode Size
config
contrib
doc
src
.gitignore -rw-r--r-- 360 bytes
COPYRIGHT -rw-r--r-- 1.2 KB
GNUmakefile.in -rw-r--r-- 3.5 KB
HISTORY -rw-r--r-- 283 bytes
Makefile -rw-r--r-- 1.5 KB
README -rw-r--r-- 1.2 KB
README.git -rw-r--r-- 727 bytes
aclocal.m4 -rw-r--r-- 385 bytes
configure -rwxr-xr-x 852.4 KB
configure.in -rw-r--r-- 63.7 KB

README

back to top