Re: Fix bug with accessing to temporary tables of other sessions

From: Daniil Davydov <3danissimo(at)gmail(dot)com>
To: Jim Jones <jim(dot)jones(at)uni-muenster(dot)de>
Cc: Soumya S Murali <soumyamurali(dot)work(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Stepan Neretin <slpmcf(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Fix bug with accessing to temporary tables of other sessions
Date: 2026-04-10 07:10:02
Message-ID: CAJDiXgi0JFk0f2KWWQkzLBC5P7erX9WP18qqnbi-rjZ-K-P=3w@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Fri, Apr 10, 2026 at 12:46 AM Jim Jones <jim(dot)jones(at)uni-muenster(dot)de> wrote:
>
> I guess a check in read_stream_begin_relation()
> and in StartReadBuffersImpl() would be the best solution? If you agree,
> could you add it in v16?

Having both checks might look a bit redundant since the read stream will
eventually call the StartReadBuffersImpl function. On the other hand, there are
many places which are checking this restriction even if subsequent functions
(from bufmgr) also have this check.

So, I'll keep both checks and a bit reduce the comments in the bufmgr.c .

BTW, what do you think about making this comment less "concrete"? :
# SELECT via index scan from other session.
# Sequential scans are blocked at read_stream_begin_relation(); index scans
# bypass that path entirely and reach ReadBufferExtended() in bufmgr.c
# (nbtree's _bt_getbuf calls ReadBuffer directly for individual page fetches).
# enable_seqscan=off forces the planner to use the index.

I mean that if the described logic changes, this comment will become confusing.
We can describe the test in general words. For example :
# Index scans can use a different code path from the one sequential scans are
# following. Make sure that we cannot access other sessions' temp tables during
# index scan either.

Thank you for the comments! Please, see an updated set of patches.

--
Best regards,
Daniil Davydov

Attachment Content-Type Size
v16-0002-Test-cross-session-access-on-temporary-tables.patch text/x-patch 4.7 KB
v16-0001-Prevent-access-to-other-sessions-temp-tables.patch text/x-patch 3.2 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Lukas Fittl 2026-04-10 07:12:00 Re: Reduce timing overhead of EXPLAIN ANALYZE using rdtsc?
Previous Message Chao Li 2026-04-10 07:07:03 Re: Use proc_exit() in WalRcvWaitForStartPosition