[4/4] tunables: use mmap() instead of sbrk()
Commit Message
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(-)
@@ -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--;