pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix use-after-free bug with event triggers in an extension scrip
7+ messages / 2 participants
[nested] [flat]

* pgsql: Fix use-after-free bug with event triggers in an extension scrip
@ 2020-09-16 00:05 Alvaro Herrera <alvherre@alvh.no-ip.org>
  0 siblings, 0 replies; 7+ messages in thread

From: Alvaro Herrera @ 2020-09-16 00:05 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix use-after-free bug with event triggers in an extension script

ALTER TABLE commands in an extension script are added to an event
trigger command list; but starting with commit b5810de3f4 they do so in
a memory context that's too short-lived, so when execution ends and time
comes to use the entries, they've already been freed.

(This would also be a problem with ALTER TABLE commands in a
multi-command query string, but these serendipitously end in
PortalContext -- which probably explains why it took so long for this to
be reported.)

Fix by using the memory context specifically set for that, instead.

Backpatch to 13, where the aforementioned commit appeared.

Reported-by: Philippe Beaudoin
Author: Jehan-Guillaume de Rorthais <jgdr@dalibo.com>
Discussion: https://postgr.es/m/20200902193715.6e0269d4@firost

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/ced138e8cbac7f5a840de8679e9882665478c680

Modified Files
--------------
src/backend/commands/event_trigger.c                     |  6 ++++++
src/test/modules/test_extensions/Makefile                |  6 ++++--
.../modules/test_extensions/expected/test_extensions.out |  5 +++++
src/test/modules/test_extensions/sql/test_extensions.sql |  6 ++++++
.../test_extensions/test_ext_evttrig--1.0--2.0.sql       |  7 +++++++
.../modules/test_extensions/test_ext_evttrig--1.0.sql    | 16 ++++++++++++++++
.../modules/test_extensions/test_ext_evttrig.control     |  3 +++
7 files changed, 47 insertions(+), 2 deletions(-)



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

* pgsql: Fix use-after-free bug with event triggers in an extension scrip
@ 2020-09-16 00:05 Alvaro Herrera <alvherre@alvh.no-ip.org>
  0 siblings, 0 replies; 7+ messages in thread

From: Alvaro Herrera @ 2020-09-16 00:05 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix use-after-free bug with event triggers in an extension script

ALTER TABLE commands in an extension script are added to an event
trigger command list; but starting with commit b5810de3f4 they do so in
a memory context that's too short-lived, so when execution ends and time
comes to use the entries, they've already been freed.

(This would also be a problem with ALTER TABLE commands in a
multi-command query string, but these serendipitously end in
PortalContext -- which probably explains why it took so long for this to
be reported.)

Fix by using the memory context specifically set for that, instead.

Backpatch to 13, where the aforementioned commit appeared.

Reported-by: Philippe Beaudoin
Author: Jehan-Guillaume de Rorthais <jgdr@dalibo.com>
Discussion: https://postgr.es/m/20200902193715.6e0269d4@firost

Branch
------
REL_13_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/873cb8fca9b14bde3e1d5577fcbb7b76d303076d

Modified Files
--------------
src/backend/commands/event_trigger.c                     |  6 ++++++
src/test/modules/test_extensions/Makefile                |  6 ++++--
.../modules/test_extensions/expected/test_extensions.out |  5 +++++
src/test/modules/test_extensions/sql/test_extensions.sql |  6 ++++++
.../test_extensions/test_ext_evttrig--1.0--2.0.sql       |  7 +++++++
.../modules/test_extensions/test_ext_evttrig--1.0.sql    | 16 ++++++++++++++++
.../modules/test_extensions/test_ext_evttrig.control     |  3 +++
7 files changed, 47 insertions(+), 2 deletions(-)



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

* pgsql: Fix use-after-free bug with event triggers and ALTER TABLE.
@ 2020-10-27 19:37 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 7+ messages in thread

From: Tom Lane @ 2020-10-27 19:37 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix use-after-free bug with event triggers and ALTER TABLE.

EventTriggerAlterTableEnd neglected to make sure that it built its
output list in the right context.  In simple cases this was masked
because the function is called in PortalContext which will be
sufficiently long-lived anyway; but that doesn't make it not a bug.
Commit ced138e8c fixed this in HEAD and v13, but mistakenly chose
not to back-patch further.  Back-patch the same code change all
the way (I didn't bother with the test case though, as it would
prove nothing in pre-v13 branches).

Per report from Arseny Sher.
Original fix by Jehan-Guillaume de Rorthais.

Discussion: https://postgr.es/m/877drcyprb.fsf@ars-thinkpad
Discussion: https://postgr.es/m/20200902193715.6e0269d4@firost

Branch
------
REL_12_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/93f726c04fb134e1b28aaec84f10f296a00b6df8

Modified Files
--------------
src/backend/commands/event_trigger.c | 6 ++++++
1 file changed, 6 insertions(+)



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

* pgsql: Fix use-after-free bug with event triggers and ALTER TABLE.
@ 2020-10-27 19:37 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 7+ messages in thread

From: Tom Lane @ 2020-10-27 19:37 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix use-after-free bug with event triggers and ALTER TABLE.

EventTriggerAlterTableEnd neglected to make sure that it built its
output list in the right context.  In simple cases this was masked
because the function is called in PortalContext which will be
sufficiently long-lived anyway; but that doesn't make it not a bug.
Commit ced138e8c fixed this in HEAD and v13, but mistakenly chose
not to back-patch further.  Back-patch the same code change all
the way (I didn't bother with the test case though, as it would
prove nothing in pre-v13 branches).

Per report from Arseny Sher.
Original fix by Jehan-Guillaume de Rorthais.

Discussion: https://postgr.es/m/877drcyprb.fsf@ars-thinkpad
Discussion: https://postgr.es/m/20200902193715.6e0269d4@firost

Branch
------
REL_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/66c036b4f143d129ea3c2e390ff4e3b449a83ed6

Modified Files
--------------
src/backend/commands/event_trigger.c | 6 ++++++
1 file changed, 6 insertions(+)



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

* pgsql: Fix use-after-free bug with event triggers and ALTER TABLE.
@ 2020-10-27 19:37 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 7+ messages in thread

From: Tom Lane @ 2020-10-27 19:37 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix use-after-free bug with event triggers and ALTER TABLE.

EventTriggerAlterTableEnd neglected to make sure that it built its
output list in the right context.  In simple cases this was masked
because the function is called in PortalContext which will be
sufficiently long-lived anyway; but that doesn't make it not a bug.
Commit ced138e8c fixed this in HEAD and v13, but mistakenly chose
not to back-patch further.  Back-patch the same code change all
the way (I didn't bother with the test case though, as it would
prove nothing in pre-v13 branches).

Per report from Arseny Sher.
Original fix by Jehan-Guillaume de Rorthais.

Discussion: https://postgr.es/m/877drcyprb.fsf@ars-thinkpad
Discussion: https://postgr.es/m/20200902193715.6e0269d4@firost

Branch
------
REL_10_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/41c742a432427177e2ddd6ba434d555f8e6cf02b

Modified Files
--------------
src/backend/commands/event_trigger.c | 6 ++++++
1 file changed, 6 insertions(+)



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

* pgsql: Fix use-after-free bug with event triggers and ALTER TABLE.
@ 2020-10-27 19:37 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 7+ messages in thread

From: Tom Lane @ 2020-10-27 19:37 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix use-after-free bug with event triggers and ALTER TABLE.

EventTriggerAlterTableEnd neglected to make sure that it built its
output list in the right context.  In simple cases this was masked
because the function is called in PortalContext which will be
sufficiently long-lived anyway; but that doesn't make it not a bug.
Commit ced138e8c fixed this in HEAD and v13, but mistakenly chose
not to back-patch further.  Back-patch the same code change all
the way (I didn't bother with the test case though, as it would
prove nothing in pre-v13 branches).

Per report from Arseny Sher.
Original fix by Jehan-Guillaume de Rorthais.

Discussion: https://postgr.es/m/877drcyprb.fsf@ars-thinkpad
Discussion: https://postgr.es/m/20200902193715.6e0269d4@firost

Branch
------
REL9_6_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/cc623ed2f4ac09a97c5ef24dee28d91482ae2e13

Modified Files
--------------
src/backend/commands/event_trigger.c | 6 ++++++
1 file changed, 6 insertions(+)



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

* pgsql: Fix use-after-free bug with event triggers and ALTER TABLE.
@ 2020-10-27 19:37 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 7+ messages in thread

From: Tom Lane @ 2020-10-27 19:37 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix use-after-free bug with event triggers and ALTER TABLE.

EventTriggerAlterTableEnd neglected to make sure that it built its
output list in the right context.  In simple cases this was masked
because the function is called in PortalContext which will be
sufficiently long-lived anyway; but that doesn't make it not a bug.
Commit ced138e8c fixed this in HEAD and v13, but mistakenly chose
not to back-patch further.  Back-patch the same code change all
the way (I didn't bother with the test case though, as it would
prove nothing in pre-v13 branches).

Per report from Arseny Sher.
Original fix by Jehan-Guillaume de Rorthais.

Discussion: https://postgr.es/m/877drcyprb.fsf@ars-thinkpad
Discussion: https://postgr.es/m/20200902193715.6e0269d4@firost

Branch
------
REL9_5_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/7978ad025478e1c6f3a60ee95d6ebefe7f263841

Modified Files
--------------
src/backend/commands/event_trigger.c | 6 ++++++
1 file changed, 6 insertions(+)



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


end of thread, other threads:[~2020-10-27 19:37 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-09-16 00:05 pgsql: Fix use-after-free bug with event triggers in an extension scrip Alvaro Herrera <alvherre@alvh.no-ip.org>
2020-09-16 00:05 pgsql: Fix use-after-free bug with event triggers in an extension scrip Alvaro Herrera <alvherre@alvh.no-ip.org>
2020-10-27 19:37 pgsql: Fix use-after-free bug with event triggers and ALTER TABLE. Tom Lane <tgl@sss.pgh.pa.us>
2020-10-27 19:37 pgsql: Fix use-after-free bug with event triggers and ALTER TABLE. Tom Lane <tgl@sss.pgh.pa.us>
2020-10-27 19:37 pgsql: Fix use-after-free bug with event triggers and ALTER TABLE. Tom Lane <tgl@sss.pgh.pa.us>
2020-10-27 19:37 pgsql: Fix use-after-free bug with event triggers and ALTER TABLE. Tom Lane <tgl@sss.pgh.pa.us>
2020-10-27 19:37 pgsql: Fix use-after-free bug with event triggers and ALTER TABLE. 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