Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf0b051e

Browse files
committed
Allow GRANT on pg_log_backend_memory_contexts().
Remove superuser check, allowing any user granted permissions onpg_log_backend_memory_contexts() to log the memory contexts of anybackend.Note that this could allow a privileged non-superuser to log thememory contexts of a superuser backend, but as discussed, that doesnot seem to be a problem.Reviewed-by: Nathan Bossart, Bharath Rupireddy, Michael Paquier, Kyotaro Horiguchi, Andres FreundDiscussion:https://postgr.es/m/e5cf6684d17c8d1ef4904ae248605ccd6da03e72.camel@j-davis.com
1 parent5fedf74 commitf0b051e

File tree

6 files changed

+62
-16
lines changed

6 files changed

+62
-16
lines changed

‎doc/src/sgml/func.sgml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25332,7 +25332,6 @@ SELECT collation for ('foo' COLLATE "de_DE");
2533225332
(See <xref linkend="runtime-config-logging"/> for more information),
2533325333
but will not be sent to the client regardless of
2533425334
<xref linkend="guc-client-min-messages"/>.
25335-
Only superusers can request to log the memory contexts.
2533625335
</para></entry>
2533725336
</row>
2533825337

‎src/backend/catalog/system_functions.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,8 @@ REVOKE EXECUTE ON FUNCTION pg_ls_dir(text) FROM public;
699699

700700
REVOKE EXECUTEON FUNCTION pg_ls_dir(text,boolean,boolean)FROM public;
701701

702+
REVOKE EXECUTEON FUNCTION pg_log_backend_memory_contexts(integer)FROM PUBLIC;
703+
702704
--
703705
-- We also set up some things as accessible to standard roles.
704706
--

‎src/backend/utils/adt/mcxtfuncs.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,10 @@ pg_get_backend_memory_contexts(PG_FUNCTION_ARGS)
162162
* pg_log_backend_memory_contexts
163163
*Signal a backend process to log its memory contexts.
164164
*
165-
*Onlysuperusers are allowed to signal to log the memory contexts
166-
* because allowing any users to issue this request at an unbounded
167-
* rate would cause lots of log messages and which can lead to
168-
*denial of service.
165+
*By default, onlysuperusers are allowed to signal to log the memory
166+
*contextsbecause allowing any users to issue this request at an unbounded
167+
* rate would cause lots of log messages and which can lead to denial of
168+
*service. Additional roles can be permitted with GRANT.
169169
*
170170
* On receipt of this signal, a backend sets the flag in the signal
171171
* handler, which causes the next CHECK_FOR_INTERRUPTS() to log the
@@ -177,12 +177,6 @@ pg_log_backend_memory_contexts(PG_FUNCTION_ARGS)
177177
intpid=PG_GETARG_INT32(0);
178178
PGPROC*proc;
179179

180-
/* Only allow superusers to log memory contexts. */
181-
if (!superuser())
182-
ereport(ERROR,
183-
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
184-
errmsg("must be a superuser to log memory contexts")));
185-
186180
proc=BackendPidGetProc(pid);
187181

188182
/*

‎src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO202109101
56+
#defineCATALOG_VERSION_NO202110260
5757

5858
#endif

‎src/test/regress/expected/misc_functions.out

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,43 @@ HINT: No function matches the given name and argument types. You might need to
138138
--
139139
-- Memory contexts are logged and they are not returned to the function.
140140
-- Furthermore, their contents can vary depending on the timing. However,
141-
-- we can at least verify that the code doesn't fail.
141+
-- we can at least verify that the code doesn't fail, and that the
142+
-- permissions are set properly.
142143
--
143-
SELECT* FROMpg_log_backend_memory_contexts(pg_backend_pid());
144+
SELECT pg_log_backend_memory_contexts(pg_backend_pid());
144145
pg_log_backend_memory_contexts
145146
--------------------------------
146147
t
147148
(1 row)
148149

150+
CREATE ROLE regress_log_memory;
151+
SELECT has_function_privilege('regress_log_memory',
152+
'pg_log_backend_memory_contexts(integer)', 'EXECUTE'); -- no
153+
has_function_privilege
154+
------------------------
155+
f
156+
(1 row)
157+
158+
GRANT EXECUTE ON FUNCTION pg_log_backend_memory_contexts(integer)
159+
TO regress_log_memory;
160+
SELECT has_function_privilege('regress_log_memory',
161+
'pg_log_backend_memory_contexts(integer)', 'EXECUTE'); -- yes
162+
has_function_privilege
163+
------------------------
164+
t
165+
(1 row)
166+
167+
SET ROLE regress_log_memory;
168+
SELECT pg_log_backend_memory_contexts(pg_backend_pid());
169+
pg_log_backend_memory_contexts
170+
--------------------------------
171+
t
172+
(1 row)
173+
174+
RESET ROLE;
175+
REVOKE EXECUTE ON FUNCTION pg_log_backend_memory_contexts(integer)
176+
FROM regress_log_memory;
177+
DROP ROLE regress_log_memory;
149178
--
150179
-- Test some built-in SRFs
151180
--

‎src/test/regress/sql/misc_functions.sql

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,31 @@ SELECT num_nulls();
3535
--
3636
-- Memory contexts are logged and they are not returned to the function.
3737
-- Furthermore, their contents can vary depending on the timing. However,
38-
-- we can at least verify that the code doesn't fail.
38+
-- we can at least verify that the code doesn't fail, and that the
39+
-- permissions are set properly.
3940
--
40-
SELECT*FROM pg_log_backend_memory_contexts(pg_backend_pid());
41+
42+
SELECT pg_log_backend_memory_contexts(pg_backend_pid());
43+
44+
CREATE ROLE regress_log_memory;
45+
46+
SELECT has_function_privilege('regress_log_memory',
47+
'pg_log_backend_memory_contexts(integer)','EXECUTE');-- no
48+
49+
GRANT EXECUTEON FUNCTION pg_log_backend_memory_contexts(integer)
50+
TO regress_log_memory;
51+
52+
SELECT has_function_privilege('regress_log_memory',
53+
'pg_log_backend_memory_contexts(integer)','EXECUTE');-- yes
54+
55+
SET ROLE regress_log_memory;
56+
SELECT pg_log_backend_memory_contexts(pg_backend_pid());
57+
RESET ROLE;
58+
59+
REVOKE EXECUTEON FUNCTION pg_log_backend_memory_contexts(integer)
60+
FROM regress_log_memory;
61+
62+
DROP ROLE regress_log_memory;
4163

4264
--
4365
-- Test some built-in SRFs

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp