>From 9ac586928bbef16b572bcb34bfcbcb5515c2335a Mon Sep 17 00:00:00 2001
From: Paul Eggert
Date: Tue, 19 Nov 2019 18:23:01 -0800
Subject: [PATCH] Make .pdmp file more reproducible
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Problem reported by Ulrich Müller
and diagnosed by Andreas Schwab
.
* src/sysdep.c (maybe_disable_address_randomization):
Disable ASLR if any kind of dumping, instead of merely if
unexec dumping. Omit first arg for simplicity; all uses changed.
---
src/emacs.c | 3 +--
src/lisp.h | 4 ++--
src/sysdep.c | 7 +++++--
3 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/src/emacs.c b/src/emacs.c
index 21a05d337e..8a6e34deda 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -1054,8 +1054,7 @@ main (int argc, char **argv)
load_pdump (argc, argv);
#endif
- argc = maybe_disable_address_randomization (
- will_dump_with_unexec_p (), argc, argv);
+ argc = maybe_disable_address_randomization (argc, argv);
#if defined GNU_LINUX && defined HAVE_UNEXEC
if (!initialized)
diff --git a/src/lisp.h b/src/lisp.h
index 1d25add928..e0ae2c4262 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -4576,10 +4576,10 @@ #define DAEMON_RUNNING (w32_daemon_event != INVALID_HANDLE_VALUE)
/* Defined in sysdep.c. */
#ifdef HAVE_PERSONALITY_ADDR_NO_RANDOMIZE
-extern int maybe_disable_address_randomization (bool, int, char **);
+extern int maybe_disable_address_randomization (int, char **);
#else
INLINE int
-maybe_disable_address_randomization (bool dumping, int argc, char **argv)
+maybe_disable_address_randomization (int argc, char **argv)
{
return argc;
}
diff --git a/src/sysdep.c b/src/sysdep.c
index aa18ee22fd..e34ab2eb58 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -158,14 +158,17 @@ #define ULLONG_MAX TYPE_MAXIMUM (unsigned long long int)
/* Try to disable randomization if the current process needs it and
does not appear to have it already. */
int
-maybe_disable_address_randomization (bool dumping, int argc, char **argv)
+maybe_disable_address_randomization (int argc, char **argv)
{
/* Undocumented Emacs option used only by this function. */
static char const aslr_disabled_option[] = "--__aslr-disabled";
if (argc < 2 || strcmp (argv[1], aslr_disabled_option) != 0)
{
- bool disable_aslr = dumping;
+ /* If dumping via unexec, ASLR must be disabled, as otherwise
+ data may be scattered and undumpable as a simple executable.
+ If pdumping, disabling ASLR makes the .pdmp file reproducible. */
+ bool disable_aslr = will_dump_p ();
# ifdef __PPC64__
disable_aslr = true;
# endif
--
2.23.0