diff mbox series

[4/4] tunables: use mmap() instead of sbrk()

Message ID 20201128115945.42732-5-toiwoton@gmail.com
State New
Headers show
Series Improved ASLR | expand

Commit Message

Topi Miettinen Nov. 28, 2020, 11:59 a.m. UTC
Randomize the location of copy of tunable environment variable, at the
cost of losing up to 4095 bytes.
---
 elf/dl-tunables.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/elf/dl-tunables.c b/elf/dl-tunables.c
index 2ba2844075..4ca15eb30f 100644
--- a/elf/dl-tunables.c
+++ b/elf/dl-tunables.c
@@ -43,13 +43,16 @@  tunables_strdup (const char *in)
   size_t i = 0;
 
   while (in[i++] != '\0');
-  char *out = __sbrk (i);
+
+  int error = 0;
+  char *out = __mmap_noerrno (NULL, ALIGN_UP (i, GLRO(dl_pagesize)), PROT_READ | PROT_WRITE,
+			      MAP_ANONYMOUS | MAP_PRIVATE, -1, 0, &error);
 
   /* For most of the tunables code, we ignore user errors.  However,
      this is a system error - and running out of memory at program
      startup should be reported, so we do.  */
-  if (out == (void *)-1)
-    _dl_fatal_printf ("sbrk() failure while processing tunables\n");
+  if (error || out == MAP_FAILED)
+    _dl_fatal_printf ("mmap() failure while processing tunables\n");
 
   i--;