Re: [Bug] Heap Use After Free in parallel_vacuum_reset_dead_items Function

From: John Naylor <johncnaylorls(at)gmail(dot)com>
To: Vallimaharajan G <vallimaharajan(dot)gs(at)zohocorp(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, "zlabs-cstore(at)zohocorp(dot)com" <zlabs-cstore(at)zohocorp(dot)com>, pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, pgsql-bugs <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: [Bug] Heap Use After Free in parallel_vacuum_reset_dead_items Function
Date: 2024-11-26 09:53:45
Message-ID: CANWCAZYJe4vya4taNFdqK2dx6q3VmyxyL7V+8DBy62YnaQUeiA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

On Tue, Nov 26, 2024 at 1:58 AM Vallimaharajan G <
vallimaharajan(dot)gs(at)zohocorp(dot)com> wrote:
>
> Hi Developers,
> We have discovered a bug in the parallel_vacuum_reset_dead_items
function in PG v17.2. Specifically:
>
> TidStoreDestroy(dead_items) frees the dead_items pointer.
> The pointer is reinitialized using TidStoreCreateShared().
> However, the code later accesses the freed pointer instead of the newly
reinitialized pvs->dead_items, as seen in these lines:
>
> pvs->shared->dead_items_dsa_handle =
dsa_get_handle(TidStoreGetDSA(dead_items));
> pvs->shared->dead_items_handle = TidStoreGetHandle(dead_items);

Thanks for the report! I don't see any immediate evidence of deleterious
effects, but it's still sloppy. To reduce risk going forward, I think we
should always access this pointer via the struct rather than a separate
copy, quick attempt attached.

(BTW, it's normally discouraged to cross-post to different lists. Either
one is fine in this case.)

--
John Naylor
Amazon Web Services

Attachment Content-Type Size
v2-fix-parallel-vacuum.patch text/x-patch 3.2 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Иван Ситников 2024-11-26 10:33:57 Re: BUG #18724: High data disk utilization during log writing
Previous Message Thomas Munro 2024-11-26 02:25:40 Re: Build failure with GCC 15 (defaults to -std=gnu23)

Browse pgsql-hackers by date

  From Date Subject
Next Message Matthias van de Meent 2024-11-26 10:18:06 Re: Potential ABI breakage in upcoming minor releases
Previous Message Tatsuo Ishii 2024-11-26 09:25:13 Re: Doc: typo in config.sgml