You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1.3 KiB

  1. commit 7e751a3c24a7021075fb298025c4a1ce98a5b049
  2. Author: Olivier Houchard <cognet@ci0.org>
  3. Date: Sun Oct 21 01:33:11 2018 +0200
  4. BUG/MEDIUM: pools: Fix the usage of mmap()) with DEBUG_UAF.
  5. When mapping memory with mmap(), we should use a fd of -1, not 0. 0 may
  6. work on linux, but it doesn't work on FreeBSD, and probably other OSes.
  7. It would be nice to backport this to 1.8 to help debugging there.
  8. (cherry picked from commit 62975a7740cba4bdaf1c096dd246feba854d2410)
  9. Signed-off-by: Willy Tarreau <w@1wt.eu>
  10. diff --git a/include/common/memory.h b/include/common/memory.h
  11. index a2237da5..da0641de 100644
  12. --- a/include/common/memory.h
  13. +++ b/include/common/memory.h
  14. @@ -186,12 +186,13 @@ static inline void pool_free_area(void *area, size_t __maybe_unused size)
  15. * some padding is added, the area's start address is copied at the end of the
  16. * padding to help detect underflows.
  17. */
  18. +#include <errno.h>
  19. static inline void *pool_alloc_area(size_t size)
  20. {
  21. size_t pad = (4096 - size) & 0xFF0;
  22. void *ret;
  23. - ret = mmap(NULL, (size + 4095) & -4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
  24. + ret = mmap(NULL, (size + 4095) & -4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
  25. if (ret == MAP_FAILED)
  26. return NULL;
  27. if (pad >= sizeof(void *))