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

Commit 11da970

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 e078fb5 commit 11da970

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

src/backend/replication/libpqwalreceiver/libpqwalreceiver.c

+17
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

+6
Original file line numberDiff line numberDiff line change
@@ -2019,6 +2019,12 @@ ApplyWorkerMain(Datum main_arg)
20192019
MyLogicalRepWorker->userid,
20202020
0);
20212021

2022+
/*
2023+
* Set always-secure search path, so malicious users can't redirect user
2024+
* code (e.g. pg_index.indexprs).
2025+
*/
2026+
SetConfigOption("search_path", "", PGC_SUSET, PGC_S_OVERRIDE);
2027+
20222028
/* Load the subscription into persistent memory context. */
20232029
ApplyContext = AllocSetContextCreate(TopMemoryContext,
20242030
"ApplyContext",

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

+4
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)