Replace typcache.c's buggy in_progress_list.

Commit b85a9d046efdd27775cbe7db9e92aad96aab4ada added this mechanism
as a response to bugs reported when the same feature was previously
committed as c14d4acb81348a34497b53a19dce2924cc4f6551. Unfortunately,
it turns out to have multiple bugs. AtEOSubXact_TypeCache() cleared
the entire list, instead of only the entries added at or below
the current subtransaction level. Both AtEOXact_TypeCache() and
AtEOSubXact_TypeCache() perform allocations in the abort path,
which risks a second error before we've finished recovering from
the first. Also, because in_progress_list was used to defer adding
entries to RelIdToTypeIdCacheHash, it introduced a risk of missing
invalidations that occurred after lookup_type_cache() performed
the pg_type lookup and before the RelIdToTypeIdCacheHash update.
Some of these problems are security vulnerabilities.

Removing in_progress_list fixes all of these problems, but risks
reintroducing the problems that in_progress_list was meant to fix.
Specifically, we have to make sure that an invalidation processed
while lookup_type_cache() is executing can't remove the associated
RelIdToTypeIdCacheHash entry before the TypeCacheEntry is even
returned to the caller. This commit solves that problem by never
removing entries from that hash table under any circumstances.
Instead, we now tolerate stale hash table entries, and check
whether any given entry is still valid before relying on it. See
the comments for further details.

Reported-by: Peter Geoghegan <[email protected]>
Reviewed-by: Michael Paquier <[email protected]>
Reviewed-by: Nathan Bossart <[email protected]>
Security: CVE-2026-120144
Backpatch-through: 18

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/016b63271fb794436255ae13917793486a6c450f
Author: Robert Haas <[email protected]>

Modified Files
--------------
src/backend/utils/cache/typcache.c | 274 ++++++++++---------------------------
1 file changed, 73 insertions(+), 201 deletions(-)

Reply via email to