Re: Proper object locking for GRANT/REVOKE

From: Noah Misch <noah(at)leadboat(dot)com>
To: Peter Eisentraut <peter(at)eisentraut(dot)org>
Cc: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Proper object locking for GRANT/REVOKE
Date: 2025-06-23 23:16:09
Message-ID: 20250623231609.e2.nmisch@google.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Jun 11, 2025 at 05:22:53PM +0200, Peter Eisentraut wrote:
> On 09.12.24 02:25, Noah Misch wrote:
> > > Ok, we should probably put that comment back in slightly altered form, like
> > >
> > > "XXX This function intentionally takes only an AccessShareLock ... $REASON.
> > > In the face of concurrent DDL, we might easily latch
> > > onto an old version of an object, causing the GRANT or REVOKE statement
> > > to fail."
> >
> > Yep.
>
> There is an open item for PG18 for this. So here is a patch that adds a
> comment back, mostly from your descriptions in this thread.
>
> > > The change to AccessShareLock at least prevents confusing "cache lookup
> > > failed" messages, and might alleviate some security concerns about swapping
> > > in a completely different object concurrently (even if we currently think
> > > this is not an actual problem).
> >
> > Perhaps. To me, the v17 behavior smells mildly superior to the v18 behavior.
>
> Hmm. I think there has been a general effort to get rid of internal errors
> like "cache lookup failed ..." and replace them with proper user-facing
> errors. This change seems in line with that.

I have seen some commits along those lines, e.g. d8a0993. They weren't adding
lock acquisitions, though. If we've deliberately incurred lock acquisitions
just to get rid of "cache lookup failed ...", I don't remember those commits.

> An alternative, if we wanted to go back to the old behavior (other than
> reverting altogether, since I think the refactoring is still valuable),
> would be to allow get_object_address() to work with lockmode == NoLock. That
> would require a bit of work, but nothing magical.

That seems a bit better to me than your comment-only proposal, but either
could be okay.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Jacob Champion 2025-06-23 23:36:22 [PATCH] Fix OAuth feature detection on OpenBSD+Meson
Previous Message Melanie Plageman 2025-06-23 22:30:24 Re: Vacuum ERRORs out considering freezing dead tuples from before OldestXmin