]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix some possibly latent bugs in slab.c
authorDavid Rowley <drowley@postgresql.org>
Thu, 1 Sep 2022 07:23:44 +0000 (19:23 +1200)
committerDavid Rowley <drowley@postgresql.org>
Thu, 1 Sep 2022 07:23:44 +0000 (19:23 +1200)
commitf249f1026f71bd8f2e820f1895b745d59fab041e
tree1d7e4a7d9199dfde01c43816ef1fe8f4cbefdec9
parentdc565a4597e9412a731960a4df092637e7a833c7
Fix some possibly latent bugs in slab.c

Primarily, this fixes an incorrect calculation in SlabCheck which was
looking in the wrong byte for the sentinel check.  The reason that we've
never noticed this before in the form of a failing sentinel check is
because the pre-check to this always fails because all current core users
of slab contexts have a chunk size which is already MAXALIGNed, therefore
there's never any space for the sentinel byte.  It is possible that an
extension needs to use a slab context and if they do with a chunk size
that's not MAXALIGNed, then they'll likely get errors about overwritten
sentinel bytes.

Additionally, this patch changes various calculations which are being done
based on the sizeof(SlabBlock).  Currently, sizeof(SlabBlock) is a
multiple of 8, therefore sizeof(SlabBlock) is the same as
MAXALIGN(sizeof(SlabBlock)), however, if we were to ever have to add any
fields to that struct as part of a bug fix, then SlabAlloc could end up
returning a non-MAXALIGNed pointer.  To be safe, let's ensure we always
MAXALIGN sizeof(SlabBlock) before using it in any calculations.

This patch has already been applied to master in d5ee4db0e.

Diagnosed-by: Tomas Vondra, Tom Lane
Author: Tomas Vondra, David Rowley
Discussion: https://postgr.es/m/CAA4eK1%2B1JyW5TiL%3DyV-3Uq1CrfnTyn0Xrk5uArt31Z%3D8rgPhXQ%40mail.gmail.com
Backpatch-through: 10
src/backend/utils/mmgr/slab.c