V3 protocol gets out of sync on messages that cause allocation failures

Поиск
Список
Период
Сортировка
От Oliver Jowett
Тема V3 protocol gets out of sync on messages that cause allocation failures
Дата
Msg-id 41733D8D.2050706@opencloud.com
обсуждение исходный текст
Ответы Re: V3 protocol gets out of sync on messages that cause allocation failures  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: Re: Open Items
Следующее
От: Bruce Momjian
Дата:
Сообщение: Re: Open Items