unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Dumper issue, revisited; invalid realloc/free
@ 2015-02-04 17:57 Rich Felker
  2015-02-04 19:08 ` Eli Zaretskii
  2015-02-04 19:21 ` Eli Zaretskii
  0 siblings, 2 replies; 23+ messages in thread
From: Rich Felker @ 2015-02-04 17:57 UTC (permalink / raw)
  To: emacs-devel

Last summer I started a thread about the ever-recurring dumper
portability problem and how it was blocking use of emacs on systems
based on musl libc. Recently I've been working with several people
interested in getting emacs working on Alpine Linux and musl-based
Gentoo, and I made some progress working around the issue:

http://www.openwall.com/lists/musl/2015/02/03/1

(Note: there are a couple known bugs in the attached code.)

However, on further examination, the workaround I did is insufficient.
From what I can tell, emacs is making an additional assumption on
malloc: not only that malloc results will be contiguous with
data/bss/brk so they can be dumped, but also that calling free() or
realloc() on these objects in the new process after dumping is valid.
IMO this is utter nonsense, even with glibc or other widely-used
systems. It imposes an assumption that the heap structures in the
malloc version used at dump time match the heap structures in the
malloc version used at runtime, and that the runtime malloc is not
doing any sanity checks to catch and abort when a pointer into .data
is passed to realloc/free.

The simplest solution I can find is to make the affected free
functions (xrealloc, xfree, lisp_free, and lisp_align_free) check
whether their argument is in the range of data_start...initial_brk and
act as a nop (or in the case of xrealloc, allocate a new object
without freeing the old one) when this is the case. The check is
easily accomplished by saving initial_brk=sbrk(0) at startup (to be
lazy I did this with attribute((constructor)) but other approaches
might be preferred for an upstream fix. For xrealloc, since the old
size is not known, I simply estimate it as initial_brk-block. Copying
up to the min or this value and the new size should be safe, anyway.

Does this sound acceptable for upstream?

Rich



^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2015-02-05 18:43 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-04 17:57 Dumper issue, revisited; invalid realloc/free Rich Felker
2015-02-04 19:08 ` Eli Zaretskii
2015-02-04 19:13   ` Rich Felker
2015-02-04 19:22     ` Eli Zaretskii
2015-02-04 19:26     ` Eli Zaretskii
2015-02-04 20:34       ` Ken Brown
2015-02-05  1:31         ` Rich Felker
2015-02-05  3:25           ` Rich Felker
2015-02-05  3:48             ` Eli Zaretskii
2015-02-05  4:33               ` Rich Felker
2015-02-05 16:14                 ` Wolfgang Jenkner
2015-02-05 18:43                   ` Rich Felker
2015-02-04 19:21 ` Eli Zaretskii
2015-02-04 19:37   ` Rich Felker
2015-02-04 19:44     ` Eli Zaretskii
2015-02-04 19:49       ` Rich Felker
2015-02-04 19:54         ` Eli Zaretskii
2015-02-04 20:02           ` Rich Felker
2015-02-04 20:36             ` Eli Zaretskii
2015-02-04 20:08       ` Rich Felker
2015-02-04 20:40         ` Eli Zaretskii
2015-02-04 22:17           ` Rich Felker
2015-02-05  3:42             ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).