Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 412c5c4

Browse files
committed
Empty search_path in logical replication apply worker and walsender.
This is like CVE-2018-1058 commit 582edc3. Today, a malicious user of a publisher or subscriber database can invoke arbitrary SQL functions under an identity running replication, often a superuser. This fix may cause "does not exist" or "no schema has been selected to create in" errors in a replication process. After upgrading, consider watching server logs for these errors. Objects accruing schema qualification in the wake of the earlier commit are unlikely to need further correction. Back-patch to v10, which introduced logical replication. Security: CVE-2020-14349
1 parent 41dae35 commit 412c5c4

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

src/backend/replication/libpqwalreceiver/libpqwalreceiver.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include "access/xlog.h"
2323
#include "catalog/pg_type.h"
24+
#include "common/connect.h"
2425
#include "funcapi.h"
2526
#include "libpq-fe.h"
2627
#include "mb/pg_wchar.h"
@@ -213,6 +214,22 @@ libpqrcv_connect(const char *conninfo, bool logical, const char *appname,
213214
return NULL;
214215
}
215216

217+
if (logical)
218+
{
219+
PGresult *res;
220+
221+
res = libpqrcv_PQexec(conn->streamConn,
222+
ALWAYS_SECURE_SEARCH_PATH_SQL);
223+
if (PQresultStatus(res) != PGRES_TUPLES_OK)
224+
{
225+
PQclear(res);
226+
ereport(ERROR,
227+
(errmsg("could not clear search path: %s",
228+
pchomp(PQerrorMessage(conn->streamConn)))));
229+
}
230+
PQclear(res);
231+
}
232+
216233
conn->logical = logical;
217234

218235
return conn;

src/backend/replication/logical/worker.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,6 +1988,12 @@ ApplyWorkerMain(Datum main_arg)
19881988
MyLogicalRepWorker->userid,
19891989
0);
19901990

1991+
/*
1992+
* Set always-secure search path, so malicious users can't redirect user
1993+
* code (e.g. pg_index.indexprs).
1994+
*/
1995+
SetConfigOption("search_path", "", PGC_SUSET, PGC_S_OVERRIDE);
1996+
19911997
/* Load the subscription into persistent memory context. */
19921998
ApplyContext = AllocSetContextCreate(TopMemoryContext,
19931999
"ApplyContext",

src/test/subscription/t/001_rep_changes.pl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
$node_subscriber->start;
1717

1818
# Create some preexisting content on publisher
19+
$node_publisher->safe_psql(
20+
'postgres',
21+
"CREATE FUNCTION public.pg_get_replica_identity_index(int)
22+
RETURNS regclass LANGUAGE sql AS 'SELECT 1/0'"); # shall not call
1923
$node_publisher->safe_psql('postgres',
2024
"CREATE TABLE tab_notrep AS SELECT generate_series(1,10) AS a");
2125
$node_publisher->safe_psql('postgres',

0 commit comments

Comments
 (0)