pg.ddx.io pgsql-committers@postgresql.org mailing list archive
help / color / mirror / Atom feedpgsql: Ensure COPY TO on an RLS-enabled table copies no more than it sh
8+ messages / 2 participants
[nested] [flat]
* pgsql: Ensure COPY TO on an RLS-enabled table copies no more than it sh
@ 2023-03-10 18:52 Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 8+ messages in thread
From: Tom Lane @ 2023-03-10 18:52 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Ensure COPY TO on an RLS-enabled table copies no more than it should.
The COPY documentation is quite clear that "COPY relation TO" copies
rows from only the named table, not any inheritance children it may
have. However, if you enabled row-level security on the table then
this stopped being true, because the code forgot to apply the ONLY
modifier in the "SELECT ... FROM relation" query that it constructs
in order to allow RLS predicates to be attached. Fix that.
Report and patch by Antonin Houska (comment adjustments and test case
by me). Back-patch to all supported branches.
Discussion: https://postgr.es/m/3472.1675251957@antos
Branch
------
REL_13_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/866fd004d9f94b87d453642c0c854d38884d3d3d
Modified Files
--------------
src/backend/commands/copy.c | 9 +++++---
src/test/regress/expected/rowsecurity.out | 37 +++++++++++++++++++++++++++++++
src/test/regress/sql/rowsecurity.sql | 34 ++++++++++++++++++++++++++++
3 files changed, 77 insertions(+), 3 deletions(-)
^ permalink raw reply [nested|flat] 8+ messages in thread
* pgsql: Ensure COPY TO on an RLS-enabled table copies no more than it sh
@ 2023-03-10 18:52 Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 8+ messages in thread
From: Tom Lane @ 2023-03-10 18:52 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Ensure COPY TO on an RLS-enabled table copies no more than it should.
The COPY documentation is quite clear that "COPY relation TO" copies
rows from only the named table, not any inheritance children it may
have. However, if you enabled row-level security on the table then
this stopped being true, because the code forgot to apply the ONLY
modifier in the "SELECT ... FROM relation" query that it constructs
in order to allow RLS predicates to be attached. Fix that.
Report and patch by Antonin Houska (comment adjustments and test case
by me). Back-patch to all supported branches.
Discussion: https://postgr.es/m/3472.1675251957@antos
Branch
------
REL_14_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/53a53ea332131b3d29d8d69e1dc2823f4d6ff21a
Modified Files
--------------
src/backend/commands/copy.c | 5 ++++-
src/backend/commands/copyto.c | 4 ++--
src/test/regress/expected/rowsecurity.out | 37 +++++++++++++++++++++++++++++++
src/test/regress/sql/rowsecurity.sql | 34 ++++++++++++++++++++++++++++
4 files changed, 77 insertions(+), 3 deletions(-)
^ permalink raw reply [nested|flat] 8+ messages in thread
* pgsql: Ensure COPY TO on an RLS-enabled table copies no more than it sh
@ 2023-03-10 18:52 Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 8+ messages in thread
From: Tom Lane @ 2023-03-10 18:52 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Ensure COPY TO on an RLS-enabled table copies no more than it should.
The COPY documentation is quite clear that "COPY relation TO" copies
rows from only the named table, not any inheritance children it may
have. However, if you enabled row-level security on the table then
this stopped being true, because the code forgot to apply the ONLY
modifier in the "SELECT ... FROM relation" query that it constructs
in order to allow RLS predicates to be attached. Fix that.
Report and patch by Antonin Houska (comment adjustments and test case
by me). Back-patch to all supported branches.
Discussion: https://postgr.es/m/3472.1675251957@antos
Branch
------
REL_15_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/59947bac7384ac56b5c95c69dee7655e2ed810df
Modified Files
--------------
src/backend/commands/copy.c | 5 ++++-
src/backend/commands/copyto.c | 4 ++--
src/test/regress/expected/rowsecurity.out | 37 +++++++++++++++++++++++++++++++
src/test/regress/sql/rowsecurity.sql | 34 ++++++++++++++++++++++++++++
4 files changed, 77 insertions(+), 3 deletions(-)
^ permalink raw reply [nested|flat] 8+ messages in thread
* pgsql: Ensure COPY TO on an RLS-enabled table copies no more than it sh
@ 2023-03-10 18:52 Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 8+ messages in thread
From: Tom Lane @ 2023-03-10 18:52 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Ensure COPY TO on an RLS-enabled table copies no more than it should.
The COPY documentation is quite clear that "COPY relation TO" copies
rows from only the named table, not any inheritance children it may
have. However, if you enabled row-level security on the table then
this stopped being true, because the code forgot to apply the ONLY
modifier in the "SELECT ... FROM relation" query that it constructs
in order to allow RLS predicates to be attached. Fix that.
Report and patch by Antonin Houska (comment adjustments and test case
by me). Back-patch to all supported branches.
Discussion: https://postgr.es/m/3472.1675251957@antos
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/d66bb048c3130c7b7a4876fc9050291f9e4cad2b
Modified Files
--------------
src/backend/commands/copy.c | 5 ++++-
src/backend/commands/copyto.c | 4 ++--
src/test/regress/expected/rowsecurity.out | 37 +++++++++++++++++++++++++++++++
src/test/regress/sql/rowsecurity.sql | 34 ++++++++++++++++++++++++++++
4 files changed, 77 insertions(+), 3 deletions(-)
^ permalink raw reply [nested|flat] 8+ messages in thread
* pgsql: Ensure COPY TO on an RLS-enabled table copies no more than it sh
@ 2023-03-10 18:52 Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 8+ messages in thread
From: Tom Lane @ 2023-03-10 18:52 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Ensure COPY TO on an RLS-enabled table copies no more than it should.
The COPY documentation is quite clear that "COPY relation TO" copies
rows from only the named table, not any inheritance children it may
have. However, if you enabled row-level security on the table then
this stopped being true, because the code forgot to apply the ONLY
modifier in the "SELECT ... FROM relation" query that it constructs
in order to allow RLS predicates to be attached. Fix that.
Report and patch by Antonin Houska (comment adjustments and test case
by me). Back-patch to all supported branches.
Discussion: https://postgr.es/m/3472.1675251957@antos
Branch
------
REL_11_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/6e2674d772b017f4ad4e36394aa1cf64c05b46e5
Modified Files
--------------
src/backend/commands/copy.c | 9 +++++---
src/test/regress/expected/rowsecurity.out | 37 +++++++++++++++++++++++++++++++
src/test/regress/sql/rowsecurity.sql | 34 ++++++++++++++++++++++++++++
3 files changed, 77 insertions(+), 3 deletions(-)
^ permalink raw reply [nested|flat] 8+ messages in thread
* pgsql: Ensure COPY TO on an RLS-enabled table copies no more than it sh
@ 2023-03-10 18:52 Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 8+ messages in thread
From: Tom Lane @ 2023-03-10 18:52 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Ensure COPY TO on an RLS-enabled table copies no more than it should.
The COPY documentation is quite clear that "COPY relation TO" copies
rows from only the named table, not any inheritance children it may
have. However, if you enabled row-level security on the table then
this stopped being true, because the code forgot to apply the ONLY
modifier in the "SELECT ... FROM relation" query that it constructs
in order to allow RLS predicates to be attached. Fix that.
Report and patch by Antonin Houska (comment adjustments and test case
by me). Back-patch to all supported branches.
Discussion: https://postgr.es/m/3472.1675251957@antos
Branch
------
REL_12_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/a30310833d071cfe9c1e7a9768e4d4df47685106
Modified Files
--------------
src/backend/commands/copy.c | 9 +++++---
src/test/regress/expected/rowsecurity.out | 37 +++++++++++++++++++++++++++++++
src/test/regress/sql/rowsecurity.sql | 34 ++++++++++++++++++++++++++++
3 files changed, 77 insertions(+), 3 deletions(-)
^ permalink raw reply [nested|flat] 8+ messages in thread
* [PATCH v1 1/1] fix LWLock shmem reinitialization
@ 2025-09-17 03:11 Nathan Bossart <nathan@postgresql.org>
0 siblings, 0 replies; 8+ messages in thread
From: Nathan Bossart @ 2025-09-17 03:11 UTC (permalink / raw)
---
src/backend/storage/lmgr/lwlock.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
inline patch 1: src/backend/storage/lmgr/lwlock.c (+10/-8 lines) download inline-1.patch
diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c
index 46c82c63ca5..694e9e33510 100644
--- a/src/backend/storage/lmgr/lwlock.c
+++ b/src/backend/storage/lmgr/lwlock.c
@@ -192,6 +192,9 @@ typedef struct NamedLWLockTrancheRequest
int NamedLWLockTrancheRequests = 0;
NamedLWLockTrancheRequest *NamedLWLockTrancheRequestArray = NULL;
+/* postmaster's local copy of the request array */
+static NamedLWLockTrancheRequest *LocalNamedLWLockTrancheRequestArray;
+
/* shared memory counter of registered tranches */
int *LWLockCounter = NULL;
@@ -382,7 +385,7 @@ NumLWLocksForNamedTranches(void)
int i;
for (i = 0; i < NamedLWLockTrancheRequests; i++)
- numLocks += NamedLWLockTrancheRequestArray[i].num_lwlocks;
+ numLocks += LocalNamedLWLockTrancheRequestArray[i].num_lwlocks;
return numLocks;
}
@@ -457,9 +460,8 @@ CreateLWLocks(void)
*/
if (NamedLWLockTrancheRequests > 0)
{
- memcpy(ptr, NamedLWLockTrancheRequestArray,
+ memcpy(ptr, LocalNamedLWLockTrancheRequestArray,
NamedLWLockTrancheRequests * sizeof(NamedLWLockTrancheRequest));
- pfree(NamedLWLockTrancheRequestArray);
NamedLWLockTrancheRequestArray = (NamedLWLockTrancheRequest *) ptr;
ptr += NamedLWLockTrancheRequests * sizeof(NamedLWLockTrancheRequest);
}
@@ -648,10 +650,10 @@ RequestNamedLWLockTranche(const char *tranche_name, int num_lwlocks)
errdetail("LWLock tranche names must be no longer than %d bytes.",
NAMEDATALEN - 1)));
- if (NamedLWLockTrancheRequestArray == NULL)
+ if (LocalNamedLWLockTrancheRequestArray == NULL)
{
NamedLWLockTrancheRequestsAllocated = 16;
- NamedLWLockTrancheRequestArray = (NamedLWLockTrancheRequest *)
+ LocalNamedLWLockTrancheRequestArray = (NamedLWLockTrancheRequest *)
MemoryContextAlloc(TopMemoryContext,
NamedLWLockTrancheRequestsAllocated
* sizeof(NamedLWLockTrancheRequest));
@@ -661,13 +663,13 @@ RequestNamedLWLockTranche(const char *tranche_name, int num_lwlocks)
{
int i = pg_nextpower2_32(NamedLWLockTrancheRequests + 1);
- NamedLWLockTrancheRequestArray = (NamedLWLockTrancheRequest *)
- repalloc(NamedLWLockTrancheRequestArray,
+ LocalNamedLWLockTrancheRequestArray = (NamedLWLockTrancheRequest *)
+ repalloc(LocalNamedLWLockTrancheRequestArray,
i * sizeof(NamedLWLockTrancheRequest));
NamedLWLockTrancheRequestsAllocated = i;
}
- request = &NamedLWLockTrancheRequestArray[NamedLWLockTrancheRequests];
+ request = &LocalNamedLWLockTrancheRequestArray[NamedLWLockTrancheRequests];
strlcpy(request->tranche_name, tranche_name, NAMEDATALEN);
request->num_lwlocks = num_lwlocks;
NamedLWLockTrancheRequests++;
--
2.39.5 (Apple Git-154)
--90DLrh6oh+Wqjmvg--
^ permalink raw reply [nested|flat] 8+ messages in thread
* [PATCH v2 1/1] fix LWLock shmem reinitialization
@ 2025-09-17 03:11 Nathan Bossart <nathan@postgresql.org>
0 siblings, 0 replies; 8+ messages in thread
From: Nathan Bossart @ 2025-09-17 03:11 UTC (permalink / raw)
---
src/backend/storage/lmgr/lwlock.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
inline patch 1: src/backend/storage/lmgr/lwlock.c (+7/-1 lines) download inline-1.patch
diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c
index 46c82c63ca5..626f0fbdac1 100644
--- a/src/backend/storage/lmgr/lwlock.c
+++ b/src/backend/storage/lmgr/lwlock.c
@@ -192,6 +192,9 @@ typedef struct NamedLWLockTrancheRequest
int NamedLWLockTrancheRequests = 0;
NamedLWLockTrancheRequest *NamedLWLockTrancheRequestArray = NULL;
+/* postmaster's local copy of the request array */
+static NamedLWLockTrancheRequest *LocalNamedLWLockTrancheRequestArray;
+
/* shared memory counter of registered tranches */
int *LWLockCounter = NULL;
@@ -396,6 +399,9 @@ LWLockShmemSize(void)
Size size;
int numLocks = NUM_FIXED_LWLOCKS;
+ if (LocalNamedLWLockTrancheRequestArray)
+ NamedLWLockTrancheRequestArray = LocalNamedLWLockTrancheRequestArray;
+
/* Calculate total number of locks needed in the main array. */
numLocks += NumLWLocksForNamedTranches();
@@ -459,7 +465,7 @@ CreateLWLocks(void)
{
memcpy(ptr, NamedLWLockTrancheRequestArray,
NamedLWLockTrancheRequests * sizeof(NamedLWLockTrancheRequest));
- pfree(NamedLWLockTrancheRequestArray);
+ LocalNamedLWLockTrancheRequestArray = NamedLWLockTrancheRequestArray;
NamedLWLockTrancheRequestArray = (NamedLWLockTrancheRequest *) ptr;
ptr += NamedLWLockTrancheRequests * sizeof(NamedLWLockTrancheRequest);
}
--
2.39.5 (Apple Git-154)
--U22hRdN7XmUh2Va9--
^ permalink raw reply [nested|flat] 8+ messages in thread
end of thread, other threads:[~2025-09-17 03:11 UTC | newest]
Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-03-10 18:52 pgsql: Ensure COPY TO on an RLS-enabled table copies no more than it sh Tom Lane <tgl@sss.pgh.pa.us>
2023-03-10 18:52 pgsql: Ensure COPY TO on an RLS-enabled table copies no more than it sh Tom Lane <tgl@sss.pgh.pa.us>
2023-03-10 18:52 pgsql: Ensure COPY TO on an RLS-enabled table copies no more than it sh Tom Lane <tgl@sss.pgh.pa.us>
2023-03-10 18:52 pgsql: Ensure COPY TO on an RLS-enabled table copies no more than it sh Tom Lane <tgl@sss.pgh.pa.us>
2023-03-10 18:52 pgsql: Ensure COPY TO on an RLS-enabled table copies no more than it sh Tom Lane <tgl@sss.pgh.pa.us>
2023-03-10 18:52 pgsql: Ensure COPY TO on an RLS-enabled table copies no more than it sh Tom Lane <tgl@sss.pgh.pa.us>
2025-09-17 03:11 [PATCH v1 1/1] fix LWLock shmem reinitialization Nathan Bossart <nathan@postgresql.org>
2025-09-17 03:11 [PATCH v2 1/1] fix LWLock shmem reinitialization Nathan Bossart <nathan@postgresql.org>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox