Re: Use-after-free issue in postgres_fdw

From: Etsuro Fujita <etsuro(dot)fujita(at)gmail(dot)com>
To: Matheus Alcantara <matheusssilv97(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Michael Paquier <michael(at)paquier(dot)xyz>
Subject: Re: Use-after-free issue in postgres_fdw
Date: 2026-03-21 11:44:47
Message-ID: CAPmGK17nv3GMr5k14M0tBf=Gri-TGyRHS1apYme4apiYWHkYKA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Matheus,

On Sat, Mar 21, 2026 at 1:00 AM Matheus Alcantara
<matheusssilv97(at)gmail(dot)com> wrote:
> On 19/03/26 11:56, Etsuro Fujita wrote:
> > I think the root cause is that it is too early to free the PGconn in
> > pgfdw_reject_incomplete_xact_state_change() even if the connection is
> > in a state where we cannot use it any further; I think we should delay
> > that until abort cleanup (ie, pgfdw_xact_callback()). Attached is a
> > patch for that.
>
> IIUC, with this patch, disconnect_pg_server() will be called at
> pgfdw_xact_callback() via pgfdw_reset_xact_state() when the top level
> transaction is rollback right?

That is right.

> I've tested and it seems to fix the issue, when "close c1;" is
> executed "conn" points to a valid connection pointer and this
> connection is properly disconnected when the top level transactions is
> rollback.
>
> This issue is reproducible on v14, so I think that we need a back-port.

Yes, I am thinking of back-patching the fix to all supported versions,
if no objections.

Thanks for testing/reviewing the patch!

Best regards,
Etsuro Fujita

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Etsuro Fujita 2026-03-21 11:56:41 Re: Use-after-free issue in postgres_fdw
Previous Message Etsuro Fujita 2026-03-21 11:40:50 Re: Use-after-free issue in postgres_fdw