]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: pools: Fix the usage of mmap()) with DEBUG_UAF.
authorOlivier Houchard <cognet@ci0.org>
Sat, 20 Oct 2018 23:33:11 +0000 (01:33 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 21 Oct 2018 03:43:33 +0000 (05:43 +0200)
When mapping memory with mmap(), we should use a fd of -1, not 0. 0 may
work on linux, but it doesn't work on FreeBSD, and probably other OSes.

It would be nice to backport this to 1.8 to help debugging there.

include/common/memory.h

index 5fde4bcddc7eee6236df03abe3867e8f33101ee0..2301e3ad5386b7bd9e9b02e5d5caf1cd54f77e0c 100644 (file)
@@ -394,12 +394,13 @@ static inline void pool_free_area(void *area, size_t __maybe_unused size)
  * some padding is added, the area's start address is copied at the end of the
  * padding to help detect underflows.
  */
+#include <errno.h>
 static inline void *pool_alloc_area(size_t size)
 {
        size_t pad = (4096 - size) & 0xFF0;
        void *ret;
 
-       ret = mmap(NULL, (size + 4095) & -4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
+       ret = mmap(NULL, (size + 4095) & -4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
        if (ret == MAP_FAILED)
                return NULL;
        if (pad >= sizeof(void *))