]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: pools: detect() when munmap() fails in UAF mode
authorWilly Tarreau <w@1wt.eu>
Mon, 13 Oct 2025 17:22:31 +0000 (19:22 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 13 Oct 2025 17:22:31 +0000 (19:22 +0200)
Better check that munmap() always works, otherwise it means we might
have miscalculated an address, and if it fails silently, it will eat
all the memory extremely quickly. Let's add a BUG_ON() on munmap's
return.

include/haproxy/pool-os.h

index 016070822c3245fbd9a59cbdab026b8cf3b2bdf3..59bb41b944677d6822302b4e2e8aeaea1948739b 100644 (file)
@@ -97,7 +97,8 @@ static inline void pool_free_area_uaf(void *area, size_t size)
        if (pad >= sizeof(void *) && *(void **)(area - sizeof(void *)) != area)
                ABORT_NOW();
 
-       munmap(area - pad, (size + 4095) & -4096);
+       /* better know immediately if an address calculation was wrong! */
+       BUG_ON(munmap(area - pad, (size + 4095) & -4096) == -1);
 }
 
 #endif /* _HAPROXY_POOL_OS_H */