Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w5ILY-0036RU-0P for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Mar 2026 07:08:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w5ILW-00CZMI-1p for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Mar 2026 07:08:06 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from <3danissimo@gmail.com>) id 1w5ILW-00CZM7-0U for pgsql-hackers@lists.postgresql.org; Wed, 25 Mar 2026 07:08:06 +0000 Received: from mail-yw1-x1135.google.com ([2607:f8b0:4864:20::1135]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from <3danissimo@gmail.com>) id 1w5ILU-00000000vVa-2p6p for pgsql-hackers@postgresql.org; Wed, 25 Mar 2026 07:08:05 +0000 Received: by mail-yw1-x1135.google.com with SMTP id 00721157ae682-79ab5fd969aso32906457b3.0 for ; Wed, 25 Mar 2026 00:08:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1774422484; cv=none; d=google.com; s=arc-20240605; b=ECuswNoTkCh4RKJ4KpexJnrG/1fPxPeaVnn1JdxVWK3e0BDv5JeoHlougGJ2h8512q WC5CwEiz2Acarqn1FOseSW8y6i5wg1q2Txfwb/e+V3DU1ZjDlPvnlQy/vODTL//ZJ6bS SC16wG2C0EI7pZSJe53gcFEj9Jr/fvcBoR8kzQXIo32l5xyUhP726CKAkD3Hg3Fe328k 68Ubea9ZgKsvLKE06+t7XB1+zG5s8eOTUsgHxnbRNpHpV2C5N+q/nEiehG8Na7G4HrS0 GkuxvjBvUrvsaNLb8Fu9yiEh6HpJHvnLtUf32xjy75u6w4Izuc8RPDdqJB7xsTNcQKrk Bk2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=6UgWghBkszb3haSoBjG5mGeqrA2SYrWAW5UD61kOd3I=; fh=r7HUbLSHTD68eSq90w8rzi3xfUgT6aRjfCGzUFAcw7o=; b=h4i5MwhOLNmRUF1CZvCjab0SbQZ6x7JTisB+SMbKTVDhcTRYl6hXqhB5OySPSP//wu HwaS7yzZa25UljF8FMAtWHkqaP1ziA2+6feAlDVSAi8HVeCgXsDCQ+Cjuoa9pSFo/LF/ DG2rUG3LuIjSKhSfX7h8Ah/KuFZ3E5AUC4OKBP/eJ8liGn5zGBTTFPPe3k82QM9C29qe 446OI4gW0wxeUW4nCmLQu/C0W/slyt2fIvnj7ZXI8sexKdfONaitCUHpalXPi6C9Atj5 X2Wgody4uSRf3LJDre+X7c07Hhlf6wfuwTMdpnpO+BISPdouxRBSsZ1v35nCgJ9oTnVx rlWQ==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774422484; x=1775027284; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=6UgWghBkszb3haSoBjG5mGeqrA2SYrWAW5UD61kOd3I=; b=rKHs7+30hfcMlJJ83bAE2ikXEU7/OkD0DUM2soy4Df6LtuTlrlz+LYncInjEkprZiI rHg9/HAAXZzb1QNHDkv7aVSYQgxT6aVLJSzmJfo78BHY+M+zR7kS9jd5rrjj+4T1Ug3z p/MBCvtstdMvGKfWOFUJ+IaqDfXXueBgXMKhvV2NXRwU6nVm//GM0Ky6m+BODDnnuaph hz6TjuqQPnie4KZNzO0eEA1EJQyIfQTGqFt5Bj+RZ4o3ILbhO3paR3kntsSw1OclLjAZ XzElRjqVQb9fQhWkGPNJ8mdDoQgiCdWaXuGmWOSZCRMOACG7H2ig0X3SHY4iVcTaExDH 0/bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774422484; x=1775027284; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=6UgWghBkszb3haSoBjG5mGeqrA2SYrWAW5UD61kOd3I=; b=Po92G1QwN2RA0BgQmSyvjsFJBXrL9I46jaVStR5ifiwuf26WAnE6Z7+XDrLPdGSkxd eYoDI5UolhEZVl+fVdUdfl1qOF1ck3QmFYL9Nf4xF8jt+FhdJ88B2RpsIwAepyMTVF1o QC47P6OPAvQkVFavxTcdBWi6uT4S9GYUeXWwa+D29ffjqXBsYNaJmYgGiYaadzw08ojL Pft0o/otKDVCM1bDm8hkOsZi6myYEomg0cvpkyjZbhl3IC2tAeAD34OEkjAbJqID9nuc NI4E1f2oIzP+fhkxgZpy4mg62wLN0L6dB62b+3CzbRWkNnsq8EGEn0MqFz7IFV0G4ZDk QnBQ== X-Forwarded-Encrypted: i=1; AJvYcCUfswsZ7D0O9V1rO0gqOKh0KGhSNr9wMHwYXBrMbdE/7sK1CvDRdKvoYG1U29CpeWoKzJiAkPXWBrc2vZLC@postgresql.org X-Gm-Message-State: AOJu0YxBOPfwNh5ZL5uicwTbz9PSVG4wsOtrXtIefOlg3b9XM3oBWct8 603byQZH0ZCmH3Dt0oWDrHr9ZGFGGfbJBFZDUqePDRZjbxord+uqiaxyY3UrIbNJq5SgPz/iLTa XY78x26UtGj+xwyuuOTo+ewCwL433wvI= X-Gm-Gg: ATEYQzwXL0lCnKSRHE+xicOiqbTQQNG5kjvRB+dYcVYuMSWzG+lk/bq0mdsyUbVxvop zJz1IU6s8K6czJpryz3x+/7UG2S82YSdU5WAWuExkkhioaBqnzchEenN8Q/iK1C642pXReecBms bxlZRxq0gcrO0LImC9yi6S2ZrhBXAR4Gb2lCwL+FH6zocH/tFrlDG0ET4eWLbfVRPrHAoox+tm9 1VuCkkSPwl/6uuN/0IT1ErfLtfoBUaX02bbIh28BT4MCZsFAEDU2121ZXIXHzLY2/vpL8HFN3Uw X8obgla3ZuOUhgsjhZ8= X-Received: by 2002:a05:690c:7:b0:79a:b49a:cb38 with SMTP id 00721157ae682-79acf6a6d65mr23339087b3.59.1774422483857; Wed, 25 Mar 2026 00:08:03 -0700 (PDT) MIME-Version: 1.0 References: <2f3fa419-9000-4e2a-b070-6e35d5de0e4c@uni-muenster.de> <751a6cb8-cac8-46c4-8c64-9e23f663e926@uni-muenster.de> <1a32fc83-df78-4774-97dc-2bb06dbb16e9@uni-muenster.de> <3529398.1774273446@sss.pgh.pa.us> <4075754.1774378690@sss.pgh.pa.us> In-Reply-To: <4075754.1774378690@sss.pgh.pa.us> From: Daniil Davydov <3danissimo@gmail.com> Date: Wed, 25 Mar 2026 14:07:52 +0700 X-Gm-Features: AQROBzA6zNbgoAD5skH74Aw4PNqO9648YPVZmMhw2GdL9novk2bpGU_dOw0Noq4 Message-ID: Subject: Re: Fix bug with accessing to temporary tables of other sessions To: Tom Lane Cc: Jim Jones , Soumya S Murali , Stepan Neretin , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Wed, Mar 25, 2026 at 1:58=E2=80=AFAM Tom Lane wrote: > > > Actually, v12 patch is not about a superuser rights restriction, but ab= out > > forbidding such operations for everyone. > > ... including superusers, who bypass permissions restrictions > everywhere else. You are going to have to contort the ACL system > badly to make that happen at all, and I would not be surprised > if you introduce new bugs. > I've never dealt with the ACL system before, so it's hard for me to assess the scale of the problem. I am inclined to believe you on this issue. > >> The actual problem is that the buffer manager is incapable of dealing > >> with other sessions' temp tables, and we need to un-break the buffer > >> manager's defense for that implementation restriction. So I feel the > >> correct approach is something similar to what I described here: > >> https://www.postgresql.org/message-id/flat/2736425.1758475979%40sss.pg= h.pa.us > > > Handling access to other-temp-tables on the buffer manager level seems = to me > > like fighting the symptom, not the cause. > > No, it IS the cause. If someday someone were to reimplement buffer > management in a way that didn't have this implementation restriction, > we would surely not arbitrarily restrict superusers from looking at > tables that they then would physically be able to look at. > OK, now I fully understand your point (I hope so) : We want to restrict backend access to other-temp-tables just because it is physically impossible for them to read the pages of such tables. And if som= e users has enough privileges, it is OK for us to allow them to lock/vacuum/drop/... other-temp-tables. I.e. only operations with heap page= s access must be forbidden, and the buffer manager layer is an appropriate pl= ace for it. > > Am I missing something? > > Mainly, that we had a setup that was working fine for decades, > until somebody made holes in it with careless refactoring. > We should fix that mistake, not introduce inconsistent-with- > decades-of-practice permissions behavior to hide the mistake > at an unrelated logical level. > Yeah, we have a few checks in the bufmgr (PrefetchBuffer, ReadBufferExtende= d), but they stopped coping with their task. > Also, we need a defense at the buffer manager level anyway, because > otherwise C code could try to access another session's temp table > and we'd not realize it was getting bogus answers. (Whether such > an attempt is a bug or not is a different discussion; but we at > least need some logic that detects that it won't work, and the ACL > system cannot be expected to stop C-level code from trying.) > > Also, we really need a patch that's simple and non-invasive enough > to be back-patched into v17 and v18. This proposal is not that. > OK > > > I don't actually want to use gram.y as a main solver of this issue. But > > gram.y is setting the "relpersistence" field for the RangeVar and all > > subsequent code is treating this value as truthful. > > I do kind of agree with this concern, but the v12 patch simply moves > the untruthfulness around. Reality is that we cannot know whether an > unqualified-name RangeVar references a temp table until we do a > catalog lookup, ... Yep, Jim's example shows us that we cannot always rely on the "relpersisten= ce" field. > ...so IMO we should not have a relpersistence field there > at all. At best it means something quite different from what it means > elsewhere, and that's a recipe for confusion. But changing that would > not be a bug fix (AFAIK) but refactoring to reduce the probability of > future bugs. > I agree with the idea to get rid of this field. By now I cannot say for sur= e whether we can fix a bug without modifying the RangeVar structure. But I'll try to implement proposed logic only within the bufmgr. Thank you very much for your comments! I'll post a new patch in the near future. -- Best regards, Daniil Davydov