Skip to content

Commit b403f41

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 54d4a8f commit b403f41

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
@@ -8982,7 +8982,7 @@ do_pg_start_backup(const char *backupidstr, bool fast, char **labelfile)
89828982
FILE *fp;
89838983
StringInfoData labelfbuf;
89848984

8985-
if (!superuser() && !is_authenticated_user_replication_role())
8985+
if (!superuser() && !has_rolreplication(GetUserId()))
89868986
ereport(ERROR,
89878987
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
89888988
errmsg("must be superuser or replication role to run a backup")));
@@ -9261,7 +9261,7 @@ do_pg_stop_backup(char *labelfile, bool waitforarchive)
92619261
bool reported_waiting = false;
92629262
char *remaining;
92639263

9264-
if (!superuser() && !is_authenticated_user_replication_role())
9264+
if (!superuser() && !has_rolreplication(GetUserId()))
92659265
ereport(ERROR,
92669266
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
92679267
(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
@@ -669,7 +669,7 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username,
669669
Assert(!bootstrap);
670670

671671
/* must have authenticated as a replication role */
672-
if (!is_authenticated_user_replication_role())
672+
if (!has_rolreplication(GetUserId()))
673673
ereport(FATAL,
674674
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
675675
errmsg("must be replication role to start walsender")));

src/include/miscadmin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ extern void ValidatePgVersion(const char *path);
395395
extern void process_shared_preload_libraries(void);
396396
extern void process_local_preload_libraries(void);
397397
extern void pg_bindtextdomain(const char *domain);
398-
extern bool is_authenticated_user_replication_role(void);
398+
extern bool has_rolreplication(Oid roleid);
399399

400400
/* in access/transam/xlog.c */
401401
extern bool BackupInProgress(void);

0 commit comments

Comments
 (0)