pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Fix use-after-free issues due to drop of portals being set up 4+ messages / 1 participants [nested] [flat]
* pgsql: Fix use-after-free issues due to drop of portals being set up @ 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 Fix use-after-free issues due to drop of portals being set up Between CreatePortal() and PortalStart(), a portal can run user-defined code due to planning and executor startup, like SQL functions. A function attempting to close a portal would free it, without its creator knowing about it. This could lead to use-after-free issues when trying to use portals that have already been closed. With this change, PortalDrop() now refuses to act on portals marked as PORTAL_NEW or PORTAL_DEFINED. CLOSE ALL skips them, as it does for active portals. Note that AtAbort_Portals() (for transaction aborts) and AtSubAbort_Portals() (for subtransaction aborts) now puts such portals in a failed state so as they can be cleaned up during error cleanup. Two sets of tests are added: - Portal manipulations during planning and executor startup. - Portals and Bind messages, relying on injection points to check various transaction cases with portals marked as either PORTAL_NEW or PORTAL_DEFINED, where the on-error cleanup of portals marked as failed matters. Reported-by: Tomas Vondra <tomas@vondra.me> Author: Michael Paquier <michael@paquier.xyz> Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Backpatch-through: 14 Security: CVE-2026-116332 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/5b23669ea3442961f56e2a057141d34763638257 Author: Michael Paquier <michael@paquier.xyz> Modified Files -------------- src/backend/tcop/postgres.c | 4 + src/backend/utils/mmgr/portalmem.c | 40 ++++++- src/test/modules/injection_points/Makefile | 2 +- .../injection_points/expected/portal_bind.out | 133 +++++++++++++++++++++ src/test/modules/injection_points/meson.build | 1 + .../modules/injection_points/sql/portal_bind.sql | 61 ++++++++++ src/test/regress/expected/portals_inflight.out | 127 ++++++++++++++++++++ src/test/regress/parallel_schedule | 2 +- src/test/regress/sql/portals_inflight.sql | 99 +++++++++++++++ 9 files changed, 463 insertions(+), 6 deletions(-) ^ permalink raw reply [nested|flat] 4+ messages in thread
* pgsql: Fix use-after-free issues due to drop of portals being set up @ 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 Fix use-after-free issues due to drop of portals being set up Between CreatePortal() and PortalStart(), a portal can run user-defined code due to planning and executor startup, like SQL functions. A function attempting to close a portal would free it, without its creator knowing about it. This could lead to use-after-free issues when trying to use portals that have already been closed. With this change, PortalDrop() now refuses to act on portals marked as PORTAL_NEW or PORTAL_DEFINED. CLOSE ALL skips them, as it does for active portals. Note that AtAbort_Portals() (for transaction aborts) and AtSubAbort_Portals() (for subtransaction aborts) now puts such portals in a failed state so as they can be cleaned up during error cleanup. Two sets of tests are added: - Portal manipulations during planning and executor startup. - Portals and Bind messages, relying on injection points to check various transaction cases with portals marked as either PORTAL_NEW or PORTAL_DEFINED, where the on-error cleanup of portals marked as failed matters. Reported-by: Tomas Vondra <tomas@vondra.me> Author: Michael Paquier <michael@paquier.xyz> Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Backpatch-through: 14 Security: CVE-2026-116332 Branch ------ REL_19_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/b63c8123e65ff5fefce076b5770cfc8581e04824 Author: Michael Paquier <michael@paquier.xyz> Modified Files -------------- src/backend/tcop/postgres.c | 4 + src/backend/utils/mmgr/portalmem.c | 40 ++++++- src/test/modules/injection_points/Makefile | 2 +- .../injection_points/expected/portal_bind.out | 133 +++++++++++++++++++++ src/test/modules/injection_points/meson.build | 1 + .../modules/injection_points/sql/portal_bind.sql | 61 ++++++++++ src/test/regress/expected/portals_inflight.out | 127 ++++++++++++++++++++ src/test/regress/parallel_schedule | 2 +- src/test/regress/sql/portals_inflight.sql | 99 +++++++++++++++ 9 files changed, 463 insertions(+), 6 deletions(-) ^ permalink raw reply [nested|flat] 4+ messages in thread
* pgsql: Fix use-after-free issues due to drop of portals being set up @ 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 Fix use-after-free issues due to drop of portals being set up Between CreatePortal() and PortalStart(), a portal can run user-defined code due to planning and executor startup, like SQL functions. A function attempting to close a portal would free it, without its creator knowing about it. This could lead to use-after-free issues when trying to use portals that have already been closed. With this change, PortalDrop() now refuses to act on portals marked as PORTAL_NEW or PORTAL_DEFINED. CLOSE ALL skips them, as it does for active portals. Note that AtAbort_Portals() (for transaction aborts) and AtSubAbort_Portals() (for subtransaction aborts) now puts such portals in a failed state so as they can be cleaned up during error cleanup. Two sets of tests are added: - Portal manipulations during planning and executor startup. - Portals and Bind messages, relying on injection points to check various transaction cases with portals marked as either PORTAL_NEW or PORTAL_DEFINED, where the on-error cleanup of portals marked as failed matters. Reported-by: Tomas Vondra <tomas@vondra.me> Author: Michael Paquier <michael@paquier.xyz> Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Backpatch-through: 14 Security: CVE-2026-116332 Branch ------ REL_18_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/8a2982de9f1a6f859d740b52cb97b457a29d009e Author: Michael Paquier <michael@paquier.xyz> Modified Files -------------- src/backend/tcop/postgres.c | 4 + src/backend/utils/mmgr/portalmem.c | 40 ++++++- src/test/modules/injection_points/Makefile | 2 +- .../injection_points/expected/portal_bind.out | 133 +++++++++++++++++++++ src/test/modules/injection_points/meson.build | 1 + .../modules/injection_points/sql/portal_bind.sql | 61 ++++++++++ src/test/regress/expected/portals_inflight.out | 127 ++++++++++++++++++++ src/test/regress/parallel_schedule | 2 +- src/test/regress/sql/portals_inflight.sql | 99 +++++++++++++++ 9 files changed, 463 insertions(+), 6 deletions(-) ^ permalink raw reply [nested|flat] 4+ messages in thread
* pgsql: Fix use-after-free issues due to drop of portals being set up @ 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 Fix use-after-free issues due to drop of portals being set up Between CreatePortal() and PortalStart(), a portal can run user-defined code due to planning and executor startup, like SQL functions. A function attempting to close a portal would free it, without its creator knowing about it. This could lead to use-after-free issues when trying to use portals that have already been closed. With this change, PortalDrop() now refuses to act on portals marked as PORTAL_NEW or PORTAL_DEFINED. CLOSE ALL skips them, as it does for active portals. Note that AtAbort_Portals() (for transaction aborts) and AtSubAbort_Portals() (for subtransaction aborts) now puts such portals in a failed state so as they can be cleaned up during error cleanup. Two sets of tests are added: - Portal manipulations during planning and executor startup. - Portals and Bind messages, relying on injection points to check various transaction cases with portals marked as either PORTAL_NEW or PORTAL_DEFINED, where the on-error cleanup of portals marked as failed matters. Reported-by: Tomas Vondra <tomas@vondra.me> Author: Michael Paquier <michael@paquier.xyz> Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Backpatch-through: 14 Security: CVE-2026-116332 Branch ------ REL_17_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/36f42216eb6135c3de6a12607d49f516c5d0dfad Author: Michael Paquier <michael@paquier.xyz> Modified Files -------------- src/backend/tcop/postgres.c | 4 + src/backend/utils/mmgr/portalmem.c | 40 ++++++- src/test/modules/injection_points/Makefile | 2 +- .../injection_points/expected/portal_bind.out | 133 +++++++++++++++++++++ src/test/modules/injection_points/meson.build | 1 + .../modules/injection_points/sql/portal_bind.sql | 61 ++++++++++ src/test/regress/expected/portals_inflight.out | 127 ++++++++++++++++++++ src/test/regress/parallel_schedule | 2 +- src/test/regress/sql/portals_inflight.sql | 99 +++++++++++++++ 9 files changed, 463 insertions(+), 6 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: Fix use-after-free issues due to drop of portals being set up Noah Misch <noah@leadboat.com> 2026-11-09 14:21 pgsql: Fix use-after-free issues due to drop of portals being set up Noah Misch <noah@leadboat.com> 2026-11-09 14:21 pgsql: Fix use-after-free issues due to drop of portals being set up Noah Misch <noah@leadboat.com> 2026-11-09 14:22 pgsql: Fix use-after-free issues due to drop of portals being set up 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