diff options
| author | Paul Eggert | 2016-07-20 09:16:49 +0200 |
|---|---|---|
| committer | Paul Eggert | 2016-07-20 09:49:41 +0200 |
| commit | 63750fd4ed4ff8bb9b3ff8868d4e36e3422adb21 (patch) | |
| tree | cff2b72f4d4fc257cc7cf73ec13777c768317328 /src/sysdep.c | |
| parent | bf5ddded70c11edaf3514b25da27fc71cfb8e965 (diff) | |
| download | emacs-63750fd4ed4ff8bb9b3ff8868d4e36e3422adb21.tar.gz emacs-63750fd4ed4ff8bb9b3ff8868d4e36e3422adb21.zip | |
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[] = | |||
| 129 | 1800, 2400, 4800, 9600, 19200, 38400 | 129 | 1800, 2400, 4800, 9600, 19200, 38400 |
| 130 | }; | 130 | }; |
| 131 | 131 | ||
| 132 | #ifdef HAVE_PERSONALITY_ADDR_NO_RANDOMIZE | ||
| 133 | # include <sys/personality.h> | ||
| 134 | |||
| 135 | /* Disable address randomization in the current process. Return true | ||
| 136 | if addresses were randomized but this has been disabled, false | ||
| 137 | otherwise. */ | ||
| 138 | bool | ||
| 139 | disable_address_randomization (void) | ||
| 140 | { | ||
| 141 | bool disabled = false; | ||
| 142 | int pers = personality (0xffffffff); | ||
| 143 | disabled = (! (pers & ADDR_NO_RANDOMIZE) | ||
| 144 | && 0 <= personality (pers | ADDR_NO_RANDOMIZE)); | ||
| 145 | return disabled; | ||
| 146 | } | ||
| 147 | #endif | ||
| 148 | |||
| 149 | /* Execute the program in FILE, with argument vector ARGV and environ | ||
| 150 | ENVP. Return an error number if unsuccessful. This is like execve | ||
| 151 | except it reenables ASLR in the executed program if necessary, and | ||
| 152 | on error it returns an error number rather than -1. */ | ||
| 153 | int | ||
| 154 | emacs_exec_file (char const *file, char *const *argv, char *const *envp) | ||
| 155 | { | ||
| 156 | #ifdef HAVE_PERSONALITY_ADDR_NO_RANDOMIZE | ||
| 157 | int pers = getenv ("EMACS_HEAP_EXEC") ? personality (0xffffffff) : -1; | ||
| 158 | bool change_personality = 0 <= pers && pers & ADDR_NO_RANDOMIZE; | ||
| 159 | if (change_personality) | ||
| 160 | personality (pers & ~ADDR_NO_RANDOMIZE); | ||
| 161 | #endif | ||
| 162 | |||
| 163 | execve (file, argv, envp); | ||
| 164 | int err = errno; | ||
| 165 | |||
| 166 | #ifdef HAVE_PERSONALITY_ADDR_NO_RANDOMIZE | ||
| 167 | if (change_personality) | ||
| 168 | personality (pers); | ||
| 169 | #endif | ||
| 170 | |||
| 171 | return err; | ||
| 172 | } | ||
| 173 | |||
| 132 | /* If FD is not already open, arrange for it to be open with FLAGS. */ | 174 | /* If FD is not already open, arrange for it to be open with FLAGS. */ |
| 133 | static void | 175 | static void |
| 134 | force_open (int fd, int flags) | 176 | force_open (int fd, int flags) |