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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Make stack depth check work with asan's use-after-return
Date: 2026-05-27 13:54:51
Message-ID: 465155.1779890091@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Andres Freund <andres(at)anarazel(dot)de> writes:
> The reason for that breakage is that with the stack-use-after-return logic,
> stack variables are moved to heap allocations, to allow to detect references
> to the memory at a later time. That breaks 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.
> I think we should backpatch this. I'd be worried about using
> __builtin_frame_address(), but we already do, for the base address of the
> stack.

+1. It was a little weird that we adopted __builtin_frame_address()
to measure the location of the stack bottom but not the stack top.
So I think this is good cleanup even if ASAN weren't forcing it.

I might write the comments a bit differently, in particular I suggest
changing

- * Compute distance from reference point to my local variables
+ * Compute distance from reference point to my stack frame

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Previous Message Andres Freund 2026-05-27 13:23:13 Make stack depth check work with asan's use-after-return