mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Undoing chroot?
@ 2001-01-26 18:31 Paul Powell
  2001-01-26 18:54 ` alex
  2001-01-27  2:47 ` Chris Wedgwood
  0 siblings, 2 replies; 4+ messages in thread
From: Paul Powell @ 2001-01-26 18:31 UTC (permalink / raw)
  To: linux-kernel

Hello,

I have a linux bootable CD which executes a custom
init.  The job of init is to figure out on which
device the CD is located.  After finding the CD, init
mounts the device and executes a CHROOT to set the
root directory to the CD.

After I'm done I'd like to umount the CD and then
eject it by sending an IOCTL eject command.  But since
I executed a CHROOT I can't umount the CD, umount
complains that the device is busy.

So how do you reverse a CHROOT?

BTW, I use an initrd image and init is a C program,
not a script.

Thanks

__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - Buy the things you want at great prices. 
http://auctions.yahoo.com/
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

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

* Re: Undoing chroot?
  2001-01-26 18:31 Undoing chroot? Paul Powell
@ 2001-01-26 18:54 ` alex
  2001-01-27  2:47 ` Chris Wedgwood
  1 sibling, 0 replies; 4+ messages in thread
From: alex @ 2001-01-26 18:54 UTC (permalink / raw)
  To: Paul Powell; +Cc: linux-kernel

On Fri, Jan 26, 2001 at 10:31:40AM -0800, Paul Powell wrote:
> I have a linux bootable CD which executes a custom
> init.  The job of init is to figure out on which
> device the CD is located.  After finding the CD, init
> mounts the device and executes a CHROOT to set the
> root directory to the CD.
> 
> After I'm done I'd like to umount the CD and then
> eject it by sending an IOCTL eject command.  But since
> I executed a CHROOT I can't umount the CD, umount
> complains that the device is busy.
> 
> So how do you reverse a CHROOT?

By definition, a chroot() is not undoable.  There are strong security reasons 
for this (chroot() is often used to create protected "jails" for untrusted 
code.  If the code could just undo the chroot() it wouldn't be very useful).  
However, chroot() is per-process, therefore what you probably want to do is 
fork(), then do a chroot() in the child and do whatever you want to do there, 
when you're done with the CD, exit the child, and have the parent eject it.

-alex
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

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

* Re: Undoing chroot?
  2001-01-26 18:31 Undoing chroot? Paul Powell
  2001-01-26 18:54 ` alex
@ 2001-01-27  2:47 ` Chris Wedgwood
  1 sibling, 0 replies; 4+ messages in thread
From: Chris Wedgwood @ 2001-01-27  2:47 UTC (permalink / raw)
  To: Paul Powell; +Cc: linux-kernel

On Fri, Jan 26, 2001 at 10:31:40AM -0800, Paul Powell wrote:

    So how do you reverse a CHROOT?

move the prison walls inside of your cell then walk away:

as root:

  mkdir("blah");
  chroot("blah");
  chdir("../../../../../../");

sort of thing



  --cw
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

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

* Re: Undoing chroot?
       [not found] <0C01A29FBAE24448A792F5C68F5EA47D04E323@nasdaq.ms.ensim.com>
@ 2001-01-26 22:15 ` Paul Menage
  0 siblings, 0 replies; 4+ messages in thread
From: Paul Menage @ 2001-01-26 22:15 UTC (permalink / raw)
  To: Paul Powell; +Cc: linux-kernel

In article <0C01A29FBAE24448A792F5C68F5EA47D04E323@nasdaq.ms.ensim.com>,
you write:
>
>So how do you reverse a CHROOT?
>

Assuming your process doesn't drop its root privileges, before you do
the initial chroot() you could do:

old_root = open("/", O_RDONLY);

Then later do

fchdir(oldroot);
chroot(".");

But the cleaner and more portable solution is probably to have a child
process executing inside the chroot, and have its parent eject the CD
when the child exists.

Paul
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

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

end of thread, other threads:[~2001-01-27  2:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-01-26 18:31 Undoing chroot? Paul Powell
2001-01-26 18:54 ` alex
2001-01-27  2:47 ` Chris Wedgwood
     [not found] <0C01A29FBAE24448A792F5C68F5EA47D04E323@nasdaq.ms.ensim.com>
2001-01-26 22:15 ` Paul Menage

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®