[Libguestfs] missing chdir before chroot in guestfsd
Richard W.M. Jones
rjones at redhat.com
Mon Aug 19 09:07:17 UTC 2013
On Sun, Aug 18, 2013 at 02:29:15PM +0200, Olaf Hering wrote:
>
> daemon.c does just a chroot, without chdir. The result is that pwd does not
> work correctly (it causes fs/dcache.c:prepend_unreachable() to add the
> unreachable string). A workaround is to add "cd /" before each sh command.
>
> ><fs> mount /dev/sda2 /
> ><fs> sh "cd / ; chroot / ; /bin/pwd"
> /
>
> ><fs> sh "/bin/pwd"
> (unreachable)/
>
> ><fs> sh "cd / ; /bin/pwd"
> /
>
> This untested change may fix it.
>
> ===================
> --- libguestfs-1.20.10.orig/daemon/guestfsd.c
> +++ libguestfs-1.20.10/daemon/guestfsd.c
> @@ -879,7 +879,11 @@ commandrvf (char **stdoutput, char **std
> close (stdin_fd[PIPE_READ]);
> close (stdin_fd[PIPE_WRITE]);
>
> - if (chroot (sysroot) == -1) {
> + if (chdir (sysroot) == -1) {
> + perror ("chdir");
> + _exit (EXIT_FAILURE);
> + }
> + if (chroot (".") == -1) {
> perror ("chroot");
> _exit (EXIT_FAILURE);
> }
If you look at the upstream code, this has been fixed, or at
least, the code is quite different. See:
commit 2aa731e7c441581f0d72bcd06e9431b92931466a
Author: Matthew Booth <mbooth at redhat.com>
Date: Thu Dec 13 15:22:39 2012 +0000
daemon: Remove redundant fork in commandrvf
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-p2v converts physical machines to virtual machines. Boot with a
live CD or over the network (PXE) and turn machines into KVM guests.
http://libguestfs.org/virt-v2v
More information about the Libguestfs
mailing list