pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Rowley <drowley@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix race condition in TupleDescCompactAttr assert code
Date: Tue, 24 Dec 2024 01:55:39 +0000
Message-ID: <E1tPu94-0011Qv-NZ@gemulon.postgresql.org> (raw)

Fix race condition in TupleDescCompactAttr assert code

5983a4cff added CompactAttribute as an abbreviated alternative to
FormData_pg_attribute to allow more cache-friendly processing in tasks
related to TupleDescs.  That commit contained some assert-only code to
check that the CompactAttribute had been populated correctly, however,
the method used to do that checking caused the TupleDesc's
CompactAttribute to be zeroed before it was repopulated and compared to
the snapshot taken before the memset call.  This caused issues as the type
cache caches TupleDescs in shared memory which can be used by multiple
backend processes at the same time.  There was a window of time between
the zero and repopulation of the CompactAttribute where another process
would mistakenly think that the CompactAttribute is invalid due to the
memset.

To fix this, instead of taking a snapshot of the CompactAttribute and
calling populate_compact_attribute() and comparing the snapshot to the
freshly populated TupleDesc's CompactAttribute, refactor things so we
can just populate a temporary CompactAttribute on the stack.  This way
we don't touch the TupleDesc's memory.

Reported-by: Alexander Lakhin, SQLsmith
Discussion: https://postgr.es/m/ca3a256a-5d12-42db-aabe-a75a030d9fb9@gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/6f3820f37aba94232468365bae7ba5de697fe993

Modified Files
--------------
src/backend/access/common/tupdesc.c | 71 ++++++++++++++++++++++++++++++++-----
src/include/access/tupdesc.h        | 29 ++++-----------
2 files changed, 69 insertions(+), 31 deletions(-)



Message-ID: <E1tPu94-0011Qv-NZ@gemulon.postgresql.org>
Permalink:  ../E1tPu94-0011Qv-NZ@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1tPu94-0011Qv-NZ@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: drowley@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Fix race condition in TupleDescCompactAttr assert code
  In-Reply-To: <E1tPu94-0011Qv-NZ@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox