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 1wCGW1-001oUa-2w for pgsql-hackers@arkaria.postgresql.org; Mon, 13 Apr 2026 12:35:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wCGW0-006gaR-0F for pgsql-hackers@arkaria.postgresql.org; Mon, 13 Apr 2026 12:35:44 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wCGVz-006gZz-2O for pgsql-hackers@lists.postgresql.org; Mon, 13 Apr 2026 12:35:44 +0000 Received: from mail-dl1-x1231.google.com ([2607:f8b0:4864:20::1231]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wCGVy-00000000pic-2Aq8 for pgsql-hackers@postgresql.org; Mon, 13 Apr 2026 12:35:44 +0000 Received: by mail-dl1-x1231.google.com with SMTP id a92af1059eb24-12c20010f10so11013419c88.0 for ; Mon, 13 Apr 2026 05:35:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1776083740; cv=none; d=google.com; s=arc-20240605; b=DO/1yfmizwrpAIxgNwdz/1MRsxvq6vCunQ+Xf0lMVflqo0aIlZ8YApLCu+RwclYTOU GR6FP/57bA3lV/JKMEZw1jjXkAVimAKxINJWLVCaAh++sher4de+UQLcrC2uTAMS5S9n ak7g0tvbq5c5BIrnKuL4KCYhACAAv1SEceiblFs4t+hfJUwKYEG6Y5LAt6KG5+fBLDN0 YbS+IbhAKMY2As64uORO8plP2la3fc2E+lnKdKGfWbWR0TdI9oFncbF1oyoSVceypBqn FIAiMAV4sp2IVMJ9FBZiQyVXEmyWzXSKPH7quhR1dN52Bt8kBeiBew/qNqV+8fW+2sWb TLKw== 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=+dXUAsonqBCE2WRE59Bd5YoTXEV1QXRQPYD0Kt3r7/g=; fh=2Me72EB1DPbM4PWpehYaB73N3VZAJiXW6Uhj2udmb4Y=; b=ZacDQoyyKDHIJgHogFvdAnvBc8eiQ7KNHN+nunb87rLZRMZxuN6cRuCHZ7TP9systu nA0MwJHtYuSdMV5hY9b+pkoGyVQHc2S3Y2NNxUXD3pzkeEzbn0KzzhS4tgpdYQuOOTXk ClpZ2/59tTNp+elnryRvYO8ghcfCjjBh4Kpaz/HVE7q7oAyhQa8l4WG8SUPU5QYq08MS 6kp+Qi/FX8FdWL/rsaZI4DlGCo/Jq9fQfSsLBC/N7kh+LrXzB0cdBC07HO0lHb9F1Web v8rEM55VPfKy8RZM4vnLAigOzrHcdqhVfGVQD2HATFJ1Pc8bZn8tCKcgrgePPZsLHdrz X+wg==; 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=1776083740; x=1776688540; 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=+dXUAsonqBCE2WRE59Bd5YoTXEV1QXRQPYD0Kt3r7/g=; b=I/NklOhrikD7Je0IQ4hSbNa36WZOVyl87/2EA/xewqrCVbiNLnn2SO0HIaqIFBQDjn WWCHCpdWznndIa8oQ5syPDzUNi9mWU9wJRzceqdSgmt4FL7fs0Qy7FcPqcQ57X/v0V0H RmwTTDqLxFoyzgOPB+zZ0sW8A3IU32W+JBL7FvSq/r9G5rxeQ5qg6umqrm+gdTCLdbBr 2zTdi/bxXvlHXJFwkWlLkjRcQ+W0UfDahfSixioh5cXUUXD3kxwNEW5hsU4d/ArF2V/m HdeRYP6r8ivZjIONpDrAul93Yd07G22LcG4Y9ZXs3JgNF5Kv22wsWeoOpLGzlVGmYep2 SX3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776083740; x=1776688540; 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=+dXUAsonqBCE2WRE59Bd5YoTXEV1QXRQPYD0Kt3r7/g=; b=qcFOYfUdMRDHAZQA4rDbCCRu888NGaEFpHa8gBzynuu4nvPSAZWoJgcG0Ylx/qiPke 2zh9Gqwxpdq2grU4thF5WUnVBJ+2JZWobXwIQ+SvVFAbKNp9BRzw4kHfJAgdbld1JNeJ u41MgOcEyOOwztA2G81TcHqGsymYpeu8+c2zJ16JFpALcG4HdhSopqJ3FC5JXgTXIjTP BwUFdR0rEih6/PaFsT6Hso0X3DCee7Q6nE29AR+Y2mJ54quuD1aOqem9uJwXmI92p1WW ykfzhzQQzODYYgluQZ6ULb6NSuORnmaxLteTSBy9LAWKbkoYHVpHn8EQCtK2c+APIlQd eNlw== X-Forwarded-Encrypted: i=1; AFNElJ+Ncmmzqi9KFhu8qCpX0DvIR8WxgLyv1HMUIJTe59w92MUWabmYDR27L5dDQNEnkjy2MhFcj+NyHZAKFwQR@postgresql.org X-Gm-Message-State: AOJu0YzraosinJvAuhqLx43XBJyEU/mxFN5wfULTHQW7OkESqUvTRPY0 X9twojp9iPbuREBuDZe49EQI/C8CsmbZ3TlxfwExwmlBIWltIUW5ZPJdtYYLI8HaPrNEO6L2VnJ YkEncaqn7HuFwwAKSN4JnchERjmR2bYc= X-Gm-Gg: AeBDiessXx3FCcGXy6dTvj92qmovjYYMKyJ1z3jLyea/qNgWtWNjNXfJHQxtLuanQNt ttutf1+3o+eOwbLFFw9gTeGAfbxrN3x7AW/949LzpZI9LEABlCTmSo6duJaHjRKubdtx7jM/3CY pVmoiAllzniGhTsFxduV4vqn/RNYj+PGAn+FQf7O9MCqRzRlwk6OI0/u36XIAP7fV4XrC2rBmSS 2TOqjLrK2ZtInBYnDEUtkqJH9Es/DiyoGgk1wFOOz99IDZnVxeC3005mYwjaIksQlw3yYCkzi9s UJ0a0aI= X-Received: by 2002:a05:7022:fd0a:b0:128:d967:466c with SMTP id a92af1059eb24-12c34eeb82cmr8256702c88.24.1776083740052; Mon, 13 Apr 2026 05:35:40 -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> <67637cf8-8cbf-4f86-8775-52aa0329972d@uni-muenster.de> In-Reply-To: <67637cf8-8cbf-4f86-8775-52aa0329972d@uni-muenster.de> From: Soumya S Murali Date: Mon, 13 Apr 2026 18:06:03 +0530 X-Gm-Features: AQROBzByywCwmq1GRWIV9eiO27x4RfbRuiEdUPISxwL4NaowIKrSUUy39kBl9yo Message-ID: Subject: Re: Fix bug with accessing to temporary tables of other sessions To: Jim Jones Cc: Daniil Davydov <3danissimo@gmail.com>, Tom Lane , 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 all, On Wed, Apr 8, 2026 at 4:11=E2=80=AFPM Jim Jones wrote: > > Hi > > On 08/04/2026 11:17, Soumya S Murali wrote: > > I worked on the issue of accessing temporary tables belonging to other > > sessions and tried implementing the fix at the buffer manager level, > > as suggested. I added checks in ReadBuffer_common() and > > PrefetchBuffer() to reject access when a relation is temporary > > (relpersistence =3D TEMP) but does not use local buffers > > (!RelationUsesLocalBuffers) so that it ensures only heap page access > > is blocked, while catalog lookups and other metadata operations > > continue to work as before. While testing, I observed that in many > > cases the query does not reach the buffer manager because name > > resolution fails earlier with =E2=80=9Crelation does not exist=E2=80=9D= . However, the > > added checks ensure that even if execution reaches the buffer layer, > > access to other sessions=E2=80=99 temporary tables is safely rejected. = The > > change is minimal, and did not modify parser/ACL behavior and all > > regression tests got passed successfully too. > > Kindly review the attached patch herewith. Please let me know if this > > approach aligns with expectations or if further adjustments are > > needed. > > A few comments: > > =3D=3D PrefetchBuffer =3D=3D > > The condition nested inside the if (RelationUsesLocalBuffers(reln)) > tests the opposite of the main if !RelationUsesLocalBuffers(reln): > > if (RelationUsesLocalBuffers(reln)) > { > /* ACCESS DENIED CHECK */ > if (reln !=3D NULL && > reln->rd_rel !=3D NULL && > reln->rd_rel->relpersistence =3D=3D RELPERSISTENCE_TEMP && > !RelationUsesLocalBuffers(reln)) > { > ereport(ERROR, > (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), > errmsg("cannot access temporary tables of other sessions"))); > } > ... > } > > So it'll be always false, making the ereport unreachable. > > =3D=3D ReadBufferExtended =3D=3D > > These conditions cancel each other out: > > if (reln->rd_rel->relpersistence =3D=3D RELPERSISTENCE_TEMP && > !RelationUsesLocalBuffers(reln)) > > RelationUsesLocalBuffers(reln) expands to > ((relation)->rd_rel->relpersistence =3D=3D RELPERSISTENCE_TEMP), making t= he > error message unreachable. Perhaps you meant RELATION_IS_OTHER_TEMP? > > =3D=3D ReadBuffer_common =3D=3D > > Same as in ReadBufferExtended and PrefetchBuffer. > > =3D=3D tests =3D=3D > > You excluded the tests from the patch. > > =3D=3D patch version =3D=3D > > You forgot to add the patch version. Thank you for the detailed review and for pointing out these issues. I understood that the condition I used with RelationUsesLocalBuffers() was incorrect and made the checks unreachable. Also the RELATION_IS_OTHER_TEMP() was not the appropriate macro to use here. Regarding PrefetchBuffer, placing the check inside the RelationUsesLocalBuffers() branch was also logically inconsistent. Apologies for missing the tests and patch versioning in my submission. I will ensure these are included properly in future iterations. Based on the subsequent discussion and the analysis of the regression introduced by routing through read_stream_next_buffer(), I agree that the fix is better in the read stream / buffer read entry points rather than only in bufmgr. Thank you for your guidance. It really helped clarify both the root cause and the correct placement of the fix. Regards, Soumya