Re: Fix segfault while accessing half-initialized hash table in pgstat_shmem.c
Mikhail Kot <mikhail.kot@databricks.com>
From: Mikhail Kot <mikhail.kot@databricks.com>
To: pgsql-hackers@lists.postgresql.org
Cc: to@myrrc.dev
Date: 2025-09-03T21:39:04Z
Lists: pgsql-hackers
Attachments
- 0002-fix-sshashent-access-segfault-when-it-s-half-initial.patch (application/octet-stream) patch 0002
Hi Michael, Steven, and Ranier, > Anyway, couldn't we flip the order of the operations in pgstat_init_entry() so as we do first an allocation and avoid any inconsistency in the shared state? The issue is not only in pgstat_init_entry(). Currently it errors on OOM but this doesn't prevent us from calling pgstat_lock_entry() through pgstat_get_entry_ref() which accesses a non-initialized lock. Here's the second version of the patch. Now we remove inserted hash entry on OOM which would prevent accessing the entry
Commits
-
Fix corruption of pgstats shared hashtable due to OOM failures
- 1852ec5db5d8 15.15 landed
- 12f57681c79b 16.11 landed
- 3e6dfcfb0529 17.7 landed
- f256a7bba728 18.0 landed
- 8191e0c16a03 19 (unreleased) landed