pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #15116: pg_recvlogical always fails
8+ messages / 4 participants
[nested] [flat]

* BUG #15116: pg_recvlogical always fails
@ 2018-03-16 15:34 PG Bug reporting form <noreply@postgresql.org>
  2018-03-16 22:37 ` Re: BUG #15116: pg_recvlogical always fails Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  0 siblings, 1 reply; 8+ messages in thread

From: PG Bug reporting form @ 2018-03-16 15:34 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: kotlarski.krzysztof@gmail.com

The following bug has been logged on the website:

Bug reference:      15116
Logged by:          Krzysztof Kotlarski
Email address:      kotlarski.krzysztof@gmail.com
PostgreSQL version: 9.6.8
Operating system:   Linux
Description:        

When run with correct arguments (working in previous versions)
pg_recvlogical always fails with: 

pg_recvlogical: could not clear search_path: ERROR:  syntax error

I suspect it's trying to execute ALWAYS_SECURE_SEARCH_PATH_SQL on
replication connection which is nonSQL.



^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: BUG #15116: pg_recvlogical always fails
  2018-03-16 15:34 BUG #15116: pg_recvlogical always fails PG Bug reporting form <noreply@postgresql.org>
@ 2018-03-16 22:37 ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  2018-03-17 00:20   ` Re: BUG #15116: pg_recvlogical always fails Michael Paquier <michael@paquier.xyz>
  0 siblings, 1 reply; 8+ messages in thread

From: Peter Eisentraut @ 2018-03-16 22:37 UTC (permalink / raw)
  To: kotlarski.krzysztof@gmail.com; pgsql-bugs@lists.postgresql.org

On 3/16/18 11:34, PG Bug reporting form wrote:
> When run with correct arguments (working in previous versions)
> pg_recvlogical always fails with: 
> 
> pg_recvlogical: could not clear search_path: ERROR:  syntax error
> 
> I suspect it's trying to execute ALWAYS_SECURE_SEARCH_PATH_SQL on
> replication connection which is nonSQL.

I can confirm this problem.

I have copied the 030_pg_recvlogical.pl test from 10 into 9.6 to produce
a test failure with that same error message.

Haven't looked further yet.

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services




^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: BUG #15116: pg_recvlogical always fails
  2018-03-16 15:34 BUG #15116: pg_recvlogical always fails PG Bug reporting form <noreply@postgresql.org>
  2018-03-16 22:37 ` Re: BUG #15116: pg_recvlogical always fails Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
@ 2018-03-17 00:20   ` Michael Paquier <michael@paquier.xyz>
  2018-03-17 00:32     ` Re: BUG #15116: pg_recvlogical always fails Michael Paquier <michael@paquier.xyz>
  0 siblings, 1 reply; 8+ messages in thread

From: Michael Paquier @ 2018-03-17 00:20 UTC (permalink / raw)
  To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; +Cc: kotlarski.krzysztof@gmail.com; pgsql-bugs@lists.postgresql.org

On Fri, Mar 16, 2018 at 06:37:04PM -0400, Peter Eisentraut wrote:
> I can confirm this problem.

At least slot creation fails.  One just needs to start up an instance
and run that for example:
$ pg_recvlogical --create-slot -S popo -d "dbname=postgres"
pg_recvlogical: could not clear search_path: ERROR:  syntax erro
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: BUG #15116: pg_recvlogical always fails
  2018-03-16 15:34 BUG #15116: pg_recvlogical always fails PG Bug reporting form <noreply@postgresql.org>
  2018-03-16 22:37 ` Re: BUG #15116: pg_recvlogical always fails Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  2018-03-17 00:20   ` Re: BUG #15116: pg_recvlogical always fails Michael Paquier <michael@paquier.xyz>
@ 2018-03-17 00:32     ` Michael Paquier <michael@paquier.xyz>
  2018-03-17 17:33       ` Re: BUG #15116: pg_recvlogical always fails Magnus Hagander <magnus@hagander.net>
  0 siblings, 1 reply; 8+ messages in thread

From: Michael Paquier @ 2018-03-17 00:32 UTC (permalink / raw)
  To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; +Cc: kotlarski.krzysztof@gmail.com; pgsql-bugs@lists.postgresql.org

On Sat, Mar 17, 2018 at 09:20:26AM +0900, Michael Paquier wrote:
> At least slot creation fails.  One just needs to start up an instance
> and run that for example:
> $ pg_recvlogical --create-slot -S popo -d "dbname=postgres"
> pg_recvlogical: could not clear search_path: ERROR:  syntax erro

The issue is that support for plain SQL queries has been added in
PostgreSQL 10 for logical replication connections, however e170b8c8 has
missed the fact that this is not supported for older versions.  Hence,
two things need to happen as pg_recvlogical needs to be kept compatible
with past server versions:
1) Make the check deciding if search_path should be enforced smarter by
checking if the server version is newer than 10.  This needs to be
patched on HEAD and REL_10_STABLE.  recvlogical-search-path-fix.patch
does so.
2) Simply remove the check on past branches, as I recall that we
maintain downstream compatibility, but do not for example guarantee that
a Postgres 10 server would work with a 9.6's pg_recvlogical. This is
what recvlogical-search-path-fix-96.patch attached does.

Thanks,
--
Michael

Attachments: download all (3 files, .tar.gz)

recvlogical-search-path-fix.patch (text/x-diff, 685B) download diff --git a/src/bin/pg_basebackup/streamutil.c b/src/bin/pg_basebackup/streamutil.c index 296b1888aa..79a1a0bdca 100644 --- a/src/bin/pg_basebackup/streamutil.c +++ b/src/bin/pg_basebackup/streamutil.c @@ -209,8 +209,12 @@ GetConnection(void) if (conn_opts) PQconninfoFree(conn_opts); - /* Set always-secure search path, so malicious users can't get control. */ - if (dbname != NULL) + /* + * Set always-secure search path, so malicious users can't get control. + * The capacity to run normal SQL queries has been added in PostgreSQL + * 10, so this does not matter for older versions. + */ + if (dbname != NULL && PQserverVersion(conn) >= 100000) { PGresult *res;
recvlogical-search-path-fix-96.patch (text/x-diff, 817B) download diff --git a/src/bin/pg_basebackup/streamutil.c b/src/bin/pg_basebackup/streamutil.c index aa14dbbb75..3f3f2633ae 100644 --- a/src/bin/pg_basebackup/streamutil.c +++ b/src/bin/pg_basebackup/streamutil.c @@ -209,23 +209,6 @@ GetConnection(void) if (conn_opts) PQconninfoFree(conn_opts); - /* Set always-secure search path, so malicious users can't get control. */ - if (dbname != NULL) - { - PGresult *res; - - res = PQexec(tmpconn, ALWAYS_SECURE_SEARCH_PATH_SQL); - if (PQresultStatus(res) != PGRES_TUPLES_OK) - { - fprintf(stderr, _("%s: could not clear search_path: %s\n"), - progname, PQerrorMessage(tmpconn)); - PQclear(res); - PQfinish(tmpconn); - exit(1); - } - PQclear(res); - } - /* * Ensure we have the same value of integer timestamps as the server we * are connecting to.
signature.asc (application/pgp-signature, 832B) download ^ permalink raw reply [nested|flat] 8+ messages in thread

* Re: BUG #15116: pg_recvlogical always fails
  2018-03-16 15:34 BUG #15116: pg_recvlogical always fails PG Bug reporting form <noreply@postgresql.org>
  2018-03-16 22:37 ` Re: BUG #15116: pg_recvlogical always fails Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  2018-03-17 00:20   ` Re: BUG #15116: pg_recvlogical always fails Michael Paquier <michael@paquier.xyz>
  2018-03-17 00:32     ` Re: BUG #15116: pg_recvlogical always fails Michael Paquier <michael@paquier.xyz>
@ 2018-03-17 17:33       ` Magnus Hagander <magnus@hagander.net>
  2018-03-17 23:02         ` Re: BUG #15116: pg_recvlogical always fails Michael Paquier <michael@paquier.xyz>
  0 siblings, 1 reply; 8+ messages in thread

From: Magnus Hagander @ 2018-03-17 17:33 UTC (permalink / raw)
  To: Michael Paquier <michael@paquier.xyz>; +Cc: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; kotlarski.krzysztof@gmail.com; pgsql-bugs@lists.postgresql.org

On Sat, Mar 17, 2018 at 1:32 AM, Michael Paquier <michael@paquier.xyz>
wrote:

> On Sat, Mar 17, 2018 at 09:20:26AM +0900, Michael Paquier wrote:
> > At least slot creation fails.  One just needs to start up an instance
> > and run that for example:
> > $ pg_recvlogical --create-slot -S popo -d "dbname=postgres"
> > pg_recvlogical: could not clear search_path: ERROR:  syntax erro
>
> The issue is that support for plain SQL queries has been added in
> PostgreSQL 10 for logical replication connections, however e170b8c8 has
> missed the fact that this is not supported for older versions.  Hence,
> two things need to happen as pg_recvlogical needs to be kept compatible
> with past server versions:
> 1) Make the check deciding if search_path should be enforced smarter by
> checking if the server version is newer than 10.  This needs to be
> patched on HEAD and REL_10_STABLE.  recvlogical-search-path-fix.patch
> does so.
>

This looks like the correct fix.



> 2) Simply remove the check on past branches, as I recall that we
> maintain downstream compatibility, but do not for example guarantee that
> a Postgres 10 server would work with a 9.6's pg_recvlogical. This is
> what recvlogical-search-path-fix-96.patch attached does.
>

In this scenario, since we don't actively *enforce* this version
difference, I think we should apply the fix from #1 in this scenario as
well. Otherwise you might use an old pg_recvlogical to connect to a newer
server, and open up a vulnerability somehow. I assume pg_recvlogical of
that age doesn't actually try to do something with it, but it still feels
safer for the future.

Is there any particular reason why doing #1 would not work on the older
branches?

-- 
 Magnus Hagander
 Me: https://www.hagander.net/ <http://www.hagander.net/;
 Work: https://www.redpill-linpro.com/ <http://www.redpill-linpro.com/;

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: BUG #15116: pg_recvlogical always fails
  2018-03-16 15:34 BUG #15116: pg_recvlogical always fails PG Bug reporting form <noreply@postgresql.org>
  2018-03-16 22:37 ` Re: BUG #15116: pg_recvlogical always fails Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  2018-03-17 00:20   ` Re: BUG #15116: pg_recvlogical always fails Michael Paquier <michael@paquier.xyz>
  2018-03-17 00:32     ` Re: BUG #15116: pg_recvlogical always fails Michael Paquier <michael@paquier.xyz>
  2018-03-17 17:33       ` Re: BUG #15116: pg_recvlogical always fails Magnus Hagander <magnus@hagander.net>
@ 2018-03-17 23:02         ` Michael Paquier <michael@paquier.xyz>
  2018-03-18 12:13           ` Re: BUG #15116: pg_recvlogical always fails Magnus Hagander <magnus@hagander.net>
  0 siblings, 1 reply; 8+ messages in thread

From: Michael Paquier @ 2018-03-17 23:02 UTC (permalink / raw)
  To: Magnus Hagander <magnus@hagander.net>; +Cc: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; kotlarski.krzysztof@gmail.com; pgsql-bugs@lists.postgresql.org

On Sat, Mar 17, 2018 at 06:33:48PM +0100, Magnus Hagander wrote:
> In this scenario, since we don't actively *enforce* this version
> difference, I think we should apply the fix from #1 in this scenario as
> well. Otherwise you might use an old pg_recvlogical to connect to a newer
> server, and open up a vulnerability somehow. I assume pg_recvlogical of
> that age doesn't actually try to do something with it, but it still feels
> safer for the future.

Yeah, there is no actual reason to not apply #1 everywhere as well.  The
back-patch is a no-brainer.
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: BUG #15116: pg_recvlogical always fails
  2018-03-16 15:34 BUG #15116: pg_recvlogical always fails PG Bug reporting form <noreply@postgresql.org>
  2018-03-16 22:37 ` Re: BUG #15116: pg_recvlogical always fails Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  2018-03-17 00:20   ` Re: BUG #15116: pg_recvlogical always fails Michael Paquier <michael@paquier.xyz>
  2018-03-17 00:32     ` Re: BUG #15116: pg_recvlogical always fails Michael Paquier <michael@paquier.xyz>
  2018-03-17 17:33       ` Re: BUG #15116: pg_recvlogical always fails Magnus Hagander <magnus@hagander.net>
  2018-03-17 23:02         ` Re: BUG #15116: pg_recvlogical always fails Michael Paquier <michael@paquier.xyz>
@ 2018-03-18 12:13           ` Magnus Hagander <magnus@hagander.net>
  2018-03-18 13:49             ` Re: BUG #15116: pg_recvlogical always fails Michael Paquier <michael@paquier.xyz>
  0 siblings, 1 reply; 8+ messages in thread

From: Magnus Hagander @ 2018-03-18 12:13 UTC (permalink / raw)
  To: Michael Paquier <michael@paquier.xyz>; +Cc: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; kotlarski.krzysztof@gmail.com; pgsql-bugs@lists.postgresql.org

On Sun, Mar 18, 2018 at 12:02 AM, Michael Paquier <michael@paquier.xyz>
wrote:

> On Sat, Mar 17, 2018 at 06:33:48PM +0100, Magnus Hagander wrote:
> > In this scenario, since we don't actively *enforce* this version
> > difference, I think we should apply the fix from #1 in this scenario as
> > well. Otherwise you might use an old pg_recvlogical to connect to a newer
> > server, and open up a vulnerability somehow. I assume pg_recvlogical of
> > that age doesn't actually try to do something with it, but it still feels
> > safer for the future.
>
> Yeah, there is no actual reason to not apply #1 everywhere as well.  The
> back-patch is a no-brainer.
>

Applied that way with minor adjustments to the comment.


-- 
 Magnus Hagander
 Me: https://www.hagander.net/ <http://www.hagander.net/;
 Work: https://www.redpill-linpro.com/ <http://www.redpill-linpro.com/;

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: BUG #15116: pg_recvlogical always fails
  2018-03-16 15:34 BUG #15116: pg_recvlogical always fails PG Bug reporting form <noreply@postgresql.org>
  2018-03-16 22:37 ` Re: BUG #15116: pg_recvlogical always fails Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  2018-03-17 00:20   ` Re: BUG #15116: pg_recvlogical always fails Michael Paquier <michael@paquier.xyz>
  2018-03-17 00:32     ` Re: BUG #15116: pg_recvlogical always fails Michael Paquier <michael@paquier.xyz>
  2018-03-17 17:33       ` Re: BUG #15116: pg_recvlogical always fails Magnus Hagander <magnus@hagander.net>
  2018-03-17 23:02         ` Re: BUG #15116: pg_recvlogical always fails Michael Paquier <michael@paquier.xyz>
  2018-03-18 12:13           ` Re: BUG #15116: pg_recvlogical always fails Magnus Hagander <magnus@hagander.net>
@ 2018-03-18 13:49             ` Michael Paquier <michael@paquier.xyz>
  0 siblings, 0 replies; 8+ messages in thread

From: Michael Paquier @ 2018-03-18 13:49 UTC (permalink / raw)
  To: Magnus Hagander <magnus@hagander.net>; +Cc: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; kotlarski.krzysztof@gmail.com; pgsql-bugs@lists.postgresql.org

On Sun, Mar 18, 2018 at 01:13:48PM +0100, Magnus Hagander wrote:
> Applied that way with minor adjustments to the comment.

Thanks, Magnus.
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 8+ messages in thread


end of thread, other threads:[~2018-03-18 13:49 UTC | newest]

Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-03-16 15:34 BUG #15116: pg_recvlogical always fails PG Bug reporting form <noreply@postgresql.org>
2018-03-16 22:37 ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2018-03-17 00:20   ` Michael Paquier <michael@paquier.xyz>
2018-03-17 00:32     ` Michael Paquier <michael@paquier.xyz>
2018-03-17 17:33       ` Magnus Hagander <magnus@hagander.net>
2018-03-17 23:02         ` Michael Paquier <michael@paquier.xyz>
2018-03-18 12:13           ` Magnus Hagander <magnus@hagander.net>
2018-03-18 13:49             ` Michael Paquier <michael@paquier.xyz>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox