From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: bug#33174: 27.0.50; Dump fails on GNU/Linux ppc64le Date: Sun, 11 Nov 2018 22:39:56 -0800 Organization: UCLA Computer Science Department Message-ID: References: <39df62a1-58fb-0e5c-88a6-3eaae4e865d4@cs.ucla.edu> <9fbbce6a-ca72-e4e2-1456-49e146542896@cs.ucla.edu> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------F7CD2D096B092AF83B9A0320" X-Trace: blaine.gmane.org 1542004749 5503 195.159.176.226 (12 Nov 2018 06:39:09 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 12 Nov 2018 06:39:09 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 Cc: 33174-done@debbugs.gnu.org To: Thomas Fitzsimmons Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Nov 12 07:39:05 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gM5sG-0001Jm-UB for geb-bug-gnu-emacs@m.gmane.org; Mon, 12 Nov 2018 07:39:05 +0100 Original-Received: from localhost ([::1]:45019 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gM5uM-0001tn-OO for geb-bug-gnu-emacs@m.gmane.org; Mon, 12 Nov 2018 01:41:14 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45648) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gM5uF-0001sW-Pf for bug-gnu-emacs@gnu.org; Mon, 12 Nov 2018 01:41:09 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gM5uA-0007rX-OC for bug-gnu-emacs@gnu.org; Mon, 12 Nov 2018 01:41:07 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:42712) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gM5uA-0007qt-8l for bug-gnu-emacs@gnu.org; Mon, 12 Nov 2018 01:41:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gM5uA-0003xh-4Z for bug-gnu-emacs@gnu.org; Mon, 12 Nov 2018 01:41:02 -0500 Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-To: bug-gnu-emacs@gnu.org Resent-Date: Mon, 12 Nov 2018 06:41:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 33174 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Mail-Followup-To: 33174@debbugs.gnu.org, eggert@cs.ucla.edu, fitzsim@fitzsim.org Original-Received: via spool by 33174-done@debbugs.gnu.org id=D33174.154200480915131 (code D ref 33174); Mon, 12 Nov 2018 06:41:01 +0000 Original-Received: (at 33174-done) by debbugs.gnu.org; 12 Nov 2018 06:40:09 +0000 Original-Received: from localhost ([127.0.0.1]:46964 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gM5tI-0003vw-0z for submit@debbugs.gnu.org; Mon, 12 Nov 2018 01:40:09 -0500 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:47498) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gM5tE-0003uw-Ol for 33174-done@debbugs.gnu.org; Mon, 12 Nov 2018 01:40:05 -0500 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id B4B84160098; Sun, 11 Nov 2018 22:39:58 -0800 (PST) Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id SrnO9TMwPjp4; Sun, 11 Nov 2018 22:39:57 -0800 (PST) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 7342E160079; Sun, 11 Nov 2018 22:39:57 -0800 (PST) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id r15nyekULMxy; Sun, 11 Nov 2018 22:39:57 -0800 (PST) Original-Received: from [192.168.1.9] (cpe-23-242-74-103.socal.res.rr.com [23.242.74.103]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 2F6DC16006C; Sun, 11 Nov 2018 22:39:57 -0800 (PST) In-Reply-To: Content-Language: en-US X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:152313 Archived-At: This is a multi-part message in MIME format. --------------F7CD2D096B092AF83B9A0320 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Thomas Fitzsimmons wrote: > Actually, EMACS_HEAP_EXEC is true! OK, thanks, that explains things. I installed the first attached patch to the emacs-26 branch as a quick hack to work around the problem, and the second attached patch to the master branch to come up with a better way to address the underlying issue that doesn't involve fiddling with environment variables. Please let us know if this doesn't work for your platform, as I've tested this only on x86-64. --------------F7CD2D096B092AF83B9A0320 Content-Type: text/x-patch; name="0001-Work-around-dumping-bug-on-GNU-Linux-ppc64le.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Work-around-dumping-bug-on-GNU-Linux-ppc64le.patch" >From 1d79c2ebd9bd9aa36586e57463502373c0296d11 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 11 Nov 2018 22:34:46 -0800 Subject: [PATCH] Work around dumping bug on GNU/Linux ppc64le Problem reported by Thomas Fitzsimmons (Bug#33174). Do not merge to master, as we have a better fix there. * src/Makefile.in (emacs$(EXEEXT)): (bootstrap-emacs$(EXEEXT)): Unset EMACS_HEAP_EXEC before invoking temacs. --- src/Makefile.in | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Makefile.in b/src/Makefile.in index 6ed8f3cc91..53c18e7ac0 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -534,6 +534,7 @@ emacs$(EXEEXT): ifeq ($(CANNOT_DUMP),yes) ln -f temacs$(EXEEXT) $@ else + unset EMACS_HEAP_EXEC; \ LC_ALL=C $(RUN_TEMACS) -batch $(BUILD_DETAILS) -l loadup dump ifneq ($(PAXCTL_dumped),) $(PAXCTL_dumped) $@ @@ -739,6 +740,7 @@ bootstrap-emacs$(EXEEXT): ifeq ($(CANNOT_DUMP),yes) ln -f temacs$(EXEEXT) $@ else + unset EMACS_HEAP_EXEC; \ $(RUN_TEMACS) --batch $(BUILD_DETAILS) --load loadup bootstrap ifneq ($(PAXCTL_dumped),) $(PAXCTL_dumped) emacs$(EXEEXT) -- 2.17.1 --------------F7CD2D096B092AF83B9A0320 Content-Type: text/x-patch; name="0001-Fix-dumping-on-GNU-Linux-ppc64le.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Fix-dumping-on-GNU-Linux-ppc64le.patch" >From c14eab222c5208ec0650292c3771a3ee632fdb0d Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 11 Nov 2018 22:18:47 -0800 Subject: [PATCH] Fix dumping on GNU/Linux ppc64le Problem reported by Thomas Fitzsimmons (Bug#33174). * src/emacs.c (main): Adjust to sysdep.c changes. * src/sysdep.c (exec_personality): New static var. (disable_address_randomization): Remove, replacing with ... (maybe_disable_address_randomization): ... this new function. Do not set or use an environment variable; use a command-line argument instead, and set the new static var. Migrate the emacs.c personality-change code to here, where it belongs. (emacs_exec_file): Simplify by using new static var. --- src/emacs.c | 23 +---------------- src/lisp.h | 7 +++-- src/sysdep.c | 73 +++++++++++++++++++++++++++++++++------------------- 3 files changed, 53 insertions(+), 50 deletions(-) diff --git a/src/emacs.c b/src/emacs.c index 07df191035..512174d562 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -706,28 +706,7 @@ main (int argc, char **argv) dumping = false; #endif - /* True if address randomization interferes with memory allocation. */ -# ifdef __PPC64__ - bool disable_aslr = true; -# else - bool disable_aslr = dumping; -# endif - - if (disable_aslr && disable_address_randomization () - && !getenv ("EMACS_HEAP_EXEC")) - { - /* Set this so the personality will be reverted before execs - after this one, and to work around an re-exec loop on buggy - kernels (Bug#32083). */ - xputenv ("EMACS_HEAP_EXEC=true"); - - /* Address randomization was enabled, but is now disabled. - Re-execute Emacs to get a clean slate. */ - execvp (argv[0], argv); - - /* If the exec fails, warn and then try anyway. */ - perror (argv[0]); - } + argc = maybe_disable_address_randomization (dumping, argc, argv); #ifndef CANNOT_DUMP might_dump = !initialized; diff --git a/src/lisp.h b/src/lisp.h index eb6762678c..383d61274c 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -4325,9 +4325,12 @@ struct tty_display_info; /* Defined in sysdep.c. */ #ifdef HAVE_PERSONALITY_ADDR_NO_RANDOMIZE -extern bool disable_address_randomization (void); +extern int maybe_disable_address_randomization (bool, int, char **); #else -INLINE bool disable_address_randomization (void) { return false; } +INLINE void +maybe_disable_address_randomization (bool dumping, int argc, char **argv) +{ +} #endif extern int emacs_exec_file (char const *, char *const *, char *const *); extern void init_standard_fds (void); diff --git a/src/sysdep.c b/src/sysdep.c index 7a0c8a8ab8..ddcb594f66 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -150,22 +150,52 @@ static const int baud_convert[] = #ifdef HAVE_PERSONALITY_ADDR_NO_RANDOMIZE # include -/* 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) +/* If not -1, the personality that should be restored before exec. */ +static int exec_personality; + +/* 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) { - int pers = personality (0xffffffff); - if (pers < 0) - return false; - int desired_pers = pers | ADDR_NO_RANDOMIZE; + /* Undocumented Emacs option used only by this function. */ + static char const aslr_disabled_option[] = "--__aslr-disabled"; - /* Call 'personality' twice, to detect buggy platforms like WSL - where 'personality' always returns 0. */ - return (pers != desired_pers - && personality (desired_pers) == pers - && personality (0xffffffff) == desired_pers); + if (argc < 2 || strcmp (argv[1], aslr_disabled_option) != 0) + { + bool disable_aslr = dumping; +# ifdef __PPC64__ + disable_aslr = true; +# endif + exec_personality = disable_aslr ? personality (0xffffffff) : -1; + if (exec_personality & ADDR_NO_RANDOMIZE) + exec_personality = -1; + if (exec_personality != -1 + && personality (exec_personality | ADDR_NO_RANDOMIZE) != -1) + { + char **newargv = malloc ((argc + 2) * sizeof *newargv); + if (newargv) + { + /* Invoke self with undocumented option. */ + newargv[0] = argv[0]; + newargv[1] = (char *) aslr_disabled_option; + memcpy (&newargv[2], &argv[1], argc * sizeof *newargv); + execvp (newargv[0], newargv); + } + + /* If malloc or execvp fails, warn and then try anyway. */ + perror (argv[0]); + free (newargv); + } + } + else + { + /* Our earlier incarnation already disabled ASLR. */ + argc--; + memmove (&argv[1], &argv[2], argc * sizeof *argv); + } + + return argc; } #endif @@ -177,21 +207,12 @@ 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); + if (exec_personality != -1) + personality (exec_personality); #endif execve (file, argv, envp); - int err = errno; - -#ifdef HAVE_PERSONALITY_ADDR_NO_RANDOMIZE - if (change_personality) - personality (pers); -#endif - - return err; + return errno; } /* If FD is not already open, arrange for it to be open with FLAGS. */ -- 2.17.1 --------------F7CD2D096B092AF83B9A0320--