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: aio: Fix crash potential for pg_aios views due to late state upd
Date: Fri, 25 Apr 2025 17:35:03 +0000
Message-ID: <E1u8Mx5-001kvb-1k@gemulon.postgresql.org> (raw)

aio: Fix crash potential for pg_aios views due to late state update

pgaio_io_reclaim() reset the fields in PgAioHandle before updating the state
to IDLE or incrementing the generation. For most things that's OK, but for
pg_get_aios() it is not - if it copied the PgAioHandle while fields were being
reset, we wouldn't detect that and could call
pgaio_io_get_target_description() with ioh->target == PGAIO_TID_INVALID,
leading to a crash.

Fix this issue by incrementing the generation and state earlier, before
resetting.

Also add an assertion to pgaio_io_get_target_description() for the target to
be valid - that'd have made this case a bit easier to debug. While at it,
add/update a few related assertions.

Author: Alexander Lakhin <exclusion@gmail.com>
Discussion: https://postgr.es/m/062daca9-dfad-4750-9da8-b13388301ad9@gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/0d9114b7040d7503096e2897f4c856b17d461f6a

Modified Files
--------------
src/backend/storage/aio/aio.c        | 21 +++++++++++++++------
src/backend/storage/aio/aio_target.c | 12 +++++++++---
2 files changed, 24 insertions(+), 9 deletions(-)



Message-ID: <E1u8Mx5-001kvb-1k@gemulon.postgresql.org>
Permalink:  ../E1u8Mx5-001kvb-1k@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1u8Mx5-001kvb-1k@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: aio: Fix crash potential for pg_aios views due to late state upd
  In-Reply-To: <E1u8Mx5-001kvb-1k@gemulon.postgresql.org>
  References: <E1u8Mx5-001kvb-1k@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