agora inbox for pgsql-committers@postgresql.org
help / color / mirror / Atom feedFrom: Tomas Vondra <tomas.vondra@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix out-of-bounds access in autoprewarm worker
Date: Fri, 26 Jun 2026 17:54:37 +0000
Message-ID: <E1wdAlC-000J3L-0R@gemulon.postgresql.org> (raw)
Fix out-of-bounds access in autoprewarm worker
The read stream callback apw_read_stream_next_block() advances p->pos
through the block_info array. When processing the last block, it
increments p->pos to prewarm_stop_idx before returning. The callback
itself is safe because it checks bounds before accessing the array.
However, the caller assigned blk from block_info[i] at the end of the
loop body, before the loop condition was re-evaluated. When i equaled
prewarm_stop_idx, this accessed memory beyond the allocated DSM segment,
causing a segfault.
Restructure the loop to check bounds at the top and assign blk at the
beginning of the loop body, where it is always safe. This avoids the
need for an explicit bounds check at the end.
Backpatch to 18, where the bug was introduced by commit 6acab8bdbcda.
Author: Matheus Alcantara <mths.dev@pm.me>
Reported-by: Glauber Batista <glauberrbatista@gmail.com>
Reviewed-by: Melanie Plageman <melanieplageman@gmail.com>
Reviewed-by: Tomas Vondra <tomas@vondra.me>
Backpatch-through: 18
Discussion: https://www.postgresql.org/message-id/CAO%2B_mTQgQyTYwDh%3DU8iTnsDmOGyWsZJjUV31SmEYwmw6_xY6Bw%40mail...
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/dac36601fd774a00b3b7390a656a689e2881bcf4
Modified Files
--------------
contrib/pg_prewarm/autoprewarm.c | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
view thread (2+ messages) latest in thread
Message-ID: <E1wdAlC-000J3L-0R@gemulon.postgresql.org>
Permalink: ../E1wdAlC-000J3L-0R@gemulon.postgresql.org/
Also on: postgresql.org/message-id/E1wdAlC-000J3L-0R@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: tomas.vondra@postgresql.org, pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: Fix out-of-bounds access in autoprewarm worker
In-Reply-To: <E1wdAlC-000J3L-0R@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 agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox