glibc qsort() vulnerability
Mats Kindahl <mats@timescale.com>
From: Mats Kindahl <mats@timescale.com>
To: pgsql-hackers@lists.postgresql.org
Date: 2024-02-06T14:06:26Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Use new overflow-safe integer comparison functions.
- 3b42bdb47169 17.0 landed
-
Introduce overflow-safe integer comparison functions.
- 6b80394781c8 17.0 landed
-
Replace calls to pg_qsort() with the qsort() macro.
- 5497daf3aa2a 17.0 landed
-
Switch over to using our own qsort() all the time, as has been proposed
- 6edd2b4a91bd 8.2.0 cited
Attachments
- 0001-Ensure-comparison-functions-are-transitive.patch (text/x-patch) patch 0001
Hi hackers, There is a bug in glibc's qsort() algorithm that runs the risk of creating an out-of-bounds error if the comparison function is not transitive, for example, if subtraction is used so that it can create an overflow. See https://packetstormsecurity.com/files/176931/glibc-qsort-Out-Of-Bounds-Read-Write.html I checked the existing functions in the latest version of Postgres source code and most are safe, but there were a few ones that could lead to overflow. I do not know if these can actually lead to problems, but better safe than sorry, so I created a patch to fix those few cases and add a comment to one case that was not clear that it could not overflow. Best wishes, Mats Kindahl, Timescale