diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2016-07-20 09:16:49 +0200 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2016-07-20 09:49:41 +0200 |
commit | 63750fd4ed4ff8bb9b3ff8868d4e36e3422adb21 (patch) | |
tree | cff2b72f4d4fc257cc7cf73ec13777c768317328 /src/sysdep.c | |
parent | bf5ddded70c11edaf3514b25da27fc71cfb8e965 (diff) | |
download | emacs-63750fd4ed4ff8bb9b3ff8868d4e36e3422adb21.tar.gz |
Fix port to glibc 2.24 (pre-release) + ppc64
* src/callproc.c (child_setup): Use emacs_exec_file
so that ASLR is enabled in the child process.
* src/emacs.c: Move some personality details into sys/sysdep.c.
Do not include <sys/personality.h>.
(main): Disable ASLR earlier, so that we don’t chdir twice.
* src/lisp.h (disable_address_randomization): New decl.
* src/sysdep.c (disable_address_randomization)
[HAVE_PERSONALITY_ADDR_NO_RANDOMIZE]: Move personality details
here from emacs.c.
(emacs_exec_file): New function.
Diffstat (limited to 'src/sysdep.c')
-rw-r--r-- | src/sysdep.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/sysdep.c b/src/sysdep.c index 56142a55cdf..16541735f03 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -129,6 +129,48 @@ static const int baud_convert[] = 1800, 2400, 4800, 9600, 19200, 38400 }; +#ifdef HAVE_PERSONALITY_ADDR_NO_RANDOMIZE +# include <sys/personality.h> + +/* Disable address randomization in the current process. Return true + if addresses were randomized but this has been disabled, false + otherwise. */ +bool +disable_address_randomization (void) +{ + bool disabled = false; + int pers = personality (0xffffffff); + disabled = (! (pers & ADDR_NO_RANDOMIZE) + && 0 <= personality (pers | ADDR_NO_RANDOMIZE)); + return disabled; +} +#endif + +/* Execute the program in FILE, with argument vector ARGV and environ + ENVP. Return an error number if unsuccessful. This is like execve + except it reenables ASLR in the executed program if necessary, and + on error it returns an error number rather than -1. */ +int +emacs_exec_file (char const *file, char *const *argv, char *const *envp) +{ +#ifdef HAVE_PERSONALITY_ADDR_NO_RANDOMIZE + int pers = getenv ("EMACS_HEAP_EXEC") ? personality (0xffffffff) : -1; + bool change_personality = 0 <= pers && pers & ADDR_NO_RANDOMIZE; + if (change_personality) + personality (pers & ~ADDR_NO_RANDOMIZE); +#endif + + execve (file, argv, envp); + int err = errno; + +#ifdef HAVE_PERSONALITY_ADDR_NO_RANDOMIZE + if (change_personality) + personality (pers); +#endif + + return err; +} + /* If FD is not already open, arrange for it to be open with FLAGS. */ static void force_open (int fd, int flags) |