Re: Non-replayable WAL records through overflows and >MaxAllocSize lengths
Matthias van de Meent <boekewurm+postgres@gmail.com>
From: Matthias van de Meent <boekewurm+postgres@gmail.com>
To: Michael Paquier <michael@paquier.xyz>
Cc: David Zhang <david.zhang@highgo.ca>, Andres Freund <andres@anarazel.de>, Robert Haas <robertmhaas@gmail.com>, Heikki Linnakangas <hlinnaka@iki.fi>, PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Date: 2022-07-01T15:11:05Z
Lists: pgsql-hackers
Attachments
- v5-0001-Add-protections-in-xlog-record-APIs-against-large.patch (application/octet-stream) patch v5-0001
- v5-0001-Add-protections-in-xlog-record-APIs-against-large.patch.backpatch (application/octet-stream)
On Tue, 21 Jun 2022 at 03:45, Michael Paquier <michael@paquier.xyz> wrote: > + /* > + * Ensure that xlogreader.c can read the record by ensuring that the > + * data section of the WAL record can be allocated. > + */ > + if (unlikely(!AllocSizeIsValid(total_len))) > + XLogErrorDataLimitExceeded(); > > By the way, while skimming through the patch, the WAL reader seems to > be a bit more pessimistic than this estimation, calculating the amount > to allocate as of DecodeXLogRecordRequiredSpace(), based on the > xl_tot_len given by a record. I see, thanks for notifying me about that. PFA a correction for that issue. It does copy over the value for MaxAllocSize from memutils.h into xlogreader.h, because we need that value in FRONTEND builds too, and memutils.h can't be included in FRONTEND builds. One file suffixed with .backpatch that doesn't include the function signature changes, but it is not optimized for any stable branch[15]. -Matthias PS. I'm not amused by the double copy we do in the xlogreader, as I had expected we'd just read the record and point into that single xl_rec_len-sized buffer. Apparently that's not how it works... [15] it should apply to stable branches all the way back to REL_15_STABLE and still work as expected. Any older than that I haven't tested, but probably only require some updates for XLogRecMaxLength in xlogreader.h.
Commits
-
Add more protections in WAL record APIs against overflows
- 8fcb32db98ed 16.0 landed
-
Add overflow protection for block-related data in WAL records
- ffd1b6bb6f8a 16.0 landed
-
Change internal RelFileNode references to RelFileNumber or RelFileLocator.
- b0a55e43299c 16.0 cited
-
Revamp the WAL record format.
- 2c03216d8311 9.5.0 cited