]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: shctx: make sure to keep all blocks aligned
authorWilly Tarreau <w@1wt.eu>
Fri, 21 Feb 2020 12:45:58 +0000 (13:45 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 21 Feb 2020 12:45:58 +0000 (13:45 +0100)
The blocksize and the extra field are not necessarily aligned on a
machine word. This can result in crashing an align-sensitive machine
when initializing the shctx area. Let's round both sizes up to a pointer
size to make this safe everywhere.

This fixes issue #512. This should be backported as far as 1.8.

src/shctx.c

index fe1b74a7e6bb91d7333a784910f838de60c6d553..ae9cc1f1bc2ff01ca24a6340f000c6cf2ba83b58 100644 (file)
@@ -308,6 +308,10 @@ int shctx_init(struct shared_context **orig_shctx, int maxblocks, int blocksize,
        if (maxblocks <= 0)
                return 0;
 
+       /* make sure to align the records on a pointer size */
+       blocksize = (blocksize + sizeof(void *) - 1) & -sizeof(void *);
+       extra     = (extra     + sizeof(void *) - 1) & -sizeof(void *);
+
 #ifndef USE_PRIVATE_CACHE
        if (shared)
                maptype = MAP_SHARED;