]> git.ipfire.org Git - thirdparty/haproxy.git/commit
BUG/MINOR: ring: free ring's allocated area not ring's usable area when using maps
authorAurelien DARRAGON <adarragon@haproxy.com>
Tue, 21 May 2024 09:13:46 +0000 (11:13 +0200)
committerAurelien DARRAGON <adarragon@haproxy.com>
Tue, 21 May 2024 09:42:35 +0000 (11:42 +0200)
commit0cfbeb1ae831e3cc9392ea242717ffbc0ff37e9f
tree6034dc07b66551c4aba7575f20dcfc8e6f5ef52f
parentd74ba7cc24490d1ef53112b9a89e32c49a731fb0
BUG/MINOR: ring: free ring's allocated area not ring's usable area when using maps

Since 40d1c84bf0 ("BUG/MAJOR: ring: free the ring storage not the ring
itself when using maps"), munmap() call for startup_logs's ring and
file-backed rings fails to work (EINVAL) and causes memory leaks during
process cleanup.

munmap() fails because it is called with the ring's usable area pointer
which is an offset from the underlying original memory block allocated
using mmap(). Indeed, ring_area() helper function was misused because
it didn't explicitly mention that the returned address corresponds to
the usable storage's area, not the allocated one.

To fix the issue, we add an explicit ring_allocated_area() helper to
return the allocated area for the ring, just like we already have
ring_allocated_size() for the allocated size, and we properly use both
the allocated size and allocated area to manipulate them using munmap()
and msync().

No backport needed.
include/haproxy/ring.h
src/errors.c
src/sink.c