pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Fix pfree-of-already-freed-tuple when rescanning a GiST index-on 3+ messages / 1 participants [nested] [flat]
* pgsql: Fix pfree-of-already-freed-tuple when rescanning a GiST index-on @ 2017-05-04 17:59 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 3+ messages in thread From: Tom Lane @ 2017-05-04 17:59 UTC (permalink / raw) To: pgsql-committers Fix pfree-of-already-freed-tuple when rescanning a GiST index-only scan. GiST's getNextNearest() function attempts to pfree the previously-returned tuple if any (that is, scan->xs_hitup in HEAD, or scan->xs_itup in older branches). However, if we are rescanning a plan node after ending a previous scan early, those tuple pointers could be pointing to garbage, because they would be pointing into the scan's pageDataCxt or queueCxt which has been reset. In a debug build this reliably results in a crash, although I think it might sometimes accidentally fail to fail in production builds. To fix, clear the pointer field anyplace we reset a context it might be pointing into. This may be overkill --- I think probably only the queueCxt case is involved in this bug, so that resetting in gistrescan() would be sufficient --- but dangling pointers are generally bad news, so let's avoid them. Another plausible answer might be to just not bother with the pfree in getNextNearest(). The reconstructed tuples would go away anyway in the context resets, and I'm far from convinced that freeing them a bit earlier really saves anything meaningful. I'll stick with the original logic in this patch, but if we find more problems in the same area we should consider that approach. Per bug #14641 from Denis Smirnov. Back-patch to 9.5 where this logic was introduced. Discussion: https://postgr.es/m/20170504072034.24366.57688@wrigleys.postgresql.org Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/3f074845a8c190b365e68e39e39017ff70330f2a Modified Files -------------- src/backend/access/gist/gistget.c | 3 +++ src/backend/access/gist/gistscan.c | 3 +++ src/test/regress/expected/gist.out | 34 ++++++++++++++++++++++++++++++++++ src/test/regress/sql/gist.sql | 16 ++++++++++++++++ 4 files changed, 56 insertions(+) -- Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-committers ^ permalink raw reply [nested|flat] 3+ messages in thread
* pgsql: Fix pfree-of-already-freed-tuple when rescanning a GiST index-on @ 2017-05-04 17:59 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 3+ messages in thread From: Tom Lane @ 2017-05-04 17:59 UTC (permalink / raw) To: pgsql-committers Fix pfree-of-already-freed-tuple when rescanning a GiST index-only scan. GiST's getNextNearest() function attempts to pfree the previously-returned tuple if any (that is, scan->xs_hitup in HEAD, or scan->xs_itup in older branches). However, if we are rescanning a plan node after ending a previous scan early, those tuple pointers could be pointing to garbage, because they would be pointing into the scan's pageDataCxt or queueCxt which has been reset. In a debug build this reliably results in a crash, although I think it might sometimes accidentally fail to fail in production builds. To fix, clear the pointer field anyplace we reset a context it might be pointing into. This may be overkill --- I think probably only the queueCxt case is involved in this bug, so that resetting in gistrescan() would be sufficient --- but dangling pointers are generally bad news, so let's avoid them. Another plausible answer might be to just not bother with the pfree in getNextNearest(). The reconstructed tuples would go away anyway in the context resets, and I'm far from convinced that freeing them a bit earlier really saves anything meaningful. I'll stick with the original logic in this patch, but if we find more problems in the same area we should consider that approach. Per bug #14641 from Denis Smirnov. Back-patch to 9.5 where this logic was introduced. Discussion: https://postgr.es/m/20170504072034.24366.57688@wrigleys.postgresql.org Branch ------ REL9_6_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/855f0e9247a160bfad00c117ba7d97148cd2a0ec Modified Files -------------- src/backend/access/gist/gistget.c | 3 +++ src/backend/access/gist/gistscan.c | 3 +++ src/test/regress/expected/gist.out | 34 ++++++++++++++++++++++++++++++++++ src/test/regress/sql/gist.sql | 16 ++++++++++++++++ 4 files changed, 56 insertions(+) -- Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-committers ^ permalink raw reply [nested|flat] 3+ messages in thread
* pgsql: Fix pfree-of-already-freed-tuple when rescanning a GiST index-on @ 2017-05-04 17:59 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 3+ messages in thread From: Tom Lane @ 2017-05-04 17:59 UTC (permalink / raw) To: pgsql-committers Fix pfree-of-already-freed-tuple when rescanning a GiST index-only scan. GiST's getNextNearest() function attempts to pfree the previously-returned tuple if any (that is, scan->xs_hitup in HEAD, or scan->xs_itup in older branches). However, if we are rescanning a plan node after ending a previous scan early, those tuple pointers could be pointing to garbage, because they would be pointing into the scan's pageDataCxt or queueCxt which has been reset. In a debug build this reliably results in a crash, although I think it might sometimes accidentally fail to fail in production builds. To fix, clear the pointer field anyplace we reset a context it might be pointing into. This may be overkill --- I think probably only the queueCxt case is involved in this bug, so that resetting in gistrescan() would be sufficient --- but dangling pointers are generally bad news, so let's avoid them. Another plausible answer might be to just not bother with the pfree in getNextNearest(). The reconstructed tuples would go away anyway in the context resets, and I'm far from convinced that freeing them a bit earlier really saves anything meaningful. I'll stick with the original logic in this patch, but if we find more problems in the same area we should consider that approach. Per bug #14641 from Denis Smirnov. Back-patch to 9.5 where this logic was introduced. Discussion: https://postgr.es/m/20170504072034.24366.57688@wrigleys.postgresql.org Branch ------ REL9_5_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/6cfb428b05a8742ac0ec17145c90c4672d44177d Modified Files -------------- src/backend/access/gist/gistget.c | 3 +++ src/backend/access/gist/gistscan.c | 3 +++ src/test/regress/expected/gist.out | 34 ++++++++++++++++++++++++++++++++++ src/test/regress/sql/gist.sql | 16 ++++++++++++++++ 4 files changed, 56 insertions(+) -- Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-committers ^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2017-05-04 17:59 UTC | newest] Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2017-05-04 17:59 pgsql: Fix pfree-of-already-freed-tuple when rescanning a GiST index-on Tom Lane <tgl@sss.pgh.pa.us> 2017-05-04 17:59 pgsql: Fix pfree-of-already-freed-tuple when rescanning a GiST index-on Tom Lane <tgl@sss.pgh.pa.us> 2017-05-04 17:59 pgsql: Fix pfree-of-already-freed-tuple when rescanning a GiST index-on Tom Lane <tgl@sss.pgh.pa.us>
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