Re: V2.1.57 hangs when overwriting libc

Jeff Millar (jeff@wa1hco.mv.com)
Sat, 11 Oct 1997 00:57:18 -0400


At 01:37 PM 10/10/97 +0200, you wrote:
>David Woodhouse <dwmw2@cam.ac.uk> writes:
>> olaf@bigred.inka.de said:
>>
>> > Wrong. You'll overwrite the code in the library which is mapped by
>> > about every process in the system with something else and trash
>> > running images - new libraries tend to have different code from old
>> > ones ;-)
>>
>> Indeed true. But he was only restoring from a backup, and the library
coming
>> out of the tar file was identical to the one in place.
>>
>While it was copied over, the library was quite a bit shorter.
>
>Tar opens its files with O_WRONLY|O_NONBLOCK|O_APPEND|O_CREAT|O_TRUNC,
>cp with O_WRONLY|O_CREAT|O_TRUNC. Therefore, at least the swap-in of
>unmodified pages from the library would fail.
>
>Presumably, the kernel should notice this and keep a copy of the
>MAP_PRIVATEd pages around somehow (presumably by reading them when they're
>about to be overwritten / the file is truncated), but currently it doesn't
>do that.

I had assumed, without much thought, that linux.ld.so read the lib into VM
when the first process referenced it and then additional processes shared
the address space. Under that assumption, overwriting the disk file with the
same data doesn't hang user processes.

Now I know ld.so mmap's the lib and that tar and cp begin with a truncate.
Does the truncate cause all the lib's pages in VM to get
removed/invalidated...
I guess yes because if it was a file, all the disk blocks would go back on
the free list. Your idea of replicating the privately mapped pages enables
the kernel to emulate my careless assumption.

But what's the best semantics for this, copy into memory or mmap?

Another question, my POSIX.1b book says SHARED and PRIVATE are mutually
exclusive, true for one process but what about several processes, do they have
to use the same mode? It seems that users of a lib would like to see PRIVATE
(maybe to allow horrors like self modifying lib code???), but overwriting
files implies a SHARED kind of operation.

There's more to think about here than I expected.

jeff
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: 2.6.2

mQBtAzC058EAAAEDALjanMr+BdlYckaBjfF1yFGBNBjd/tQzmV8897HWLbqfa6Tt
+M2ed4TnVwsa4JptFozJfIIlnLTO0ZcT1Fhq5Ba5oh/JAidkf2Rfu5uLAw3Smt1Y
GvZTMK8ZHGa6uYB5EQAFEbQGd2ExaGNv
=lEWl
-----END PGP PUBLIC KEY BLOCK-----