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 <[email protected]> Reviewed-by: Ayush Tiwari <[email protected]> Discussion: https://postgr.es/m/[email protected] Backpatch-through: 19 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/7c1c2f0b8d837fa49df434ecc4438e7d3476144e Modified Files -------------- src/backend/utils/adt/ri_triggers.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-)
