回复: 回复: Fix segfault while accessing half-initialized hash table in pgstat_shmem.c

From: Steven Niu <niushiji(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Mikhail Kot <mikhail(dot)kot(at)databricks(dot)com>, "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>, "to(at)myrrc(dot)dev" <to(at)myrrc(dot)dev>
Subject: 回复: 回复: Fix segfault while accessing half-initialized hash table in pgstat_shmem.c
Date: 2025-09-03 09:55:35
Message-ID: MN2PR15MB3021358255AE244C3D362247A701A@MN2PR15MB3021.namprd15.prod.outlook.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


________________________________________
发件人: Michael Paquier
已发送: 2025 年 9 月 03 日 星期三 17:43
收件人: Steven Niu
抄送: Mikhail Kot; pgsql-hackers(at)lists(dot)postgresql(dot)org; to(at)myrrc(dot)dev
主题: Re: 回复: Fix segfault while accessing half-initialized hash table in pgstat_shmem.c

On Wed, Sep 03, 2025 at 07:22:00AM +0000, Steven Niu wrote:
> So unless dsa_allocate() can ensure never returns InvalidDsaPointer,
> there is risk of SegV. In fact the function dsa_allocate() does
> return InvalidDsaPointer in some cases.
>
> So, maybe should we add pointer check in all places where dsa_get_address is called. Comments?

dsa_allocate() calls dsa_allocate_extended() without DSA_ALLOC_NO_OOM,
hence on allocation failure the code does a ereport(ERROR). It would
be a problem to not check the result if DSA_ALLOC_NO_OOM is used.

Thanks, Michael, you are correct.

The problem dealt with here is different, as far as I understand: we
set some data in shared memory without considering that the DSA
allocation could fail, leaving shared memory in an inconsistent state
when an allocation failure occurs. The problem is not in the
allocation failure in itself, but in the dependency that we have
between the state in shared memory and the allocation attempt for this
pgstats code path.
--
Michael

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrei Klychkov 2025-09-03 09:59:26 Re: [PATCH] Fix ALTER SYSTEM empty string bug for GUC_LIST_QUOTE parameters
Previous Message Antonin Houska 2025-09-03 09:55:34 Re: Adding REPACK [concurrently]