pg.ddx.io pgaudit/pgaudit GitHub issues and pull requestshelp / color / mirror / Atom feed
[pgaudit/pgaudit] issue #333: PG19: backend crash / "pgaudit stack is empty" from RI fast-path permission checks (after PostgreSQL commit 5aeb36f3273) 8+ messages / 2 participants [nested] [flat]
* [pgaudit/pgaudit] issue #333: PG19: backend crash / "pgaudit stack is empty" from RI fast-path permission checks (after PostgreSQL commit 5aeb36f3273) @ 2026-09-29 17:38 "zjyzh (@zjyzh)" <noreply+zjyzh@github.com> 0 siblings, 0 replies; 8+ messages in thread From: zjyzh (@zjyzh) @ 2026-09-29 17:38 UTC (permalink / raw) To: pgaudit/pgaudit <noreply+pgaudit-pgaudit@github.com> PostgreSQL commit [5aeb36f3273](https://github.com/postgres/postgres/commit/5aeb36f3273c768831284082f85b63066e84f16d) (`REL_19_STABLE`, 2026-09-24) makes the RI fast path call `ExecutorCheckPerms_hook` from inside the FK trigger. The lists it passes live in a per-tuple context that is reset after each check. pgaudit treats every hook call as the statement's own check. That causes four problems: 1. **Crash with `log_rows = on`.** The list pointers are saved on the audit stack item and read at `ExecutorEnd` after they have been freed (signal 11). 2. **`ERROR: pgaudit stack is empty` at COMMIT.** Deferred FK checks run with an empty stack, so the COMMIT fails. 3. **Wrong attribution.** Under `SET CONSTRAINTS ALL IMMEDIATE` or `CALL`/`DO` + `COMMIT`, the check is audited against that utility statement's event. 4. **Extra audit lines.** Without `log_rows`, FK reads log as `READ,SELECT` on the user's statement. This breaks the test "FK references do not log". ## Reproduce PostgreSQL `REL_19_STABLE` (after 5aeb36f3273) with pgaudit `main`: ```sql SET pgaudit.log = 'read, write'; SET pgaudit.log_rows = on; CREATE TABLE ri_pk (id int PRIMARY KEY); CREATE TABLE ri_fk (id int REFERENCES ri_pk (id)); INSERT INTO ri_pk VALUES (1), (2); INSERT INTO ri_fk VALUES (1), (2); -- backend crash ``` The existing regression test also fails: ``` LOG: client backend (PID 2295) was terminated by signal 11: Segmentation fault DETAIL: Failed process was running: INSERT INTO bbb VALUES (1); ``` Without `log_rows`, the same test shows extra lines: ``` +NOTICE: AUDIT: OBJECT,67,1,READ,SELECT,TABLE,public.aaa,INSERT INTO bbb VALUES (1),<not logged> +NOTICE: AUDIT: SESSION,67,1,READ,SELECT,TABLE,public.aaa,INSERT INTO bbb VALUES (1),<not logged> ``` ## Proposed fix Only audit a statement's own permission check. That is either: - the call made during pgaudit's `ExecutorStart` hook for the top stack item (a static saved and restored with `PG_TRY`/`PG_FINALLY`), or - the first check of a `COPY` statement. Pass all other calls (the RI fast path, `RI_Initial_Check`, calls with an empty stack) to the next hook without auditing. This keeps the pre-5aeb36f3273 output. With this fix, the regression suite passes. The added tests cover multi-row FKs, deferred FKs at COMMIT, `SET CONSTRAINTS`, `CALL`/`DO` + `COMMIT` and `COPY FROM`, each with `log_rows` on and off. ## Related - `de00323` only skips calls where `ereport_on_violation = false`. The fast path passes `true`, so the fast path is not covered. - #80 (RI trigger selects logged), #212 (hook called with an empty stack) ^ permalink raw [nested|flat] 8+ messages in thread
* Re: [pgaudit/pgaudit] issue #333: PG19: backend crash / "pgaudit stack is empty" from RI fast-path permission checks (after PostgreSQL commit 5aeb36f3273) @ 2026-09-29 18:26 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com> 6 siblings, 0 replies; 8+ messages in thread From: dwsteele (@dwsteele) @ 2026-09-29 18:26 UTC (permalink / raw) To: pgaudit/pgaudit <noreply+pgaudit-pgaudit@github.com> Hi! Thanks for the report. You propose a fix but I don't see a PR. Can you open one with your proposed fix? ^ permalink raw [nested|flat] 8+ messages in thread
* Re: [pgaudit/pgaudit] issue #333: PG19: backend crash / "pgaudit stack is empty" from RI fast-path permission checks (after PostgreSQL commit 5aeb36f3273) @ 2026-09-29 18:26 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com> 6 siblings, 0 replies; 8+ messages in thread From: dwsteele (@dwsteele) @ 2026-09-29 18:26 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 #333: PG19: backend crash / "pgaudit stack is empty" from RI fast-path permission checks (after PostgreSQL commit 5aeb36f3273) @ 2026-09-29 18:26 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com> 6 siblings, 0 replies; 8+ messages in thread From: dwsteele (@dwsteele) @ 2026-09-29 18:26 UTC (permalink / raw) To: pgaudit/pgaudit <noreply+pgaudit-pgaudit@github.com> @dwsteele applied label "bug". ^ permalink raw [nested|flat] 8+ messages in thread
* Re: [pgaudit/pgaudit] issue #333: PG19: backend crash / "pgaudit stack is empty" from RI fast-path permission checks (after PostgreSQL commit 5aeb36f3273) @ 2026-09-29 18:28 ` "zjyzh (@zjyzh)" <noreply+zjyzh@github.com> 6 siblings, 0 replies; 8+ messages in thread From: zjyzh (@zjyzh) @ 2026-09-29 18:28 UTC (permalink / raw) To: pgaudit/pgaudit <noreply+pgaudit-pgaudit@github.com> ok sure I can put a PR later, thanks ^ permalink raw [nested|flat] 8+ messages in thread
* Re: [pgaudit/pgaudit] issue #333: PG19: backend crash / "pgaudit stack is empty" from RI fast-path permission checks (after PostgreSQL commit 5aeb36f3273) @ 2026-09-30 18:13 ` "zjyzh (@zjyzh)" <noreply+zjyzh@github.com> 6 siblings, 0 replies; 8+ messages in thread From: zjyzh (@zjyzh) @ 2026-09-30 18:13 UTC (permalink / raw) To: pgaudit/pgaudit <noreply+pgaudit-pgaudit@github.com> thanks, update the PR ^ permalink raw [nested|flat] 8+ messages in thread
* Re: [pgaudit/pgaudit] issue #333: PG19: backend crash / "pgaudit stack is empty" from RI fast-path permission checks (after PostgreSQL commit 5aeb36f3273) @ 2026-10-02 08:25 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com> 6 siblings, 0 replies; 8+ messages in thread From: dwsteele (@dwsteele) @ 2026-10-02 08:25 UTC (permalink / raw) To: pgaudit/pgaudit <noreply+pgaudit-pgaudit@github.com> @dwsteele closed this. ^ permalink raw [nested|flat] 8+ messages in thread
* Re: [pgaudit/pgaudit] issue #333: PG19: backend crash / "pgaudit stack is empty" from RI fast-path permission checks (after PostgreSQL commit 5aeb36f3273) @ 2026-10-02 08:25 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com> 6 siblings, 0 replies; 8+ messages in thread From: dwsteele (@dwsteele) @ 2026-10-02 08:25 UTC (permalink / raw) To: pgaudit/pgaudit <noreply+pgaudit-pgaudit@github.com> Closing since there is now a PR for this bug. ^ permalink raw [nested|flat] 8+ messages in thread
end of thread, other threads:[~2026-10-02 08:25 UTC | newest] Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2026-09-29 17:38 [pgaudit/pgaudit] issue #333: PG19: backend crash / "pgaudit stack is empty" from RI fast-path permission checks (after PostgreSQL commit 5aeb36f3273) "zjyzh (@zjyzh)" <noreply+zjyzh@github.com> 2026-09-29 18:26 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com> 2026-09-29 18:26 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com> 2026-09-29 18:26 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com> 2026-09-29 18:28 ` "zjyzh (@zjyzh)" <noreply+zjyzh@github.com> 2026-09-30 18:13 ` "zjyzh (@zjyzh)" <noreply+zjyzh@github.com> 2026-10-02 08:25 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com> 2026-10-02 08:25 ` "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