pgsql: Add defenses against running with a wrong selection of LOBLKSIZE

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Add defenses against running with a wrong selection of LOBLKSIZE
Date: 2014-06-05 15:31:48
Message-ID: [email protected]
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Add defenses against running with a wrong selection of LOBLKSIZE.

It's critical that the backend's idea of LOBLKSIZE match the way data has
actually been divided up in pg_largeobject. While we don't provide any
direct way to adjust that value, doing so is a one-line source code change
and various people have expressed interest recently in changing it. So,
just as with TOAST_MAX_CHUNK_SIZE, it seems prudent to record the value in
pg_control and cross-check that the backend's compiled-in setting matches
the on-disk data.

Also tweak the code in inv_api.c so that fetches from pg_largeobject
explicitly verify that the length of the data field is not more than
LOBLKSIZE. Formerly we just had Asserts() for that, which is no protection
at all in production builds. In some of the call sites an overlength data
value would translate directly to a security-relevant stack clobber, so it
seems worth one extra runtime comparison to be sure.

In the back branches, we can't change the contents of pg_control; but we
can still make the extra checks in inv_api.c, which will offer some amount
of protection against running with the wrong value of LOBLKSIZE.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/5f93c37805e7485488480916b4585e098d3cc883

Modified Files
--------------
src/backend/access/transam/xlog.c | 9 +++
src/backend/storage/large_object/inv_api.c | 84 +++++++++++++---------------
src/bin/pg_controldata/pg_controldata.c | 2 +
src/bin/pg_resetxlog/pg_resetxlog.c | 4 ++
src/include/catalog/pg_control.h | 3 +-
src/include/storage/large_object.h | 2 +
6 files changed, 58 insertions(+), 46 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Andres Freund 2014-06-05 16:32:38 pgsql: Fix off-by-one in decoding causing one-record events to be skipp
Previous Message Andres Freund 2014-06-05 14:30:45 pgsql: Consistently spell a replication slot's name as slot_name.