pgsql: Begin RI fast-path index scan under the switched user id

From: Amit Langote <amitlan(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Begin RI fast-path index scan under the switched user id
Date: 2026-08-07 08:05:15
Message-ID: E1wsFZr-00000000YKY-1mqJ@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Begin RI fast-path index scan under the switched user id

ri_FastPathCheck() called index_beginscan() before switching to the
referenced relation's owner for the permission check and probe. For
btree this has no consequence, but starting the scan before the user id
switch sets a poor example for code dealing with out-of-tree access
methods, whose beginscan could observe the wrong user id. Move
index_beginscan() after the SetUserIdAndSecContext() call.

Reported-by: Noah Misch <noah(at)leadboat(dot)com>
Reviewed-by: Ayush Tiwari <ayushtiwari(dot)slg01(at)gmail(dot)com>
Discussion: https://postgr.es/m/20260705210533.ee.noahmisch@microsoft.com
Backpatch-through: 19

Branch
------
REL_19_STABLE

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

Modified Files
--------------
src/backend/utils/adt/ri_triggers.c | 27 ++++++++++++++++++++-------
1 file changed, 20 insertions(+), 7 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Amit Langote 2026-08-07 08:05:29 pgsql: Begin RI fast-path index scan under the switched user id
Previous Message Amit Langote 2026-08-07 07:32:17 pgsql: Restrict RI fast-path FK check to btree referenced indexes