pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andres Freund <andres@anarazel.de>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix mislabeling of PROC_QUEUE->links as PGPROC, fixing UBSan on
Date: Sat, 19 Nov 2022 21:56:50 +0000
Message-ID: <E1owVpR-000vY0-Ia@gemulon.postgresql.org> (raw)

Fix mislabeling of PROC_QUEUE->links as PGPROC, fixing UBSan on 32bit

ProcSleep() used a PGPROC* variable to point to PROC_QUEUE->links.next,
because that does "the right thing" with SHMQueueInsertBefore(). While that
largely works, it's certainly not correct and unnecessary - we can just use
SHM_QUEUE* to point to the insertion point.

Noticed when testing a 32bit of postgres with undefined behavior
sanitizer. UBSan noticed that sometimes the supposed PGPROC wasn't
sufficiently aligned (required since 46d6e5f5679, ensured indirectly, via
ShmemAllocRaw() guaranteeing cacheline alignment).

For now fix this by using a SHM_QUEUE* for the insertion point. Subsequently
we should replace all the use of PROC_QUEUE and SHM_QUEUE with ilist.h, but
that's a larger change that we don't want to backpatch.

Backpatch to all supported versions - it's useful to be able to run postgres
under UBSan.

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/20221117014230.op5kmgypdv2dtqsf@awork3.anarazel.de
Backpatch: 11-

Branch
------
REL_14_STABLE

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

Modified Files
--------------
src/backend/storage/lmgr/proc.c | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)



view thread (6+ messages)  latest in thread

Message-ID: <E1owVpR-000vY0-Ia@gemulon.postgresql.org>
Permalink:  ../E1owVpR-000vY0-Ia@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1owVpR-000vY0-Ia@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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: andres@anarazel.de
  Subject: Re: pgsql: Fix mislabeling of PROC_QUEUE->links as PGPROC, fixing UBSan on
  In-Reply-To: <E1owVpR-000vY0-Ia@gemulon.postgresql.org>
  References: <E1owVpR-000vY0-Ia@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