Re: Security question: "Text file busy" overwriting executables but not shared libraries?

From: Jamie Lokier (
Date: Mon Oct 15 2001 - 06:35:06 EST

Richard Gooch wrote:
> > There are applications (GCC comes to mind) which are using mmap() to
> > read files now because it is measurably faster than read(), for
> > sufficiently large source files.
> So? MAP_PRIVATE is just fine for these. The simple solution if you
> care about an edit in the middle of a compile is to have your editor
> write a new file and do an atomic rename. No half-and-half data
> problems, and the VM logic is kept simple (well, relative to what we
> have now;-).

This does not work. Example:

  1. JamieEmacs loads file using MAP_PRIVATE.
  2. Something else writes to the file.
  3. Scroll to the bottom of the file in JamieEmacs. It displays some
     of the newly written data, though not all of it.

--> Wrong editor semantics.

Note that the something else which modifies the file in step 2 is not an
editor written especially to cooperate with JamieEmacs. So it does not
do renaming -- why should it? You might have just loaded
/var/log/messages into JamieEmacs, for example, and syslog is the
program in step 2.

What you need is read() or an equivalent. I don't know of a
memory-efficient equivalent to read. MAP_PRIVATE doesn't do it because
you have to dirty every page before you can be sure that file
modifications won't change your view of the data, and the dirtying
creates just as many page duplicates as read() does.

-- Jamie
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

This archive was generated by hypermail 2b29 : Mon Oct 15 2001 - 21:00:57 EST