pgsql: Add overflow protection for block-related data in WAL records

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Add overflow protection for block-related data in WAL records
Date: 2022-07-27 04:37:00
Message-ID: E1oGYn5-001R0k-1u@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Add overflow protection for block-related data in WAL records

XLogRecordBlockHeader, the header holding the information for the data
related to a block, tracks the length of the data appended to the WAL
record with data_length (uint16). This limitation in size was not
enforced by the public routine in charge of registering the data
assembled later to form the WAL record inserted, XLogRegisterBufData().
Incorrectly used, it could lead to the generation of records with some
of its data overflowed. This commit adds some safeguards to prevent
that for the block data, complaining immediately if attempting to add to
a record block information with a size larger than UINT16_MAX, which is
the limit implied by the internal logic.

Note that this also adjusts XLogRegisterData() and XLogRegisterBufData()
so as the length of the WAL record data given by the caller is unsigned,
matching with what gets stored in XLogRecData->len.

Extracted from a larger patch by the same author. The original patch
includes more protections when assembling a record in full that will be
looked at separately later.

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

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/ffd1b6bb6f8a2ffc929699772610c6925364dbb3

Modified Files
--------------
src/backend/access/transam/xloginsert.c | 22 ++++++++++++++++++----
src/include/access/xloginsert.h | 4 ++--
2 files changed, 20 insertions(+), 6 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Thomas Munro 2022-07-27 05:01:09 Re: pgsql: Remove the restriction that the relmap must be 512 bytes.
Previous Message Michael Paquier 2022-07-27 04:34:48 Re: pgsql: Remove the restriction that the relmap must be 512 bytes.