pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Keep the relation open while importing its statistics. 3+ messages / 1 participants [nested] [flat]
* pgsql: Keep the relation open while importing its statistics. @ 2026-11-09 14:21 Noah Misch <noah@leadboat.com> 0 siblings, 0 replies; 3+ messages in thread From: Noah Misch @ 2026-11-09 14:21 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Keep the relation open while importing its statistics. The attribute statistics import function locked the target relation but did not keep it open while converting its input values. Converting a value can run user-defined code, such as a domain's CHECK constraint, which can alter the relation in the same transaction. The lock alone does not prevent that. The import could then store statistics that no longer match the column, which can crash the backend when the planner later reads them. Keep the relation open across the conversion, so that such a reentrant ALTER TABLE is rejected by CheckTableNotInUse() as it is elsewhere. Also, the same code can drop the target column itself, which doesn't go through that check. The import would then store a pg_statistic row for a column that no longer exists. That only leaves a stale catalog row behind, but it's wrong all the same, so re-check that the column still exists before writing, and error out if it doesn't. The column must not go away while we restore its statistics, and raising an error also rolls back the drop. The extended statistics import function, added in v19, has the same hazard and is fixed in the same way. There the same code can also drop the statistics object being imported, which would leave a pg_statistic_ext_data row with no owner. A statistics object created later with the same OID would pick that row up as its own, so we re-check that as well. Branches before v19 have no such function. Reported-by: Mehmet D. INCE <mehmet@mehmetince.net> Author: Masahiko Sawada <sawada.mshk@gmail.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Reviewed-by: Andres Freund <andres@anarazel.de> Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi> Backpatch-through: 18 Security: CVE-2026-116329 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/d41c9fad0856d73cc0613d322b669bf10e91dd77 Author: Masahiko Sawada <msawada@postgresql.org> Modified Files -------------- src/backend/statistics/attribute_stats.c | 26 ++++ src/backend/statistics/extended_stats_funcs.c | 25 ++++ src/test/regress/expected/stats_import.out | 175 +++++++++++++++++++++++++- src/test/regress/sql/stats_import.sql | 156 +++++++++++++++++++++++ 4 files changed, 381 insertions(+), 1 deletion(-) ^ permalink raw reply [nested|flat] 3+ messages in thread
* pgsql: Keep the relation open while importing its statistics. @ 2026-11-09 14:21 Noah Misch <noah@leadboat.com> 0 siblings, 0 replies; 3+ messages in thread From: Noah Misch @ 2026-11-09 14:21 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Keep the relation open while importing its statistics. The attribute statistics import function locked the target relation but did not keep it open while converting its input values. Converting a value can run user-defined code, such as a domain's CHECK constraint, which can alter the relation in the same transaction. The lock alone does not prevent that. The import could then store statistics that no longer match the column, which can crash the backend when the planner later reads them. Keep the relation open across the conversion, so that such a reentrant ALTER TABLE is rejected by CheckTableNotInUse() as it is elsewhere. Also, the same code can drop the target column itself, which doesn't go through that check. The import would then store a pg_statistic row for a column that no longer exists. That only leaves a stale catalog row behind, but it's wrong all the same, so re-check that the column still exists before writing, and error out if it doesn't. The column must not go away while we restore its statistics, and raising an error also rolls back the drop. The extended statistics import function, added in v19, has the same hazard and is fixed in the same way. There the same code can also drop the statistics object being imported, which would leave a pg_statistic_ext_data row with no owner. A statistics object created later with the same OID would pick that row up as its own, so we re-check that as well. Branches before v19 have no such function. Reported-by: Mehmet D. INCE <mehmet@mehmetince.net> Author: Masahiko Sawada <sawada.mshk@gmail.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Reviewed-by: Andres Freund <andres@anarazel.de> Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi> Backpatch-through: 18 Security: CVE-2026-116329 Branch ------ REL_19_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/ee7c8f051bd433fb78f85d1c850ebb7b40004eb8 Author: Masahiko Sawada <msawada@postgresql.org> Modified Files -------------- src/backend/statistics/attribute_stats.c | 26 ++++ src/backend/statistics/extended_stats_funcs.c | 25 ++++ src/test/regress/expected/stats_import.out | 175 +++++++++++++++++++++++++- src/test/regress/sql/stats_import.sql | 156 +++++++++++++++++++++++ 4 files changed, 381 insertions(+), 1 deletion(-) ^ permalink raw reply [nested|flat] 3+ messages in thread
* pgsql: Keep the relation open while importing its statistics. @ 2026-11-09 14:21 Noah Misch <noah@leadboat.com> 0 siblings, 0 replies; 3+ messages in thread From: Noah Misch @ 2026-11-09 14:21 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Keep the relation open while importing its statistics. The attribute statistics import function locked the target relation but did not keep it open while converting its input values. Converting a value can run user-defined code, such as a domain's CHECK constraint, which can alter the relation in the same transaction. The lock alone does not prevent that. The import could then store statistics that no longer match the column, which can crash the backend when the planner later reads them. Keep the relation open across the conversion, so that such a reentrant ALTER TABLE is rejected by CheckTableNotInUse() as it is elsewhere. Also, the same code can drop the target column itself, which doesn't go through that check. The import would then store a pg_statistic row for a column that no longer exists. That only leaves a stale catalog row behind, but it's wrong all the same, so re-check that the column still exists before writing, and error out if it doesn't. The column must not go away while we restore its statistics, and raising an error also rolls back the drop. The extended statistics import function, added in v19, has the same hazard and is fixed in the same way. There the same code can also drop the statistics object being imported, which would leave a pg_statistic_ext_data row with no owner. A statistics object created later with the same OID would pick that row up as its own, so we re-check that as well. Branches before v19 have no such function. Reported-by: Mehmet D. INCE <mehmet@mehmetince.net> Author: Masahiko Sawada <sawada.mshk@gmail.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Reviewed-by: Andres Freund <andres@anarazel.de> Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi> Backpatch-through: 18 Security: CVE-2026-116329 Branch ------ REL_18_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/780900dcfab7652f510ec60059cf8dbb51bfd7f5 Author: Masahiko Sawada <msawada@postgresql.org> Modified Files -------------- src/backend/statistics/attribute_stats.c | 26 +++++++++ src/test/regress/expected/stats_import.out | 84 +++++++++++++++++++++++++++++- src/test/regress/sql/stats_import.sql | 73 ++++++++++++++++++++++++++ 3 files changed, 182 insertions(+), 1 deletion(-) ^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2026-11-09 14:21 UTC | newest] Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2026-11-09 14:21 pgsql: Keep the relation open while importing its statistics. Noah Misch <noah@leadboat.com> 2026-11-09 14:21 pgsql: Keep the relation open while importing its statistics. Noah Misch <noah@leadboat.com> 2026-11-09 14:21 pgsql: Keep the relation open while importing its statistics. 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