On Tue, 2008-01-29 at 14:36 +0300, Oleg Nesterov wrote:
Yes. While most programs don't need this it is still very important for
some critical programs to be able to unmap the executable and thereby
allow unmounting the filesystem. Unfortunately, I don't have a confirmed
specific example for you. A wild guess: some distro install or live CDs
might use this.
So, rather than what ld-linux.so does now:
$ /lib/ld-linux.so.2 /bin/sleep 100 &
[1] 12645
$ cat /proc/12645/maps
08048000-0804b000 r-xp 00000000 03:04 606421 /bin/sleep
0804b000-0804c000 rw-p 00003000 03:04 606421 /bin/sleep
80000000-8001c000 r-xp 00000000 03:04 688355 /lib/ld-2.7.so
8001c000-8001e000 rw-p 0001b000 03:04 688355 /lib/ld-2.7.so
have ld-linux.so copy the mmap'd executable areas and then unmap the
originals. So it would look roughly like:
0804c000-0804f000 r-xp 00000000 03:04 606421
0804f000-08050000 rw-p 00003000 03:04 606421
80000000-8001c000 r-xp 00000000 03:04 688355 /lib/ld-2.7.so
8001c000-8001e000 rw-p 0001b000 03:04 688355 /lib/ld-2.7.so
Then there'd be no need to have the extra reference counting this patch
adds.
I think these approaches could subtly break existing userspace
applications which don't already use these techniques. Furthermore, I
wonder if some applications may wish to unmount 'everything'. This means
there may be no mount that's acceptable to pin by either copying to or
using a modified ld-linux.so.
Fixing the problem in userspace with these techniques also requires a
non-trivial audit of userspace. There could easily be two tasks that
have little or no apparent relation to each other. One does the unmap
trick and the other expects to be able to unmount. The first would then
need to be modified to cp the executable to a suitable location or
utilize a modified ld-linux.so.
I'd be happy to submit a patch removing the extra reference counting if
there's a way to avoid breaking userspace or if there's consensus that
breaking userspace this way is acceptable.
Sure.
OK. I'll post a patch to remove the spinlock and replace it with
mmap_sem.
OK, I'll leave it unless something better comes to mind.
Thanks for taking a look at this patch and asking questions.
Cheers,
-Matt Helsley
--