pgsql: Add more protections in WAL record APIs against overflows

Поиск
Список
Период
Сортировка
От Michael Paquier
Тема pgsql: Add more protections in WAL record APIs against overflows
Дата
Msg-id E1pkahA-001m1y-GT@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Add more protections in WAL record APIs against overflows

This commit adds a limit to the size of an XLogRecord at 1020MB, based
on a suggestion by Heikki Linnakangas.  This counts for the overhead
needed by the XLogReader when allocating the memory it needs to read a
record in DecodeXLogRecordRequiredSpace(), based on the record size.  An
assertion based on that is added to detect that any additions in the
XLogReader facilities would not cause any overflows.  If that's ever the
case, the upper bound allowed would need to be adjusted.

Before this, it was possible for an external module to create WAL
records large enough to be assembled but not replayable, causing
failures when replaying such WAL records on standbys.  One case
mentioned where this is possible is the in-core function
pg_logical_emit_message() (wrapper for LogLogicalMessage), that allows
to emit WAL records with an arbitrary amount of data potentially higher
than the replay limit of approximately 1GB (limit of a palloc, minus the
overhead needed by a XLogReader).

This commit is a follow-up of ffd1b6b that has added similar protections
for the block-level data.  Here, the checks are extended to the whole
record length, mainrdata_len being extended from uint32 to uint64 with
the routines registering buffer and record data still limited to uint32
to minimize the checks when assembling a record.  All the error messages
related to overflow checks are improved to provide more context about
the error happening.

Author: Matthias van de Meent
Reviewed-by: Andres Freund, Heikki Linnakangas, Michael Paquier
Discussion: https://postgr.es/m/CAEze2WgGiw+LZt+vHf8tWqB_6VxeLsMeoAuod0N=ij1q17n5pw@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/8fcb32db98eda1ad2a0c0b40b1cbb5d9a7aa68f0

Modified Files
--------------
src/backend/access/transam/xloginsert.c | 62 ++++++++++++++++++++++++++++-----
src/include/access/xlogrecord.h         | 11 ++++++
2 files changed, 65 insertions(+), 8 deletions(-)


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

Предыдущее
От: Andres Freund
Дата:
Сообщение: pgsql: Use ExtendBufferedRelTo() in XLogReadBufferExtended()
Следующее
От: Amit Kapila
Дата:
Сообщение: pgsql: Add tab-completion for newly added SUBSCRIPTION options.