pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: dblink: Refuse to use a connection that a dblink call is already
4+ messages / 1 participants
[nested] [flat]

* pgsql: dblink: Refuse to use a connection that a dblink call is already
@ 2026-11-09 14:21  Noah Misch <noah@leadboat.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Noah Misch @ 2026-11-09 14:21 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

dblink: Refuse to use a connection that a dblink call is already using.

Previously, a dblink query that returned rows kept using its
connection after handing each row to the declared column type's input
function. That input function can run user-defined code (e.g., a
domain type with a CHECK constraint), so SQL can re-enter dblink while
an outer call is still reading results, and close the connection that
call is reading from. The close freed the connection object while the
outer call held a pointer to it, so the next libpq call read and wrote
freed memory.

dblink never had a rule about reentrancy. Calls that issued a new
query failed on their own, but by accident rather than by design:
libpq rejects a new query while one is in progress. It doesn't reject
reading a result, so a reentrant dblink_get_result() consumed a row
out of the outer query's single-row stream.

Fix this by marking a connection while a dblink call is materializing
a result from it, and refusing every other dblink call on that
connection until it's done.

Backpatch to all supported branches.

Reported-by: 안지용 <jfdg1y76@gmail.com>
Reviewed-by: Jacob Champion <champion.p@gmail.com>
Reviewed-by: Greg Burd <greg@burd.me>
Backpatch-through: 14
Security: CVE-2026-120147

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/abe3b910a12e594c4968e983602070c94a0c872b
Author: Masahiko Sawada <msawada@postgresql.org>

Modified Files
--------------
contrib/dblink/dblink.c            | 327 +++++++++++++++++++++++++------------
contrib/dblink/expected/dblink.out | 162 ++++++++++++++++++
contrib/dblink/sql/dblink.sql      |  78 +++++++++
3 files changed, 465 insertions(+), 102 deletions(-)



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

* pgsql: dblink: Refuse to use a connection that a dblink call is already
@ 2026-11-09 14:21  Noah Misch <noah@leadboat.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Noah Misch @ 2026-11-09 14:21 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

dblink: Refuse to use a connection that a dblink call is already using.

Previously, a dblink query that returned rows kept using its
connection after handing each row to the declared column type's input
function. That input function can run user-defined code (e.g., a
domain type with a CHECK constraint), so SQL can re-enter dblink while
an outer call is still reading results, and close the connection that
call is reading from. The close freed the connection object while the
outer call held a pointer to it, so the next libpq call read and wrote
freed memory.

dblink never had a rule about reentrancy. Calls that issued a new
query failed on their own, but by accident rather than by design:
libpq rejects a new query while one is in progress. It doesn't reject
reading a result, so a reentrant dblink_get_result() consumed a row
out of the outer query's single-row stream.

Fix this by marking a connection while a dblink call is materializing
a result from it, and refusing every other dblink call on that
connection until it's done.

Backpatch to all supported branches.

Reported-by: 안지용 <jfdg1y76@gmail.com>
Reviewed-by: Jacob Champion <champion.p@gmail.com>
Reviewed-by: Greg Burd <greg@burd.me>
Backpatch-through: 14
Security: CVE-2026-120147

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/2fe5aa626d6168ad2531245ac06bf7a0c90a0502
Author: Masahiko Sawada <msawada@postgresql.org>

Modified Files
--------------
contrib/dblink/dblink.c            | 327 +++++++++++++++++++++++++------------
contrib/dblink/expected/dblink.out | 162 ++++++++++++++++++
contrib/dblink/sql/dblink.sql      |  78 +++++++++
3 files changed, 465 insertions(+), 102 deletions(-)



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

* pgsql: dblink: Refuse to use a connection that a dblink call is already
@ 2026-11-09 14:21  Noah Misch <noah@leadboat.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Noah Misch @ 2026-11-09 14:21 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

dblink: Refuse to use a connection that a dblink call is already using.

Previously, a dblink query that returned rows kept using its
connection after handing each row to the declared column type's input
function. That input function can run user-defined code (e.g., a
domain type with a CHECK constraint), so SQL can re-enter dblink while
an outer call is still reading results, and close the connection that
call is reading from. The close freed the connection object while the
outer call held a pointer to it, so the next libpq call read and wrote
freed memory.

dblink never had a rule about reentrancy. Calls that issued a new
query failed on their own, but by accident rather than by design:
libpq rejects a new query while one is in progress. It doesn't reject
reading a result, so a reentrant dblink_get_result() consumed a row
out of the outer query's single-row stream.

Fix this by marking a connection while a dblink call is materializing
a result from it, and refusing every other dblink call on that
connection until it's done.

Backpatch to all supported branches.

Reported-by: 안지용 <jfdg1y76@gmail.com>
Reviewed-by: Jacob Champion <champion.p@gmail.com>
Reviewed-by: Greg Burd <greg@burd.me>
Backpatch-through: 14
Security: CVE-2026-120147

Branch
------
REL_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/b8fbeeb7600778d05bbbe1e7ee81e4491b2116e6
Author: Masahiko Sawada <msawada@postgresql.org>

Modified Files
--------------
contrib/dblink/dblink.c            | 139 ++++++++++++++++++++++++++++---
contrib/dblink/expected/dblink.out | 162 +++++++++++++++++++++++++++++++++++++
contrib/dblink/sql/dblink.sql      |  78 ++++++++++++++++++
3 files changed, 367 insertions(+), 12 deletions(-)



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

* pgsql: dblink: Refuse to use a connection that a dblink call is already
@ 2026-11-09 14:22  Noah Misch <noah@leadboat.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Noah Misch @ 2026-11-09 14:22 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

dblink: Refuse to use a connection that a dblink call is already using.

Previously, a dblink query that returned rows kept using its
connection after handing each row to the declared column type's input
function. That input function can run user-defined code (e.g., a
domain type with a CHECK constraint), so SQL can re-enter dblink while
an outer call is still reading results, and close the connection that
call is reading from. The close freed the connection object while the
outer call held a pointer to it, so the next libpq call read and wrote
freed memory.

dblink never had a rule about reentrancy. Calls that issued a new
query failed on their own, but by accident rather than by design:
libpq rejects a new query while one is in progress. It doesn't reject
reading a result, so a reentrant dblink_get_result() consumed a row
out of the outer query's single-row stream.

Fix this by marking a connection while a dblink call is materializing
a result from it, and refusing every other dblink call on that
connection until it's done.

Backpatch to all supported branches.

Reported-by: 안지용 <jfdg1y76@gmail.com>
Reviewed-by: Jacob Champion <champion.p@gmail.com>
Reviewed-by: Greg Burd <greg@burd.me>
Backpatch-through: 14
Security: CVE-2026-120147

Branch
------
REL_14_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/887f6fee58f46c93bec66d0f449a579e314552ae
Author: Masahiko Sawada <msawada@postgresql.org>

Modified Files
--------------
contrib/dblink/dblink.c            | 140 ++++++++++++++++++++++++++++---
contrib/dblink/expected/dblink.out | 167 +++++++++++++++++++++++++++++++++++++
contrib/dblink/sql/dblink.sql      |  83 ++++++++++++++++++
3 files changed, 378 insertions(+), 12 deletions(-)



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


end of thread, other threads:[~2026-11-09 14:22 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-11-09 14:21 pgsql: dblink: Refuse to use a connection that a dblink call is already Noah Misch <noah@leadboat.com>
2026-11-09 14:21 pgsql: dblink: Refuse to use a connection that a dblink call is already Noah Misch <noah@leadboat.com>
2026-11-09 14:21 pgsql: dblink: Refuse to use a connection that a dblink call is already Noah Misch <noah@leadboat.com>
2026-11-09 14:22 pgsql: dblink: Refuse to use a connection that a dblink call is already Noah Misch <noah@leadboat.com>

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