pgsql: Make stack depth check work with asan's use-after-return

From: Andres Freund <andres(at)anarazel(dot)de>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Make stack depth check work with asan's use-after-return
Date: 2026-05-28 16:21:36
Message-ID: E1wSdUF-001WYl-2z@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Make stack depth check work with asan's use-after-return

With address sanitizer's stack-use-after-return check, stack variables are
moved to heap allocations, to allow to detect references to the memory at a
later time. That broke our stack-depth check, which is why we had to disable
detect_stack_use_after_return in CI. Luckily __builtin_frame_address() works
correctly, even under asan, so use that.

We started using __builtin_frame_address() with de447bb8e6fb, however as of
that commit we just used it for the stack base address, not for the value to
compare to the base address. Now we use it for both.

When building without __builtin_frame_address() support, we continue to use
stack variables for the stack depth determination.

Reviewed-by: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Discussion: https://postgr.es/m/2kk4z4odvuyrg7qlwjd7ft4eron4cle4btb33v4qatgsdkayir@gj6e62rgsel4
Backpatch-through: 14

Branch
------
REL_18_STABLE

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

Modified Files
--------------
.cirrus.tasks.yml | 2 +-
src/backend/utils/misc/stack_depth.c | 22 +++++++++++++++++++---
2 files changed, 20 insertions(+), 4 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Álvaro Herrera 2026-05-28 18:32:05 pgsql: Improve REPACK (CONCURRENTLY) error messages some more
Previous Message Álvaro Herrera 2026-05-28 14:53:51 pgsql: Fix some minor issues in repack ereport()s