8000 Make REPLICATION privilege checks test current user not authenticated… · danielcode/postgres@e5fdb8f · GitHub
[go: up one dir, main page]

Skip to content

Commit e5fdb8f

Browse files
committed
Make REPLICATION privilege checks test current user not authenticated user.
The pg_start_backup() and pg_stop_backup() functions checked the privileges of the initially-authenticated user rather than the current user, which is wrong. For example, a user-defined index function could successfully call these functions when executed by ANALYZE within autovacuum. This could allow an attacker with valid but low-privilege database access to interfere with creation of routine backups. Reported and fixed by Noah Misch. Security: CVE-2013-1901
1 parent fe6b242 commit e5fdb8f

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

src/backend/access/transam/xlog.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9413,7 +9413,7 @@ do_pg_start_backup(const char *backupidstr, bool fast, char **labelfile)
94139413

94149414
backup_started_in_recovery = RecoveryInProgress();
94159415

9416-
if (!superuser() && !is_authenticated_user_replication_role())
9416+
if (!superuser() && !has_rolreplication(GetUserId()))
941794 10000 17
ereport(ERROR,
94189418
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
94199419
errmsg("must be superuser or replication role to run a backup")));
@@ -9743,7 +9743,7 @@ do_pg_stop_backup(char *labelfile, bool waitforarchive)
97439743

97449744
backup_started_in_recovery = RecoveryInProgress();
97459745

9746-
if (!superuser() && !is_authenticated_user_replication_role())
9746+
if (!superuser() && !has_rolreplication(GetUserId()))
97479747
ereport(ERROR,
97489748
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
97499749
(errmsg("must be superuser or replication role to run a backup"))));

src/backend/utils/init/miscinit.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,15 +389,15 @@ SetUserIdAndContext(Oid userid, bool sec_def_context)
389389

390390

391391
/*
392-
* Check if the authenticated user is a replication role
392+
* Check whether specified role has explicit REPLICATION privilege
393393
*/
394394
bool
395-
is_authenticated_user_replication_role(void)
395+
has_rolreplication(Oid roleid)
396396
{
397397
bool result = false;
398398
HeapTuple utup;
399399

400-
utup = SearchSysCache1(AUTHOID, ObjectIdGetDatum(AuthenticatedUserId));
400+
utup = SearchSysCache1(AUTHOID, ObjectIdGetDatum(roleid));
401401
if (HeapTupleIsValid(utup))
402402
{
403403
result = ((Form_pg_authid) GETSTRUCT(utup))->rolreplication;

src/backend/utils/init/postinit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username,
668668
{
669669
Assert(!bootstrap);
670670

671-
if (!superuser() && !is_authenticated_user_replication_role())
671+
if (!superuser() && !has_rolreplication(GetUserId()))
672672
ereport(FATAL,
673673
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
674674
errmsg("must be superuser or replication role to start walsender")));

src/include/miscadmin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ extern void ValidatePgVersion(const char *path);
436436
extern void process_shared_preload_libraries(void);
437437
extern void process_local_preload_libraries(void);
438438
extern void pg_bindtextdomain(const char *domain);
439-
extern bool is_authenticated_user_replication_role(void);
439+
extern bool has_rolreplication(Oid roleid);
440440

441441
/* in access/transam/xlog.c */
442442
extern bool BackupInProgress(void);

0 commit comments

Comments
 (0)
0