From: | Oliver Jowett <oliver(at)opencloud(dot)com> |
---|---|
To: | Hackers <pgsql-hackers(at)postgresql(dot)org> |
Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Subject: | V3 protocol gets out of sync on messages that cause allocation failures |
Date: | 2004-10-18 03:50:37 |
Message-ID: | 41733D8D.2050706@opencloud.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
(Tom: this is not as severe a problem as I first thought)
If a client sends a V3 message that is sufficiently large to cause a
memory allocation failure on the backend when allocating space to read
the message, the backend gets out of sync with the protocol stream.
For example, sending this:
> FE=> Parse(stmt=null,query="SELECT $1",oids={17})
> FE=> Bind(stmt=null,portal=null,$1=<<stream of 1000000000 bytes>>)
provokes this:
> ERROR: out of memory
> DETAIL: Failed on request of size 1073741823.
> FATAL: invalid frontend message type 0
What appears to be happening is that the backend goes into error
recovery as soon as the allocation fails (just after reading the message
length), and never does the read() of the body of the Bind message. So
it falls out of sync, and tries to interpret the guts of the Bind as a
new message. Bad server, no biscuit.
I was concerned that this was exploitable in applications that pass
hostile binary parameters as protocol-level parameters, but it doesn't
seem possible as the bytes at the start of a Bind are not under the
control of the attacker and don't form a valid message.
The CopyData message could probably be exploited, but it seems unlikely
that (security-conscious) applications will pass hostile data directly
in a CopyData message.
I haven't looked at a fix to this in detail (I'm not really familiar
with the backend's error-recovery path), but it seems like one easy
option is to treate all errors that occur while a message is in the
process of being read as FATAL?
-O
From | Date | Subject | |
---|---|---|---|
Next Message | Bruce Momjian | 2004-10-18 04:08:00 | Re: Open Items |
Previous Message | Bruce Momjian | 2004-10-18 03:48:39 | Re: Open Items |