Re: Fix unsigned underflow in inject_cached_message

From: Tatsuo Ishii <ishii(at)postgresql(dot)org>
To: koshino(at)sraoss(dot)co(dot)jp
Cc: pgpool-hackers(at)lists(dot)postgresql(dot)org, emond(dot)papegaaij(at)gmail(dot)com
Subject: Re: Fix unsigned underflow in inject_cached_message
Date: 2026-08-17 06:18:07
Message-ID: 20260817.151807.1592223911077560886.ishii@postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgpool-hackers

> I have reviewed the patch(011-inject-cached-message-underflow) from Emond.
> It has also passed all regression tests.
>
> This patch modifies the packet length validation in inject_cached_message to prevent
> a session crash caused by an unsigned integer underflow.
>
> Previously, the logic determined whether to process a query cache message by checking
> if the packet length minus its header size was greater than zero(if ((ntohl(len) - sizeof(len)) > 0)).
>
> However, this evaluation method introduced a critical vulnerability under unsigned arithmetic rules.
>
> When a corrupt packet with a payload length shorter than the header size is processed,
> the subtraction underflows into a massive positive integer,
> bypassing the guard and forcing a fatal memory allocation failure that terminates the session.
> In our local test environment, injecting a short packet successfully reproduced this exact behavior,
> causing a memory context allocation crash.
>
> The updated logic changes the condition to a direct comparison
> before subtraction(if (ntohl(len) > (uint32) sizeof(len))),
> ensuring that invalid short packets are securely blocked and the session remains stable,
> which proves the fix is highly valid.
>
> Thank you Emond.

I have looked into the patch. It looks good to me.

Regards,
--
Tatsuo Ishii
SRA OSS K.K.
English: http://www.sraoss.co.jp/index_en/
Japanese:http://www.sraoss.co.jp

In response to

Responses

Browse pgpool-hackers by date

  From Date Subject
Next Message Tatsuo Ishii 2026-08-17 06:24:32 Re: Delimit query-cache key to prevent collisions
Previous Message Tatsuo Ishii 2026-08-17 06:13:53 Re: Delimit query-cache key to prevent collisions