pg.ddx.io pgaudit/pgaudit GitHub issues and pull requests
help / color / mirror / Atom feed[pgaudit/pgaudit] issue #259: Coredump in log_select_dml()
8+ messages / 3 participants
[nested] [flat]
* [pgaudit/pgaudit] issue #259: Coredump in log_select_dml()
@ 2025-01-29 12:16 "x4m (@x4m)" <noreply+x4m@github.com>
0 siblings, 0 replies; 8+ messages in thread
From: x4m (@x4m) @ 2025-01-29 12:16 UTC (permalink / raw)
To: pgaudit/pgaudit <noreply+pgaudit-pgaudit@github.com>
Hi!
It seems like in some cases relOid and relNamespaceOid [here](https://github.com/pgaudit/pgaudit/blob/9dfbb957eda8e7f7f62860766859cbe27cccc3ff/pgaudit.c#L1245) might point to invalid object. This leads to coredump, but it's hard to reproduce. I suspect it happens in case of some DMLs.
I'm tempted to add "if not NULL" check, but this seems to be not very good workaround.
<details><summary>Backtrace</summary>
<p>
```
#0 0x00005568bff986ab in quote_identifier (ident=ident@entry=0x0) at utils/adt/./build/../src/backend/utils/adt/ruleutils.c:12687
#1 0x00005568bff98aca in quote_qualified_identifier (qualifier=0x0, ident=ident@entry=0x0) at utils/adt/./build/../src/backend/utils/adt/ruleutils.c:12762
#2 0x00007f8e50995969 in log_select_dml (auditOid=auditOid@entry=0, rangeTabls=rangeTabls@entry=0x5568c0ab10c0, permInfos=permInfos@entry=0x5568c0ab1198)
at ./pgaudit.c:1246
#3 0x00007f8e50995d9b in log_select_dml (permInfos=0x5568c0ab1198, rangeTabls=0x5568c0ab10c0, auditOid=0) at ./pgaudit.c:1103
#4 pgaudit_ExecutorCheckPerms_hook (rangeTabls=0x5568c0ab10c0, permInfos=0x5568c0ab1198, abort=<optimized out>) at ./pgaudit.c:1518
#5 0x00005568bfc9e9ae in InitPlan (eflags=32, queryDesc=0x5568c0ab7258) at executor/./build/../src/backend/executor/execMain.c:850
#6 standard_ExecutorStart (queryDesc=0x5568c0ab7258, eflags=32) at executor/./build/../src/backend/executor/execMain.c:263
#7 0x00007f8e509bf1dd in pgss_ExecutorStart (queryDesc=0x5568c0ab7258, eflags=<optimized out>)
at ./build/../contrib/pg_stat_statements/pg_stat_statements.c:987
#8 0x00007f8e50994b8b in pgaudit_ExecutorStart_hook (queryDesc=0x5568c0ab7258, eflags=0) at ./pgaudit.c:1453
#9 0x00005568bfe97ce0 in ExecutorStart (eflags=0, queryDesc=0x5568c0ab7258) at executor/./build/../src/backend/executor/execMain.c:137
#10 PortalStart (portal=0x5568c0a0e2b8, params=0x0, eflags=0, snapshot=0x0) at tcop/./build/../src/backend/tcop/pquery.c:517
#11 0x00005568bfe90fe4 in exec_simple_query (
query_string=0x5568c0913158 "SELECT n.nspname as \"Schema\",\n c.relname as \"Name\",\n CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'm' THEN 'materialized view' WHEN 'i' THEN 'index' WHEN 'S' THEN 'sequence' WHEN 't' THEN 'TOAST table' WHEN 'f' THEN 'foreign table' WHEN 'p' THEN 'partitioned table' WHEN 'I' THEN 'partitioned index' END as \"Type\",\n pg_catalog.pg_get_userbyid(c.relowner) as \"Owner\"\nFROM pg_catalog.pg_class c\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n LEFT JOIN pg_catalog.pg_am am ON am.oid = c.relam\nWHERE c.relkind IN ('r','p','')\n AND n.nspname <> 'pg_catalog'\n AND n.nspname !~ '^pg_toast'\n AND n.nspname <> 'information_schema'\n AND pg_catalog.pg_table_is_visible(c.oid)\nORDER BY 1,2;") at tcop/./build/../src/backend/tcop/postgres.c:1243
#12 0x00005568bfe99190 in PostgresMain (dbname=<optimized out>, username=<optimized out>) at tcop/./build/../src/backend/tcop/postgres.c:4773
#13 0x00005568bfe8f17f in BackendMain (startup_data=<optimized out>, startup_data_len=<optimized out>)
at tcop/./build/../src/backend/tcop/backend_startup.c:105
#14 0x00005568bfdec156 in postmaster_child_launch (child_type=B_BACKEND, startup_data=0x7ffd3fb7e030 "", startup_data_len=4, client_sock=0x7ffd3fb7e050)
at postmaster/./build/../src/backend/postmaster/launch_backend.c:277
#15 0x00005568bfdf9359 in postmaster_child_launch (client_sock=0x7ffd3fb7e050, startup_data_len=4, startup_data=0x7ffd3fb7e030 "", child_type=B_BACKEND)
at postmaster/./build/../src/backend/postmaster/postmaster.c:3694
#16 BackendStartup (client_sock=0x7ffd3fb7e050) at postmaster/./build/../src/backend/postmaster/postmaster.c:3593
#17 ServerLoop () at postmaster/./build/../src/backend/postmaster/postmaster.c:1674
#18 0x00005568bfdedcd0 in PostmasterMain (argc=9, argv=<optimized out>) at postmaster/./build/../src/backend/postmaster/postmaster.c:1372
#19 0x00005568bfa98ee3 in main (argc=9, argv=0x5568c087c3b0) at main/./build/../src/backend/main/main.c:197
(gdb) frame 2
#2 0x00007f8e50995969 in log_select_dml (auditOid=auditOid@entry=0, rangeTabls=rangeTabls@entry=0x5568c0ab10c0, permInfos=permInfos@entry=0x5568c0ab1198)
at ./pgaudit.c:1246
1246 in ./pgaudit.c
(gdb) info locals
relOid = 3230747760
relNamespaceOid = <optimized out>
rte = <optimized out>
perminfo = 0x5568c0ab1150
lr__state = {l = <optimized out>, i = 0}
lr = <optimized out>
first = false
found = true
local var relOid = 3230747760 not in rangeTabls
(gdb) p *((RangeTblEntry *)rangeTabls->elements[0].ptr_value)
$11 = {type = T_RangeTblEntry, alias = 0x5568c0914c70, eref = 0x5568c09a3b40, rtekind = RTE_RELATION, relid = 1259, inh = false, relkind = 114 'r',
rellockmode = 1, perminfoindex = 1, tablesample = 0x0, subquery = 0x0, security_barrier = false, jointype = JOIN_INNER, joinmergedcols = 0,
joinaliasvars = 0x0, joinleftcols = 0x0, joinrightcols = 0x0, join_using_alias = 0x0, functions = 0x0, funcordinality = false, tablefunc = 0x0,
values_lists = 0x0, ctename = 0x0, ctelevelsup = 0, self_reference = false, coltypes = 0x0, coltypmods = 0x0, colcollations = 0x0, enrname = 0x0,
enrtuples = 0, lateral = false, inFromCl = true, securityQuals = 0x0}
(gdb) p *((RangeTblEntry *)rangeTabls->elements[1].ptr_value)
$12 = {type = T_RangeTblEntry, alias = 0x5568c0914d80, eref = 0x5568c09b5ad8, rtekind = RTE_RELATION, relid = 2615, inh = false, relkind = 114 'r',
rellockmode = 1, perminfoindex = 2, tablesample = 0x0, subquery = 0x0, security_barrier = false, jointype = JOIN_INNER, joinmergedcols = 0,
joinaliasvars = 0x0, joinleftcols = 0x0, joinrightcols = 0x0, join_using_alias = 0x0, functions = 0x0, funcordinality = false, tablefunc = 0x0,
values_lists = 0x0, ctename = 0x0, ctelevelsup = 0, self_reference = false, coltypes = 0x0, coltypmods = 0x0, colcollations = 0x0, enrname = 0x0,
enrtuples = 0, lateral = false, inFromCl = true, securityQuals = 0x0}
(gdb) p *((RangeTblEntry *)rangeTabls->elements[2].ptr_value)
$13 = {type = T_RangeTblEntry, alias = 0x0, eref = 0x5568c09b7880, rtekind = RTE_JOIN, relid = 0, inh = false, relkind = 0 '\000', rellockmode = 0,
perminfoindex = 0, tablesample = 0x0, subquery = 0x0, security_barrier = false, jointype = JOIN_INNER, joinmergedcols = 0, joinaliasvars = 0x0,
joinleftcols = 0x0, joinrightcols = 0x0, join_using_alias = 0x0, functions = 0x0, funcordinality = false, tablefunc = 0x0, values_lists = 0x0,
ctename = 0x0, ctelevelsup = 0, self_reference = false, coltypes = 0x0, coltypmods = 0x0, colcollations = 0x0, enrname = 0x0, enrtuples = 0,
lateral = false, inFromCl = true, securityQuals = 0x0}
(gdb) p *((RangeTblEntry *)rangeTabls->elements[3].ptr_value)
$14 = {type = T_RangeTblEntry, alias = 0x5568c09a20c0, eref = 0x5568c09b8130, rtekind = RTE_RELATION, relid = 2601, inh = false, relkind = 114 'r',
rellockmode = 1, perminfoindex = 3, tablesample = 0x0, subquery = 0x0, security_barrier = false, jointype = JOIN_INNER, joinmergedcols = 0,
joinaliasvars = 0x0, joinleftcols = 0x0, joinrightcols = 0x0, join_using_alias = 0x0, functions = 0x0, funcordinality = false, tablefunc = 0x0,
values_lists = 0x0, ctename = 0x0, ctelevelsup = 0, self_reference = false, coltypes = 0x0, coltypmods = 0x0, colcollations = 0x0, enrname = 0x0,
enrtuples = 0, lateral = false, inFromCl = true, securityQuals = 0x0}
(gdb) p *((RangeTblEntry *)rangeTabls->elements[4].ptr_value)
$15 = {type = T_RangeTblEntry, alias = 0x0, eref = 0x5568c09b8f78, rtekind = RTE_JOIN, relid = 0, inh = false, relkind = 0 '\000', rellockmode = 0,
perminfoindex = 0, tablesample = 0x0, subquery = 0x0, security_barrier = false, jointype = JOIN_LEFT, joinmergedcols = 0, joinaliasvars = 0x0,
joinleftcols = 0x0, joinrightcols = 0x0, join_using_alias = 0x0, functions = 0x0, funcordinality = false, tablefunc = 0x0, values_lists = 0x0,
ctename = 0x0, ctelevelsup = 0, self_reference = false, coltypes = 0x0, coltypmods = 0x0, colcollations = 0x0, enrname = 0x0, enrtuples = 0,
lateral = false, inFromCl = true, securityQuals = 0x0}
```
</p>
</details>
<details><summary>query</summary>
<p>
```
SELECT n.nspname as "Schema",
c.relname as "Name",
CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'm' THEN 'materialized view' WHEN 'i' THEN 'index' WHEN 'S' THEN 'sequence' WHEN 't' THEN 'TOAST table' WHEN 'f' THEN 'foreign table' WHEN 'p' THEN 'partitioned table' WHEN 'I' THEN 'partitioned index' END as "Type",
pg_catalog.pg_get_userbyid(c.relowner) as "Owner"
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
LEFT JOIN pg_catalog.pg_am am ON am.oid = c.relam
WHERE c.relkind IN ('r','p','')
AND n.nspname <> 'pg_catalog'
AND n.nspname !~ '^pg_toast'
AND n.nspname <> 'information_schema'
AND pg_catalog.pg_table_is_visible(c.oid)
ORDER BY 1,2;
```
</p>
</details>
^ permalink raw [nested|flat] 8+ messages in thread
* Re: [pgaudit/pgaudit] issue #259: Coredump in log_select_dml()
@ 2025-02-07 08:08 "reshke (@reshke)" <noreply+reshke@github.com>
6 siblings, 0 replies; 8+ messages in thread
From: reshke (@reshke) @ 2025-02-07 08:08 UTC (permalink / raw)
To: pgaudit/pgaudit <noreply+pgaudit-pgaudit@github.com>
we are now running pgaudit from my fork and it works.
https://github.com/reshke/pgaudit/commit/8d169228f0e1c679905716fe655ca4b78ac03ce8
this is clearly not a fix, just stupid workaround.
^ permalink raw [nested|flat] 8+ messages in thread
* Re: [pgaudit/pgaudit] issue #259: Coredump in log_select_dml()
@ 2025-02-18 20:41 "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
6 siblings, 0 replies; 8+ messages in thread
From: dwsteele (@dwsteele) @ 2025-02-18 20:41 UTC (permalink / raw)
To: pgaudit/pgaudit <noreply+pgaudit-pgaudit@github.com>
@dwsteele assigned @dwsteele.
^ permalink raw [nested|flat] 8+ messages in thread
* Re: [pgaudit/pgaudit] issue #259: Coredump in log_select_dml()
@ 2025-02-18 20:42 "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
6 siblings, 0 replies; 8+ messages in thread
From: dwsteele (@dwsteele) @ 2025-02-18 20:42 UTC (permalink / raw)
To: pgaudit/pgaudit <noreply+pgaudit-pgaudit@github.com>
@dwsteele applied label "question".
^ permalink raw [nested|flat] 8+ messages in thread
* Re: [pgaudit/pgaudit] issue #259: Coredump in log_select_dml()
@ 2025-02-18 21:10 "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
6 siblings, 0 replies; 8+ messages in thread
From: dwsteele (@dwsteele) @ 2025-02-18 21:10 UTC (permalink / raw)
To: pgaudit/pgaudit <noreply+pgaudit-pgaudit@github.com>
This seems like a Postgres bug to me. We are getting relOid out of the rte. If this is somehow expiring in the middle of our operation then that points to some sort of issue with the catalog snapshot.
^ permalink raw [nested|flat] 8+ messages in thread
* Re: [pgaudit/pgaudit] issue #259: Coredump in log_select_dml()
@ 2025-02-18 21:14 "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
6 siblings, 0 replies; 8+ messages in thread
From: dwsteele (@dwsteele) @ 2025-02-18 21:14 UTC (permalink / raw)
To: pgaudit/pgaudit <noreply+pgaudit-pgaudit@github.com>
The rather large relOid (3,230,747,760) definitely points to some serious relation churn.
^ permalink raw [nested|flat] 8+ messages in thread
* Re: [pgaudit/pgaudit] issue #259: Coredump in log_select_dml()
@ 2026-06-25 08:28 "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
6 siblings, 0 replies; 8+ messages in thread
From: dwsteele (@dwsteele) @ 2026-06-25 08:28 UTC (permalink / raw)
To: pgaudit/pgaudit <noreply+pgaudit-pgaudit@github.com>
@x4m @reshke A possible fix here would be something like:
```
+ contextOld = MemoryContextSwitchTo(auditEventStack->contextAudit);
+
auditEventStack->auditEvent.auditOid = auditOid;
- auditEventStack->auditEvent.rangeTabls = rangeTabls;
- auditEventStack->auditEvent.permInfos = permInfos;
+ auditEventStack->auditEvent.rangeTabls = copyObject(rangeTabls);
+ auditEventStack->auditEvent.permInfos = copyObject(permInfos);
+
+ MemoryContextSwitchTo(contextOld);
```
But seems like it would be pretty bad for performance. Considering this issue looks like it was caused by misuse of the hook chain I'm not sure it is worth it.
Some issues of this type should be handled by #250.
Thoughts?
^ permalink raw [nested|flat] 8+ messages in thread
* Re: [pgaudit/pgaudit] issue #259: Coredump in log_select_dml()
@ 2026-07-08 02:32 "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
6 siblings, 0 replies; 8+ messages in thread
From: dwsteele (@dwsteele) @ 2026-07-08 02:32 UTC (permalink / raw)
To: pgaudit/pgaudit <noreply+pgaudit-pgaudit@github.com>
@dwsteele closed this.
^ permalink raw [nested|flat] 8+ messages in thread
end of thread, other threads:[~2026-07-08 02:32 UTC | newest]
Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-01-29 12:16 [pgaudit/pgaudit] issue #259: Coredump in log_select_dml() "x4m (@x4m)" <noreply+x4m@github.com>
2025-02-07 08:08 ` "reshke (@reshke)" <noreply+reshke@github.com>
2025-02-18 20:41 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
2025-02-18 20:42 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
2025-02-18 21:10 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
2025-02-18 21:14 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
2026-06-25 08:28 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
2026-07-08 02:32 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.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