[comp.os.minix] bug in chroot

leo@marco.UUCP (Matthias Pfaller) (07/27/90)

Yesterday I tried to use chroot(2).
my program looked like this
main()
{
	chroot("/mnt");
	execl("/bin/sh", "sh", (char *)0);
}
The program worked, and I had a sh with a changed root-directory.
but:
1. I could do a "cd /; cd .." and I was in the former root-directory
   is this behaviour correct?
2. The shell could no longer find commands. For example I could do
   'ls -l /bin/ls' and ls is found and displays /bin/ls.
   The displayed ls is that from /mnt/bin/ls, but the loaded one is
   that from the former /bin/ls. If I tried to start a program from
   /usr/bin (actually /mnt/usr/bin) the exec failed. I think the problem
   is, that mm only changes to the exec'ing process workingdirectory, but
   does not also change it's rootdirectory.

Has anyone fixed this allready?
	Matthias Pfaller (leo@verw.marco.de)

brucee@runxtsa.runx.oz.au (Bruce Evans) (08/05/90)

In article <441@alice.marco.UUCP> leo@marco.UUCP (Matthias Pfaller) writes:
>1. I could do a "cd /; cd .." and I was in the former root-directory
>   is this behaviour correct?

No. I think it will suffice to not follow the ".." link when the current
dicrectory is the root directory.

>2. [old binaries can still be executed]
>   I think the problem
>   is, that mm only changes to the exec'ing process workingdirectory, but
>   does not also change it's rootdirectory.

Yes. MM does a tell_fs(CHDIR, ...) to change the working directory.
do_chdir() in FS is kludged to switch from MM's workdir to the user's
workdir (and back) when called by MM. It also switches the effective uid,
but not the rootdir. I started to add code to switch to the user's rootdir
but stopped after realizing that this would zap the method of switching
back the workdir (by setting MM's workdir = MM's rootdir). But perhaps MM
doesn't need a workdir of its own.

The kludges are needed because MM is a server and the user task is not
visible to FS. Doing it "right" would require a lot of extra system calls
like special_open(user_nr, filename, mode), or overloading the bits in
the arguments as is already done for read() :-(.
-- 
Bruce Evans
Internet: brucee@runxtsa.runx.oz.au    UUCP: uunet!runxtsa.runx.oz.au!brucee
(My other address (evans@ditsyda.oz.au) no longer works)