From: Manu <manuelreyesbravo@gmail.com>
To: pgsql-bugs@lists.postgresql.org
Cc: John Naylor <johncnaylorls@gmail.com>
Subject: Re: use-after-free in jsonb_set_lax()
Date: Thu, 15 Oct 2026 01:08:19 -0300
Message-ID: <179203729994.745011.10874872479146524148@gmail.com> (raw)
In-Reply-To: <CANWCAZY-PS=ev8TiiV1j=NoR2xLopEL8fDq0fyQZahHiP5b+Pw@mail.gmail.com>
References: <CANWCAZY-PS=ev8TiiV1j=NoR2xLopEL8fDq0fyQZahHiP5b+Pw@mail.gmail.com>
Hi John,
> I didn't find any other places in the code base with a similar bug,
> but of course I can't be certain.
I swept for siblings and found none. Of the 444 writes to
fcinfo->args[] in the backend, all go into a frame the function built
itself or an executor/planner frame, except 15 into a caller-supplied
frame; jsonb_set_lax is the only SQL-callable one among those. Const
args are written once at expression init in the expected places
(ExecInitFunc, the JSON constructors). Same on 14-17. A differential
multi-row vs per-row fuzz over the jsonb family (132k cases, cassert
and ASan) only ever fires in jsonb_set_lax, and is clean with v1.
One note on severity, in case it affects the classification: the
read-after-free reaches the output, not just control flow. Under ASan
the thread's repro does not crash; it silently returns {"a": null}
instead of {}, since the freed null stays in the per-tuple keeper
block. The 3-argument form jsonb_set_lax(col, path, NULL) over two
rows returns bytes of freed memory inside the result value (on a
cassert build); on a non-assert build that is reused heap, so it looks
able to disclose memory contents, not only crash or return wrong data.
Allocating ~5 kB per row turns it into a clean heap-use-after-free at
the !PG_ARGISNULL(2) shortcut. v1 is clean on all of it.
Regards,
Manu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: manuelreyesbravo@gmail.com, johncnaylorls@gmail.com
Subject: Re: use-after-free in jsonb_set_lax()
In-Reply-To: <179203729994.745011.10874872479146524148@gmail.com>
References: <CANWCAZY-PS=ev8TiiV1j=NoR2xLopEL8fDq0fyQZahHiP5b+Pw@mail.gmail.com> <179203729994.745011.10874872479146524148@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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