Re: Fix crash when non-creator being an iteration on shared radix tree

From: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
To: John Naylor <johncnaylorls(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Fix crash when non-creator being an iteration on shared radix tree
Date: 2024-12-18 17:59:44
Message-ID: CAD21AoCAEr-d8n1neXcmvNHHgLZ_9QVEPB_YmOM+AS+9ohfHig@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Dec 17, 2024 at 11:12 PM John Naylor <johncnaylorls(at)gmail(dot)com> wrote:
>
> On Wed, Dec 18, 2024 at 12:49 AM Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com> wrote:
> >
> > Hi,
> >
> > I found that a server crashes due to a null-pointer-dereference if a
> > process attached to the shared radix tree begins an iteration on it,
> > because we don't create the memory context for iter_context at
> > RT_ATTACH(). There is no code in the core causing this crash in the
> > core since in parallel vacuum, the leader process always creates the
> > shared radix tree and begins the iteration. However it could happen in
> > external extensions. I've attached the patch to fix it and I think it
> > should be backpatched to v17.
>
> +1 in general, but I wonder if instead the iter_context should be
> created within RT_BEGIN_ITERATE -- I imagine that would have less
> duplication and would be as safe, but I haven't tried it. Is there
> some reason not to do that?

I agree that it has less duplication. There is no strong reason I
didn't do that. I just didn't want to check 'if (!tree->iter_context)'
in RT_BEGIN_ITERATE for simplicity. I've changed the patch
accordingly.

Regards,

--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com

Attachment Content-Type Size
v2-0001-radixtree-Fix-crash-when-non-creator-begins-an-it.patch application/octet-stream 3.3 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Ranier Vilela 2024-12-18 18:23:20 Re: Can rs_cindex be < 0 for bitmap heap scans?
Previous Message Tom Lane 2024-12-18 17:49:46 Re: Regression tests fail on OpenBSD due to low semmns value