Giter Club home page Giter Club logo

fakechroot's Introduction

fakechroot

logo

Home | Download | Documentation | ChangeLog | Development | ToDo | Links

Travis CI Salsa GitLab CI

What is it

fakechroot runs a command in an environment were is additional possibility to use chroot(8) command without root privileges. This is useful for allowing users to create own chrooted environment with possibility to install another packages without need for root privileges.

How does it work

fakechroot replaces some libc library functions (chroot(2), open(2), etc.) by ones that simulate the effect of being called with root privileges.

These wrapper functions are in a shared library libfakechroot.so which is loaded through the LD_PRELOAD mechanism of the dynamic loader. (See ld.so(8))

In fake chroot you can install Debian bootstrap with debootstrap command. In this environment you can use i.e. apt-get(8) command to install another packages. You don't need a special privileges and you can run it from common user's account.

An example session

$ id
uid=1000(dexter) gid=1000(dexter) groups=1000(dexter)

$ fakechroot fakeroot debootstrap sid /tmp/sid
I: Retrieving Release
I: Retrieving Release.gpg
I: Checking Release signature
...
I: Base system installed successfully.

$ fakechroot fakeroot chroot /tmp/sid apt-get install -q hello
Reading package lists...
Building dependency tree...
Reading state information...
The following NEW packages will be installed:
  hello
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 57.4 kB of archives.
After this operation, 558 kB of additional disk space will be used.
Get:1 http://ftp.us.debian.org/debian/ sid/main hello amd64 2.8-4 [57.4 kB]
Fetched 57.4 kB in 0s (127 kB/s)
Selecting previously unselected package hello.
(Reading database ... 24594 files and directories currently installed.)
Unpacking hello (from .../archives/hello_2.8-4_amd64.deb) ...
Processing triggers for man-db ...
Processing triggers for install-info ...
Setting up hello (2.8-4) ...

$ fakechroot chroot /tmp/sid hello
Hello, world!

Where is it used

fakechroot is mainly used as:

  • a supporter for debirf, DEBian on Initial Ram Filesystem
  • a variant of debootstrap, the tool which can set up new Debian or Ubuntu system

fakechroot had found another purposes:

  • to be a part of Klik application installer as kfakechroot project
  • to be a supporter for pbuilder building system
  • to be a supporter for Apport retracer
  • to be a supporter for libguestfs tools for accessing and modifying virtual machine disk images
  • to be a supporter for febootstrap, the tool which can set up new Fedora system
  • to be a part of cuntubuntu - Ubuntu for Android without root
  • to be a supporter for selenium-chroot setup

fakechroot's People

Contributors

andrewgregory avatar cicku avatar dex4er avatar gagern avatar gh2o avatar glebfm avatar hobbitalastair avatar jwilk avatar rbmj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fakechroot's Issues

system's passwd/group leaks into chrooted environment

At work, we've been using fakechroot+fakeroot for quite some time in a script to build a rootfs out of debian packages (similar to debootstrap).

We recently started adding postinst scriptlets to some of our packages to create users and/or groups when the packages are are installed, but this is not working reliably. For example, we've found that if the user or group already exists on the system, it is not added to the chroot's /etc/passwd or /etc/group files.

A simplified use-case to demonstrate the problem is 'fakechroot fakeroot chroot </path/to/chroot> getent passwd'. This doesn't output entries from the chroot's /etc/passwd file, instead it outputs entries from the system (including entries from NIS, even though the chroot's /etc/nsswitch.conf file is configured to only use the /etc/passwd file).

Our build servers are running Ubuntu 14.04. I've tried the system fakechroot, as well as one built from the current head of the master branch (f8dc2fc).

Basic issue getting chroot call superseded by preloaded library

Let me start by saying, this is not a bug report. I am having an issue and currently assume it is my fault and would like some help. If there is a better place to ask this question, just tell me.

I am currently trying to use fakechroot for debootstrapping squeeze for arm.

fakeroot -s fakechroot.save -f /home/corbinlc/upload/usr/bin/faked-sysv -l /home/corbinlc/upload/usr/lib/libfakeroot-sysv.so fakechroot -l /home/corbinlc/upload/usr
/lib/libfakechroot.so /home/corbinlc/upload/usr/sbin/debootstrap --verbose --arch=a
rmel --variant=fakechroot squeeze /home/corbinlc/upload/newRoot ftp.us.debian.org

Stage one goes well and I can see what appears to be all the normal files unpacked in the appropriate places.

But, when it gets around to trying to actually do a chroot call I get one of two responses:

  1. if chroot is in my PATH, I get:
    chroot: cannot change root directory to newRoot: Operation not permitted

  2. if not, I get:
    chroot: not found

It is like as if libfakechroot is not being preloaded. So, I dug a little deeper. If I check LD_PRELOAD, it is infact set and it is set to
/home/corbinlc/upload/usr/lib/libfakechroot.so
as expected.

fakechroot.so conflicts with jemalloc

In fakechroot env, run

LD_PRELOAD=libjemalloc.so:$LD_PRELOAD ls 

will cause a dead lock. Stacktrace like this:

#0  0x00007fd9b4e4df2c in __lll_lock_wait ()                                                          [17/1875]
   from /home/users/wangweibing/ubuntu2/lib/x86_64-linux-gnu/libpthread.so.0
#1  0x00007fd9b4e49657 in _L_lock_909 ()
   from /home/users/wangweibing/ubuntu2/lib/x86_64-linux-gnu/libpthread.so.0
#2  0x00007fd9b4e49480 in pthread_mutex_lock ()
   from /home/users/wangweibing/ubuntu2/lib/x86_64-linux-gnu/libpthread.so.0
#3  0x00007fd9b5a6d621 in ?? () from /home/users/wangweibing/ubuntu2/usr/lib/x86_64-linux-gnu/libjemalloc.so
#4  0x00007fd9b5a6f4ed in calloc ()
   from /home/users/wangweibing/ubuntu2/usr/lib/x86_64-linux-gnu/libjemalloc.so
#5  0x00007fd9b4c3c690 in ?? () from /home/users/wangweibing/ubuntu2/lib/x86_64-linux-gnu/libdl.so.2
#6  0x00007fd9b4c3c198 in dlsym () from /home/users/wangweibing/ubuntu2/lib/x86_64-linux-gnu/libdl.so.2
#7  0x00007fd9b585c484 in ?? ()
   from /home/users/wangweibing/ubuntu2/usr/lib/x86_64-linux-gnu/fakechroot/libfakechroot.so
#8  0x00007fd9b585f41c in readlink ()
   from /home/users/wangweibing/ubuntu2/usr/lib/x86_64-linux-gnu/fakechroot/libfakechroot.so
#9  0x00007fd9b5a6cdf0 in ?? () from /home/users/wangweibing/ubuntu2/usr/lib/x86_64-linux-gnu/libjemalloc.so
#10 0x00007fd9b5a6d691 in ?? () from /home/users/wangweibing/ubuntu2/usr/lib/x86_64-linux-gnu/libjemalloc.so
#11 0x00007fd9b5a6ee6d in malloc ()
   from /home/users/wangweibing/ubuntu2/usr/lib/x86_64-linux-gnu/libjemalloc.so
#12 0x00007fd9b5852ad1 in fakechroot_init ()
   from /home/users/wangweibing/ubuntu2/usr/lib/x86_64-linux-gnu/fakechroot/libfakechroot.so
#13 0x00007fd9b585c67d in ?? ()
   from /home/users/wangweibing/ubuntu2/usr/lib/x86_64-linux-gnu/fakechroot/libfakechroot.so
#14 0x00007fd9b5860d1b in statfs64 ()

This is because fakechroot calls malloc from jemalloc.so, but jemalloc calls readlink from fakechroot.so to read conf, eventually cause a dead lock.

Failure trying to run, possibly the package base-passwd is at fault

On Ubuntu 16.04.3 LTS (Xenial Xerus):

$ sudo apt install fakechroot
$ fakechroot fakeroot debootstrap jessie /tmp/jessie

(...)
I: Extracting liblzma5...
I: Extracting zlib1g...
I: Installing core packages...
W: Failure trying to run: chroot /tmp/jessie dpkg --force-depends --install /var/cache/apt/archives/base-passwd_3.5.37_amd64.deb
W: See /tmp/jessie/debootstrap/debootstrap.log for details (possibly the package base-passwd is at fault)

$ cat /tmp/jessie/debootstrap/debootstrap.log

gpgv: Signature made Sat Jul 22 12:45:43 2017 CEST using RSA key ID 46925553
gpgv: Good signature from "Debian Archive Automatic Signing Key (7.0/wheezy) <[email protected]>"
gpgv: Signature made Sat Jul 22 12:45:43 2017 CEST using RSA key ID 2B90D010
gpgv: Good signature from "Debian Archive Automatic Signing Key (8/jessie) <[email protected]>"
gpgv: Signature made Sat Jul 22 12:48:59 2017 CEST using RSA key ID 518E17E1
gpgv: Good signature from "Jessie Stable Release Key <[email protected]>"
dpkg: warning: parsing file '/var/lib/dpkg/status' near line 5 package 'dpkg':
 missing description
dpkg: warning: parsing file '/var/lib/dpkg/status' near line 5 package 'dpkg':
 missing architecture
Selecting previously unselected package base-passwd.
(Reading database ... 0 files and directories currently installed.)
Preparing to unpack .../base-passwd_3.5.37_amd64.deb ...
Unpacking base-passwd (3.5.37) ...
dpkg: base-passwd: dependency problems, but configuring anyway as you requested:
 base-passwd depends on libc6 (>= 2.8); however:
  Package libc6 is not installed.
 base-passwd depends on libdebconfclient0 (>= 0.145); however:
  Package libdebconfclient0 is not installed.

Setting up base-passwd (3.5.37) ...
/usr/bin/perl: error while loading shared libraries: libperl.so.5.20: cannot open shared object file: No such file or directory
dpkg: error processing package base-passwd (--install):
 subprocess installed post-installation script returned error exit status 127
Errors were encountered while processing:
 base-passwd

Possibly related to #24. Blocking AppImageCommunity/pkg2appimage#284.

Optional symlink extension behavior?

For the symlink syscall, I have a scenario in which I don't want fakechroot to extend the path being symlinked to (absolute or relative), and just want it to create the symlink as requested by the program being run under fakeroot. Would it be possible to make the current prefix behavior optional, or is there a better way to do what I want?

The scenario is for rootless building of disk images and certain tools need to run in a chroot and create an (absolute) symlink. So I run the tools under fakechroot and they work fine, except that the symlinks they create in the target filesystem now have my fake root path prepended to them, so I need to go fix them up before I can make my disk image.

Does that make sense?

symlinks to absolute path resolving to parent root filesystem

Hi,

I am not sure if anybody's faced this problem but a quick google did not yield any results. Here is my issue: inside the chroot, I have /usr/bin/env pointing to /bin/env. Anything that depends on /usr/bin/env fails to find /bin/env because the parent root filesystem does NOT have /bin/env.

e.g. /usr/bin/hg contains this line at the top:

!/usr/bin/env python

It just fails to run. As soon as I create /bin/env in the parent rootfs, it starts to work!

So, chroot is escaping to the parent.

In fact, what I notice is that any symlink to an absolute path resolves in the parent root, whereas my expectation was that it would resolve within the chroot. This breaks almost everything (think Gentoo chroot and how it has wrappers managed using symlinks in that chroot) for doing any kind of builds inside the chroot. The good thing is the that parent root is not Gentoo, so the setup never works. Otherwise, it would be a silent bug.

Deadlock in `malloc` if multi-threaded

In gagern/selenium-chroot#1 (comment) I've been encountering deadlocks when running firefox under fakechroot. Apparently the call from malloc to readlink("/etc/malloc.conf") appeared to be particularly problematic. I guess it would make sense to explicitely treat /etc/malloc.conf as non-existing, and move the corresponding settings into the MALLOC_OPTIONS environment variable if they exist at all.

different glibc versions

I'm running Debian wheezy and want to run an Arch Linux pacstrap.

$ fakechroot fakeroot chroot arch/
/bin/bash: relocation error: /home/markuman/arch/usr/lib/libc.so.6: symbol _dl_find_dso_for_object, version GLIBC_PRIVATE not defined in file ld-linux-x86-64.so.2 with link time reference

And the other way around, I'm running Arch Linux and want to run a Debian Wheezy debootstrap

$ fakechroot fakeroot chroot root/
/usr/bin/chroot: /home/markus/wheezy/root/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.14' not found (required by /usr/bin/chroot)
/usr/bin/chroot: /home/markus/wheezy/root/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.14' not found (required by /usr/lib/libfakeroot/libfakeroot.so)
/usr/bin/chroot: /home/markus/wheezy/root/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.14' not found (required by /usr/lib/libfakeroot/fakechroot/libfakechroot.so)

Any ideas how to handle those different glibc versions?

env.fakeroot.sh can't handle some variables, causing invalid test failures

Valid, or at least possible, environment variable names, are a superset of valid shell variable names. If the environment has a variable named, say, FOO-BAR (note the dash in the middle, which prevents it being a valid shell identifier), then most(?) shells (both dash and bash, at least) will not support removing them from the environment by means of the unset command. Which, of course, is what env.fakeroot.sh does.

A correct fix is probably honestly not worth the work it might cost. However, if you redirect stderr/stdout to /dev/null during just the unset loop, you can at least prevent shell complaints about the problem from being misinterpreted during test runs and causing falsely negative test results. Just be careful not to solve it in such a way that the unsets are evaluated in a subshell. :)

Path expansion before stat(...)

I get different behaviors with and without fakechroot, when issuing a stat on a non-traversable path:

case 1

~$ sudo /usr/sbin/chroot /
/# test -e __non_existent_dir__/../usr; echo $?
1

case 2

~$ /usr/bin/fakechroot /usr/sbin/chroot /
/$ test -e __non_existent_dir__/../usr; echo $?
0

test -e (in test.c from coreutils) is calling stat(...) without any expansion.

I believe that calling dedotdot(...) from expand_chroot_path in stat.c is responsible for this.

An ugly patch on the fly using a new environment variable FAKECHROOT_NODEDOTDOT fixes the issue:

--- src/dedotdot.c  2021-01-02 17:36:49.967851000 +0000
+++ src/dedotdot.c  2021-01-07 21:27:09.163077450 +0000
@@ -51,9 +51,11 @@
  */
 
 #include <string.h>
+#include <stdlib.h>
 
 LOCAL void dedotdot(char * file)
 {
+    if (getenv("FAKECHROOT_NODEDOTDOT")) return;
     char c, *cp, *cp2;
     int l;

#46 seems related ...

Fakechroot fakeroot chroot somedir ls /.. lists files in parent of somedir

I don't think this should work.

I'm not sure if it is a fakechroot or fakeroot issue.

!/bin/bash

SAND=sandpit

remove old sandpit

rm -r $SAND

create a new chroot environment

mkdir $SAND
for f in /*; do
ln -s $f $SAND/
done

make a file outside of sandpit

echo hello > q.q

in chroot, copy file from outside sandpit

fakechroot fakeroot chroot $SAND cp /../q.q r.r

did it work?

diff -s q.q $SAND/r.r

YES!

Fails on Archlinux

LANG=c fakechroot fakeroot chroot debian-9                                                                                                       :(
/usr/bin/chroot.fakechroot: line 105: 25612 Illegal instruction     (core dumped) env -u FAKECHROOT_BASE_ORIG FAKECHROOT_CMD_ORIG= LD_LIBRARY_PATH="$fakechroot_chroot_paths" FAKECHROOT_BASE="$fakechroot_chroot_base" "$fakechroot_chroot_chroot" "${@:1:$(($fakechroot_chroot_n - 1))}" "${fakechroot_chroot_newroot#$FAKECHROOT_BASE_ORIG}" "${@:$(($fakechroot_chroot_n + 1))}"

fakechroot and ldconfig

Hello.
I try to use fakechroot with my prebuild rootfs like this:

fakechroot
fakeroot
chroot /tmp/chroot/ /bin/sh

But after running any applications which used different from my host system libs I obtain error:

# ping
ping: error while loading shared libraries: libnettle.so.6: cannot open shared object file: No such file or directory

It seems that fakechroot uses ld.so.cache from host systems instead of rootfs.
Has anything method to run application inside rootfs with own environment?
Thank you.

fakechroot assumes /usr/bin/echo

fakechroot does a detect to see if its libraries are loaded. It tries to run /usr/bin/echo (hardcoded path). It is usually safe to assume echo is in /usr/bin, but I just ran into a case where echo is someplace entirely different and fakechroot failed.

The solution is to run which echo in place of /usr/bin/echo so that the fakechroot script finds echo in PATH.

NOTE: you can't just use "echo" in place of "/usr/bin/echo" because echo is often built into the shell and thus will never load any LD_PRELOAD libraries.

glibc version incompatibilities

I am trying to bootstrap an archlinux system but I keep receiving the following error. The error still remains if I enable the -s flag of fakechroot:

/usr/bin/pacman: relocation error: /tmp/target/usr/lib/libc.so.6: symbol _dl_find_dso_for_object, version GLIBC_PRIVATE not defined in file ld-linux-x86-64.so.2 with link time reference

Do you have any suggestions?

LD_PRELOAD is set too early when running chroot

LD_PRELOAD is set in fakechroot.sh line 256. If we run chroot, then the script will invoke chroot.fakechroot.sh. Then commands in chroot.fakechroot.sh such as sed and env will be run with LD_PRELOAD=libfakechroot.so. If we set our own ELF loader at the same time, which can be imported in fakechroot.sh line 131, then the commands mentioned above, which should run with system loader, will run with FAKECHROOT_ELFLOADER as their loader (libfakechroot.so invokes it), and may lead to segment fault.

I believe we should defer setting LD_PRELOAD and LD_LIBRARY_PATH to chroot.fakechroot.sh when running chroot and likely in other wrapper scripts.

No such file or directory

When setting the working directory to a symlinked directory within the fakechroot, which was created outside of the chroot, and then trying to list or open a file results in a "No such file or directory" error.

man fakechroot suggests that symlinks can be from the outside, so I expect this to work.

You can provide symlinks to the outside. The symlink have to be created before chroot is called. It can be useful for accessing the real /proc and /dev directory ...

Any help on this will be greatly appreciated.


Environment:

ubuntu 16.04
fakechroot 2.18
fakeroot 1.20.2
chroot 8.25

Steps to replicate:

Initial setup

base="$(pwd)"
root="$base/root"

# variant is fakechroot since sudo not possible
fakechroot fakeroot debootstrap --variant=fakechroot --arch=amd64 xenial $root

cd $root
ln -s $base app # see note below
cd ..

The following work as expected, when the working directory is / within the chroot.

fakechroot fakeroot chroot $root ls -ahl
fakechroot fakeroot chroot $root ls -ahl /app/
fakechroot fakeroot chroot $root sh -c 'echo "TEST" > /app/test'
cat test  # sanity check
fakechroot fakeroot chroot $root cat /app/test

The following fail when changing into /app with "No such file or directory":

fakechroot fakeroot chroot $root sh -c 'cd /app; ls -ahl'
fakechroot fakeroot chroot $root sh -c 'cd /app; cat test'

Note: The parent directory of the chroot's root directory is symlinked as app into the chroot's root directory, which may seem peculiar but unfortunately this is a environmental constraint I don't have control over.

Testsuite assumes /usr/sbin/chroot path

The path to chroot is checked configure but the testsuite assumes that it is still in /usr/sbin.

The following files need adjusted to use the path found during configure:
test/testtree.sh test/t/chroot.t

Any plans to make new release?

It is already almost two years since last release and in git repo is ATM commited +1k commits.
It would be really good to make new release .. please :)

Example fails

Host system: Arch Linux with 3.14 kernel

$ mkdir /tmp/fake1
$ id
uid=1000(pirj) gid=100(users) groups=100(users)
$ fakechroot fakeroot debootstrap sid /tmp/fake1
I: Keyring file not available at /usr/share/keyrings/debian-archive-keyring.gpg; switching to https mirror https://mirrors.kernel.org/debian
I: Retrieving Release
...
I: Installing core packages...
W: Failure trying to run: chroot /tmp/fake1 dpkg --force-depends --install /var/cache/apt/archives/base-passwd_3.5.37_i386.deb
W: See /tmp/fake1/debootstrap/debootstrap.log for details (possibly the package base-passwd is at fault)

In log file:

dpkg: warning: parsing file '/var/lib/dpkg/status' near line 5 package 'dpkg':
 missing description
dpkg: warning: parsing file '/var/lib/dpkg/status' near line 5 package 'dpkg':
 missing architecture
dpkg-deb: /usr/lib/liblzma.so.5: no version information available (required by dpkg-deb)
Selecting previously unselected package base-passwd.
(Reading database ... 0 files and directories currently installed.)
Preparing to unpack .../base-passwd_3.5.37_i386.deb ...
Unpacking base-passwd (3.5.37) ...
dpkg-deb: /usr/lib/liblzma.so.5: no version information available (required by dpkg-deb)
dpkg: base-passwd: dependency problems, but configuring anyway as you requested:
 base-passwd depends on libc6 (>= 2.8); however:
  Package libc6 is not installed.
 base-passwd depends on libdebconfclient0 (>= 0.145); however:
  Package libdebconfclient0 is not installed.

Setting up base-passwd (3.5.37) ...
update-passwd: error while loading shared libraries: libdebconfclient.so.0: cannot open shared object file: No such file or directory
update-passwd: error while loading shared libraries: libdebconfclient.so.0: cannot open shared object file: No such file or directory
dpkg: error processing package base-passwd (--install):
 subprocess installed post-installation script returned error exit status 127
Errors were encountered while processing:
 base-passwd

Same debootstrap sid /tmp/fakeX is working fine under root.

$ fakechroot fakeroot debootstrap --include=libc6,libdebconfclient0 sid /tmp/fake2 doesn't make much difference:

dpkg: warning: parsing file '/var/lib/dpkg/status' near line 5 package 'dpkg':
 missing description
dpkg: warning: parsing file '/var/lib/dpkg/status' near line 5 package 'dpkg':
 missing architecture
dpkg-deb: /usr/lib/liblzma.so.5: no version information available (required by dpkg-deb)
Selecting previously unselected package base-passwd.
(Reading database ... 0 files and directories currently installed.)
Preparing to unpack .../base-passwd_3.5.37_i386.deb ...
Unpacking base-passwd (3.5.37) ...
dpkg-deb: /usr/lib/liblzma.so.5: no version information available (required by dpkg-deb)
dpkg: base-passwd: dependency problems, but configuring anyway as you requested:
 base-passwd depends on libc6 (>= 2.8); however:
  Package libc6 is not installed.
 base-passwd depends on libdebconfclient0 (>= 0.145); however:
  Package libdebconfclient0 is not installed.

Setting up base-passwd (3.5.37) ...
update-passwd: error while loading shared libraries: libdebconfclient.so.0: cannot open shared object file: No such file or directory
update-passwd: error while loading shared libraries: libdebconfclient.so.0: cannot open shared object file: No such file or directory
dpkg: error processing package base-passwd (--install):
 subprocess installed post-installation script returned error exit status 127
Errors were encountered while processing:
 base-passwd

Changing user within chrooted environment

There is an use-case where I want to change the root directory and after doing so be known as UID 1000 (normal user), the user that executed fakeroot. So basically I want:

$ whoami
bob
$ fakechroot fakeroot chroot $(pwd)/new_root /bin/bash
$ whoami
root
$ su bob
$ whoami
bob

However, the problem is that 'su' won't work, which probably is to be expected:

su: Authentication service cannot retrieve authentication info

I wasn't sure how to do this and whether this should be the task of fakechroot or fakeroot. Any idea?

fakechroot broken by libattr 2.4.48

I noticed this while running the test cases for "rpm" on Fedora Rawhide, one of the test cases crashes and /usr/bin/install segfaults, looking at the coredump, it's in a loop with lsetxattr calling itself repeatedly.

I traced this to libattr 2.4.48, where they replaced the implementation for the syscalls with stubs that call the syscalls from glibc:

http://git.savannah.nongnu.org/cgit/attr.git/commit/libattr/syscalls.c?id=efa0b1ea982261861d64f6d6d620af83d82b02d3

Which on 2.4.47 used to implement each of them calling SYSCALL(...) directly:

http://git.savannah.nongnu.org/cgit/attr.git/tree/libattr/syscalls.c?h=v2.4.47

The problem is that when fakechroot is running with a binary that links to libattr (such as /usr/bin/install, another good example is setfattr), then dlsym(RTLD_NEXT, "lsetxattr") and friends will resolve to the reference in libattr. But with the new implementation, libattr itself will call lsetxattr and have it resolved by the dynamic linker, which will resolve it to the one in libfakechroot.so, therefore creating a loop, infinite recursion.

Not sure what's the best solution here... Perhaps convincing libattr to undo the change and keep implementing these functions directly using SYSCALL(...)? Or perhaps implementing those in a way that binds strongly to the @GLIBC_2.3 implementation? (Not sure if such a thing is even possible...)

Or, from fakechroot side, perhaps using dlvsym() here and looking up the specific symbols from GLIBC, instead of just looking up the next default symbol here... Being very explicit about which symbols are replaced.

An easy reproducer here is (using libattr 2.4.48):

$ touch testfile
$ FAKECHROOT_BASE=${PWD} fakechroot setfattr -n user.testattr -v testvalue /testfile

Thanks!
Filipe

Fakechroot misbehaves inside container

Fakechroot doesn’t seem to work in a container setup by bwrap or podman. I am not sure what the culprit is, however. I discovered this when running the RPM test suite inside a container.

Tilde expansion

Investigating other stuff, I've found that apparently fakechroot has some code to perform at least minimal tilde expansion. I was kind of surprised by that, since I was of the opinion that tilde expansion is always the responsibility of the shell. Can this code be removed? Or is there some situation I have missed where it's really the task of the runtime library to perform tilde expansion? If so, shouldn't we allow expansions for other user names as well?

LD_LIBRARY_PATH interpreted incorrectly within the chroot jail, breaks builds

I'm using fakechroot to build software inside a chroot jail. (The reason is that this software needs to be bootstrapped from a binary-release which is based off /usr, which I cannot write to.)

However, the build tools set LD_LIBRARY_PATH in the build process, and because the paths in this environment variable are interpreted from outside the chroot jail, the build process breaks.

I'm now thinking of making a symlink from /home into the chroot jail, but this would be a hack, since the home directory of the user could be rooted at /usr (not likely, granted), and this would fail then.

So, it would be nice to have LD_LIBRARY_PATH interpreted "correctly".

env escaping chroot

I have a script (or set of scripts) that build system images using fakechroot. They suddenly started failing and i'm not sure what changed, but it seems to come down to:

root@host:/# ls -id /tmp
41960819 /tmp
root@host:/# env ls -id /tmp
37365864 /tmp

Where the latter is causing ls to see the /tmp of the host environment. This problem is arising whilst installing grub-efi-amd64 which has a postinst script which tries to use ucf. ucf fails to find a tmp file as its being run via env and seeing the /tmp of the host system.

LD_LIBRARY_PATH incorrect values with "fakechroot fakeroot chroot ... " after debootstrap --variant=fakechroot

I'm using fakechroot 2.16-1 from Debian and Ubuntu, on Ubuntu Precise 12.04 LTS.
After creating a system with fakechroot fakeroot debootstrap --variant=fakechroot ... , I've tried to build some packages inside it but they failed. Checking LD_LIBRARY_PATH i've found this:

$ fakechroot fakeroot chroot precise_amd64 /bin/bash

echo $LD_LIBRARY_PATH

precise_amd64/usr/lib/libfakeroot:precise_amd64/usr/lib64/libfakeroot:precise_amd64/usr/lib32/libfakeroot:precise_amd64/usr/local/lib:precise_amd64/lib/x86_64-linux-gnu:precise_amd64/usr/lib/x86_64-linux-gnu:/usr/lib/libfakeroot:/usr/lib64/libfakeroot:/usr/lib32/libfakeroot:/home/dariemp/Work/Building/var/lib/nbs-slave/buildroots/precise_amd64/usr/lib:/home/dariemp/Work/Building/var/lib/nbs-slave/buildroots/precise_amd64/lib

Maybe i don't understand quite well how fakechroot works but i don't think it is correct that all those paths are escaping the chroot environment: all of them are relative to external directories. Shouldn't be all of them departing from the new root directory?

/usr/sbin/chroot.fakechroot: line 105: 14031 Segmentation fault

How to reproduce:

Expected

  • chroot is successful

Actual

/usr/sbin/chroot.fakechroot: line 105: 14031 Segmentation fault      env -u FAKECHROOT_BASE_ORIG FAKECHROOT_CMD_ORIG= LD_LIBRARY_PATH="$fakechroot_chroot_paths" FAKECHROOT_BASE="$fakechroot_chroot_base" "$fakechroot_chroot_chroot" "${@:1:$(($fakechroot_chroot_n - 1))}" "${fakechroot_chroot_newroot#$FAKECHROOT_BASE_ORIG}" "${@:$(($fakechroot_chroot_n + 1))}"

Comments

Similar error on an Arch Linux image. Alpine Linux images work fine though.

Uhm, how do you use this from the repo?

I don't see how do I get the command fakechroot to be work?, This is what I do.

  1. git clone the repo
  2. look around and execute bash configure and make
  3. go to fakechroot/scripts and find fakechroot
  4. do ./fakechroot
  5. get $ ./fakechroot fakechroot: preload library not found, aborting.

Running minimal rootfs as non-root on arm device

Hello,

I have created a rootfs using buildroot, but using a crosstool-ng toolchain with glibc. This showed me the minimal set of files necessary. I then replaced all the libraries with ones pulled straight from the squeeze .deb packages for armel. I then added fakeroot and fakechroot to the mix. I also modified the resolv.conf, hosts, and nsswitch.conf files to my liking. After uploading this to my device, a lot is working. "cd /" takes me to the correct place. "whoami" returns root. But, anything DNS related is not working. For example "ping google.com" returns "bad address". I have copied the libnss_* and libresolv libraries over and everything else I think is necessary. Entering the same setup, but using qemu and chroot on my host machine works, but I am trying to figure out what it is not working on my target device.

When I run "strace ping google.com" I get the following:
open("/data/local/target/bin/ping", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\2\0(\0\1\0\0\0\0\314\0\0004\0\0\0"..., 4094) = 4094
close(3) = 0
execve("/data/local/target/bin/ping", ["ping", "google.com"], [/* 21 vars */]) = 0
brk(0) = 0xb5000
uname({sys="Linux", node="localhost", ...}) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x4001d000
open("/data/local/target/usr/lib/fakechroot/libfakechroot.so", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\364\32\0\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0666, st_size=45540, ...}) = 0
mmap2(NULL, 77628, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x40026000
mprotect(0x40031000, 28672, PROT_NONE) = 0
mmap2(0x40038000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xa) = 0x40038000
close(3) = 0
open("/data/local/target/usr/lib/libfakeroot/libfakeroot-sysv.so", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\340'\0\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0666, st_size=29092, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x4001f000
mmap2(NULL, 60672, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x40039000
mprotect(0x40040000, 28672, PROT_NONE) = 0
mmap2(0x40047000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x6) = 0x40047000
close(3) = 0
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("tls/v7l/neon/vfp/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/v7l/neon/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/v7l/vfp/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/v7l/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/neon/vfp/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/neon/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/vfp/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
open("v7l/neon/vfp/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
open("v7l/neon/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
open("v7l/vfp/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
open("v7l/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
open("neon/vfp/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
open("neon/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
open("vfp/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
open("libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/data/local/target/usr/lib/tls/v7l/neon/vfp/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/data/local/target/usr/lib/tls/v7l/neon/vfp", 0xbe8980f8) = -1 ENOENT (No such file or directory)
open("/data/local/target/usr/lib/tls/v7l/neon/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/data/local/target/usr/lib/tls/v7l/neon", 0xbe8980f8) = -1 ENOENT (No such file or directory)
open("/data/local/target/usr/lib/tls/v7l/vfp/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/data/local/target/usr/lib/tls/v7l/vfp", 0xbe8980f8) = -1 ENOENT (No such file or directory)
open("/data/local/target/usr/lib/tls/v7l/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/data/local/target/usr/lib/tls/v7l", 0xbe8980f8) = -1 ENOENT (No such file or directory)
open("/data/local/target/usr/lib/tls/neon/vfp/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/data/local/target/usr/lib/tls/neon/vfp", 0xbe8980f8) = -1 ENOENT (No such file or directory)
open("/data/local/target/usr/lib/tls/neon/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/data/local/target/usr/lib/tls/neon", 0xbe8980f8) = -1 ENOENT (No such file or directory)
open("/data/local/target/usr/lib/tls/vfp/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/data/local/target/usr/lib/tls/vfp", 0xbe8980f8) = -1 ENOENT (No such file or directory)
open("/data/local/target/usr/lib/tls/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/data/local/target/usr/lib/tls", 0xbe8980f8) = -1 ENOENT (No such file or directory)
open("/data/local/target/usr/lib/v7l/neon/vfp/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/data/local/target/usr/lib/v7l/neon/vfp", 0xbe8980f8) = -1 ENOENT (No such file or directory)
open("/data/local/target/usr/lib/v7l/neon/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/data/local/target/usr/lib/v7l/neon", 0xbe8980f8) = -1 ENOENT (No such file or directory)
open("/data/local/target/usr/lib/v7l/vfp/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/data/local/target/usr/lib/v7l/vfp", 0xbe8980f8) = -1 ENOENT (No such file or directory)
open("/data/local/target/usr/lib/v7l/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/data/local/target/usr/lib/v7l", 0xbe8980f8) = -1 ENOENT (No such file or directory)
open("/data/local/target/usr/lib/neon/vfp/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/data/local/target/usr/lib/neon/vfp", 0xbe8980f8) = -1 ENOENT (No such file or directory)
open("/data/local/target/usr/lib/neon/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/data/local/target/usr/lib/neon", 0xbe8980f8) = -1 ENOENT (No such file or directory)
open("/data/local/target/usr/lib/vfp/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/data/local/target/usr/lib/vfp", 0xbe8980f8) = -1 ENOENT (No such file or directory)
open("/data/local/target/usr/lib/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/data/local/target/usr/lib", {st_mode=S_IFDIR|0775, st_size=0, ...}) = 0
open("/data/local/target/lib/tls/v7l/neon/vfp/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/data/local/target/lib/tls/v7l/neon/vfp", 0xbe8980f8) = -1 ENOENT (No such file or directory)
open("/data/local/target/lib/tls/v7l/neon/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/data/local/target/lib/tls/v7l/neon", 0xbe8980f8) = -1 ENOENT (No such file or directory)
open("/data/local/target/lib/tls/v7l/vfp/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/data/local/target/lib/tls/v7l/vfp", 0xbe8980f8) = -1 ENOENT (No such file or directory)
open("/data/local/target/lib/tls/v7l/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/data/local/target/lib/tls/v7l", 0xbe8980f8) = -1 ENOENT (No such file or directory)
open("/data/local/target/lib/tls/neon/vfp/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/data/local/target/lib/tls/neon/vfp", 0xbe8980f8) = -1 ENOENT (No such file or directory)
open("/data/local/target/lib/tls/neon/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/data/local/target/lib/tls/neon", 0xbe8980f8) = -1 ENOENT (No such file or directory)
open("/data/local/target/lib/tls/vfp/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/data/local/target/lib/tls/vfp", 0xbe8980f8) = -1 ENOENT (No such file or directory)
open("/data/local/target/lib/tls/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/data/local/target/lib/tls", 0xbe8980f8) = -1 ENOENT (No such file or directory)
open("/data/local/target/lib/v7l/neon/vfp/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/data/local/target/lib/v7l/neon/vfp", 0xbe8980f8) = -1 ENOENT (No such file or directory)
open("/data/local/target/lib/v7l/neon/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/data/local/target/lib/v7l/neon", 0xbe8980f8) = -1 ENOENT (No such file or directory)
open("/data/local/target/lib/v7l/vfp/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/data/local/target/lib/v7l/vfp", 0xbe8980f8) = -1 ENOENT (No such file or directory)
open("/data/local/target/lib/v7l/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/data/local/target/lib/v7l", 0xbe8980f8) = -1 ENOENT (No such file or directory)
open("/data/local/target/lib/neon/vfp/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/data/local/target/lib/neon/vfp", 0xbe8980f8) = -1 ENOENT (No such file or directory)
open("/data/local/target/lib/neon/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/data/local/target/lib/neon", 0xbe8980f8) = -1 ENOENT (No such file or directory)
open("/data/local/target/lib/vfp/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/data/local/target/lib/vfp", 0xbe8980f8) = -1 ENOENT (No such file or directory)
open("/data/local/target/lib/libc.so.6", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\374V\1\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0777, st_size=1209660, ...}) = 0
mmap2(NULL, 1246468, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x40048000
mprotect(0x4016b000, 32768, PROT_NONE) = 0
mmap2(0x40173000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x123) = 0x40173000
mmap2(0x40176000, 9476, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x40176000
close(3) = 0
open("tls/v7l/neon/vfp/libdl.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/v7l/neon/libdl.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/v7l/vfp/libdl.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/v7l/libdl.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/neon/vfp/libdl.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/neon/libdl.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/vfp/libdl.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/libdl.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("v7l/neon/vfp/libdl.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("v7l/neon/libdl.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("v7l/vfp/libdl.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("v7l/libdl.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("neon/vfp/libdl.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("neon/libdl.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("vfp/libdl.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("libdl.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/data/local/target/usr/lib/libdl.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/data/local/target/lib/libdl.so.2", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0$\t\0\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0777, st_size=9808, ...}) = 0
mmap2(NULL, 41136, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x40179000
mprotect(0x4017b000, 28672, PROT_NONE) = 0
mmap2(0x40182000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1) = 0x40182000
close(3) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40020000
set_tls(0x40020170, 0x40020847, 0x40020848, 0x40020170, 0x40025000) = 0
mprotect(0x40182000, 4096, PROT_READ) = 0
mprotect(0x40173000, 8192, PROT_READ) = 0
mprotect(0xb1000, 4096, PROT_READ) = 0
mprotect(0x40024000, 4096, PROT_READ) = 0
brk(0) = 0xb5000
brk(0xd6000) = 0xd6000
socket(PF_FILE, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 3
connect(3, {sa_family=AF_FILE, path="/var/run/nscd/socket"}, 110) = -1 ENOENT (No such file or directory)
close(3) = 0
socket(PF_FILE, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 3
connect(3, {sa_family=AF_FILE, path="/var/run/nscd/socket"}, 110) = -1 ENOENT (No such file or directory)
close(3) = 0
open("/etc/nsswitch.conf", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/v7l/neon/vfp/libnss_compat.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/v7l/neon/libnss_compat.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/v7l/vfp/libnss_compat.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/v7l/libnss_compat.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/neon/vfp/libnss_compat.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/neon/libnss_compat.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/vfp/libnss_compat.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/libnss_compat.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("v7l/neon/vfp/libnss_compat.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("v7l/neon/libnss_compat.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("v7l/vfp/libnss_compat.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("v7l/libnss_compat.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("neon/vfp/libnss_compat.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("neon/libnss_compat.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("vfp/libnss_compat.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("libnss_compat.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/data/local/target/usr/lib/libnss_compat.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/data/local/target/lib/libnss_compat.so.2", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0|\r\0\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0777, st_size=26480, ...}) = 0
mmap2(NULL, 57952, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x40184000
mprotect(0x4018a000, 28672, PROT_NONE) = 0
mmap2(0x40191000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x5) = 0x40191000
close(3) = 0
open("tls/v7l/neon/vfp/libnsl.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/v7l/neon/libnsl.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/v7l/vfp/libnsl.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/v7l/libnsl.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/neon/vfp/libnsl.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/neon/libnsl.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/vfp/libnsl.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/libnsl.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("v7l/neon/vfp/libnsl.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("v7l/neon/libnsl.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("v7l/vfp/libnsl.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("v7l/libnsl.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("neon/vfp/libnsl.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("neon/libnsl.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("vfp/libnsl.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("libnsl.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/data/local/target/usr/lib/libnsl.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/data/local/target/lib/libnsl.so.1", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0x/\0\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0777, st_size=75732, ...}) = 0
mmap2(NULL, 116488, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x40193000
mprotect(0x401a5000, 28672, PROT_NONE) = 0
mmap2(0x401ac000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x11) = 0x401ac000
mmap2(0x401ae000, 5896, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x401ae000
close(3) = 0
mprotect(0x401ac000, 4096, PROT_READ) = 0
mprotect(0x40191000, 4096, PROT_READ) = 0
open("/etc/nsswitch.conf", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/v7l/neon/vfp/libnss_nis.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/v7l/neon/libnss_nis.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/v7l/vfp/libnss_nis.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/v7l/libnss_nis.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/neon/vfp/libnss_nis.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/neon/libnss_nis.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/vfp/libnss_nis.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/libnss_nis.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("v7l/neon/vfp/libnss_nis.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("v7l/neon/libnss_nis.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("v7l/vfp/libnss_nis.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("v7l/libnss_nis.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("neon/vfp/libnss_nis.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("neon/libnss_nis.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("vfp/libnss_nis.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("libnss_nis.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/data/local/target/usr/lib/libnss_nis.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/data/local/target/lib/libnss_nis.so.2", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0X\30\0\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0777, st_size=38608, ...}) = 0
mmap2(NULL, 70236, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x401b0000
mprotect(0x401b9000, 28672, PROT_NONE) = 0
mmap2(0x401c0000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x8) = 0x401c0000
close(3) = 0
open("tls/v7l/neon/vfp/libnss_files.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/v7l/neon/libnss_files.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/v7l/vfp/libnss_files.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/v7l/libnss_files.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/neon/vfp/libnss_files.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/neon/libnss_files.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/vfp/libnss_files.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/libnss_files.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("v7l/neon/vfp/libnss_files.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("v7l/neon/libnss_files.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("v7l/vfp/libnss_files.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("v7l/libnss_files.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("neon/vfp/libnss_files.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("neon/libnss_files.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("vfp/libnss_files.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("libnss_files.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/data/local/target/usr/lib/libnss_files.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/data/local/target/lib/libnss_files.so.2", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\330\31\0\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0777, st_size=42688, ...}) = 0
mmap2(NULL, 74492, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x401c2000
mprotect(0x401cc000, 28672, PROT_NONE) = 0
mmap2(0x401d3000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x9) = 0x401d3000
close(3) = 0
mprotect(0x401d3000, 4096, PROT_READ) = 0
mprotect(0x401c0000, 4096, PROT_READ) = 0
open("/data/local/target/etc/passwd", O_RDONLY|O_CLOEXEC) = 3
fcntl64(3, F_GETFD) = 0x1 (flags FD_CLOEXEC)
_llseek(3, 0, [0], SEEK_CUR) = 0
fstat64(3, {st_mode=S_IFREG|0666, st_size=596, ...}) = 0
mmap2(NULL, 596, PROT_READ, MAP_SHARED, 3, 0) = 0x40021000
_llseek(3, 596, [596], SEEK_SET) = 0
munmap(0x40021000, 596) = 0
close(3) = 0
getpid() = 5994
socket(PF_NETLINK, SOCK_RAW, 0) = 3
bind(3, {sa_family=AF_NETLINK, pid=0, groups=00000000}, 12) = 0
getsockname(3, {sa_family=AF_NETLINK, pid=5994, groups=00000000}, [12]) = 0
gettimeofday({1366699621, 228514}, NULL) = 0
sendto(3, "\24\0\0\0\26\0\1\3e.vQ\0\0\0\0\0\0\0\0", 20, 0, {sa_family=AF_NETLINK, pid=0, groups=00000000}, 12) = 20
recvmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{"0\0\0\0\24\0\2\0e.vQj\27\0\0\2\10\200\376\1\0\0\0\10\0\1\0\177\0\0\1"..., 4096}], msg_controllen=0, msg_flags=0}, 0) = 108
recvmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{"@\0\0\0\24\0\2\0e.vQj\27\0\0\n\200\200\376\1\0\0\0\24\0\1\0\0\0\0\0"..., 4096}], msg_controllen=0, msg_flags=0}, 0) = 128
recvmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{"\24\0\0\0\3\0\2\0e.vQj\27\0\0\0\0\0\0\1\0\0\0\24\0\1\0\0\0\0\0"..., 4096}], msg_controllen=0, msg_flags=0}, 0) = 20
close(3) = 0
open("/etc/resolv.conf", O_RDONLY) = -1 ENOENT (No such file or directory)
uname({sys="Linux", node="localhost", ...}) = 0
socket(PF_FILE, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 3
connect(3, {sa_family=AF_FILE, path="/var/run/nscd/socket"}, 110) = -1 ENOENT (No such file or directory)
close(3) = 0
socket(PF_FILE, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 3
connect(3, {sa_family=AF_FILE, path="/var/run/nscd/socket"}, 110) = -1 ENOENT (No such file or directory)
close(3) = 0
open("/etc/nsswitch.conf", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/v7l/neon/vfp/libnss_dns.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/v7l/neon/libnss_dns.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/v7l/vfp/libnss_dns.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/v7l/libnss_dns.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/neon/vfp/libnss_dns.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/neon/libnss_dns.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/vfp/libnss_dns.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/libnss_dns.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("v7l/neon/vfp/libnss_dns.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("v7l/neon/libnss_dns.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("v7l/vfp/libnss_dns.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("v7l/libnss_dns.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("neon/vfp/libnss_dns.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("neon/libnss_dns.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("vfp/libnss_dns.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("libnss_dns.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/data/local/target/usr/lib/libnss_dns.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/data/local/target/lib/libnss_dns.so.2", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0000\v\0\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0777, st_size=18040, ...}) = 0
mmap2(NULL, 49316, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x401d5000
mprotect(0x401d9000, 28672, PROT_NONE) = 0
mmap2(0x401e0000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x3) = 0x401e0000
close(3) = 0
open("tls/v7l/neon/vfp/libresolv.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/v7l/neon/libresolv.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/v7l/vfp/libresolv.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/v7l/libresolv.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/neon/vfp/libresolv.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/neon/libresolv.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/vfp/libresolv.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/libresolv.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("v7l/neon/vfp/libresolv.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("v7l/neon/libresolv.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("v7l/vfp/libresolv.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("v7l/libresolv.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("neon/vfp/libresolv.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("neon/libresolv.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("vfp/libresolv.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("libresolv.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/data/local/target/usr/lib/libresolv.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/data/local/target/lib/libresolv.so.2", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0H$\0\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0777, st_size=71524, ...}) = 0
mmap2(NULL, 79772, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x401e2000
mmap2(0x401f2000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x10) = 0x401f2000
mmap2(0x401f4000, 6044, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x401f4000
close(3) = 0
mprotect(0x401f2000, 4096, PROT_READ) = 0
mprotect(0x401e0000, 4096, PROT_READ) = 0
open("/etc/host.conf", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/etc/resolv.conf", 0xbe897e98) = -1 ENOENT (No such file or directory)
gettimeofday({1366699621, 250480}, NULL) = 0
socket(PF_INET, SOCK_DGRAM|SOCK_NONBLOCK, IPPROTO_IP) = 3
connect(3, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("127.0.0.1")}, 16) = 0
gettimeofday({1366699621, 251348}, NULL) = 0
poll([{fd=3, events=POLLOUT}], 1, 0) = 1 ([{fd=3, revents=POLLOUT}])
send(3, "\332\316\1\0\0\1\0\0\0\0\0\0\6google\3com\0\0\1\0\1", 28, MSG_NOSIGNAL) = 28
poll([{fd=3, events=POLLIN}], 1, 5000) = 1 ([{fd=3, revents=POLLERR}])
close(3) = 0
socket(PF_INET, SOCK_DGRAM|SOCK_NONBLOCK, IPPROTO_IP) = 3
connect(3, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("127.0.0.1")}, 16) = 0
gettimeofday({1366699621, 253357}, NULL) = 0
poll([{fd=3, events=POLLOUT}], 1, 0) = 1 ([{fd=3, revents=POLLOUT}])
send(3, "\332\316\1\0\0\1\0\0\0\0\0\0\6google\3com\0\0\1\0\1", 28, MSG_NOSIGNAL) = 28
poll([{fd=3, events=POLLIN}], 1, 5000) = 1 ([{fd=3, revents=POLLERR}])
close(3) = 0
gettimeofday({1366699621, 254826}, NULL) = 0
socket(PF_INET, SOCK_DGRAM|SOCK_NONBLOCK, IPPROTO_IP) = 3
connect(3, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("127.0.0.1")}, 16) = 0
gettimeofday({1366699621, 255502}, NULL) = 0
poll([{fd=3, events=POLLOUT}], 1, 0) = 1 ([{fd=3, revents=POLLOUT}])
send(3, "DU\1\0\0\1\0\0\0\0\0\0\6google\3com\0\0\1\0\1", 28, MSG_NOSIGNAL) = 28
poll([{fd=3, events=POLLIN}], 1, 5000) = 1 ([{fd=3, revents=POLLERR}])
close(3) = 0
socket(PF_INET, SOCK_DGRAM|SOCK_NONBLOCK, IPPROTO_IP) = 3
connect(3, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("127.0.0.1")}, 16) = 0
gettimeofday({1366699621, 257278}, NULL) = 0
poll([{fd=3, events=POLLOUT}], 1, 0) = 1 ([{fd=3, revents=POLLOUT}])
send(3, "DU\1\0\0\1\0\0\0\0\0\0\6google\3com\0\0\1\0\1", 28, MSG_NOSIGNAL) = 28
poll([{fd=3, events=POLLIN}], 1, 5000) = 1 ([{fd=3, revents=POLLERR}])
close(3) = 0
open("/data/local/target/etc/hosts", O_RDONLY|O_CLOEXEC) = 3
fcntl64(3, F_GETFD) = 0x1 (flags FD_CLOEXEC)
fstat64(3, {st_mode=S_IFREG|0666, st_size=40, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40021000
read(3, "127.0.0.1\tlocalhost\n127.0.1.1\tbu"..., 4096) = 40
read(3, "", 4096) = 0
close(3) = 0
munmap(0x40021000, 4096) = 0
write(2, "ping: bad address 'google.com'\n", 31) = 31
exit_group(1) = ?

You can see it finds the various libnss_* libraries and it figured out that the host file wasn't simply at /etc/hosts, but why do you think it didn't look in the correct location for nsswitch.conf and resolv.conf?

Thanks,
Corbin

block scoped variable life range violation

In src/libfakechroot.h there is

   #define expand_chroot_path(path) 
    { 
        if (!fakechroot_localdir(path)) { 
            if ((path) != NULL) { 
                char fakechroot_abspath[FAKECHROOT_PATH_MAX]; 
                rel2abs((path), fakechroot_abspath); 
                (path) = fakechroot_abspath; 
                expand_chroot_rel_path(path); 
            } 
        } 
    }

The address of the block local scoped char array abspath is erroneously passed to the outer scoped path. This can fail anytime and randomly, especially when enabling compiler optimizations.

There are more such pieces in the source code for example in bind.c

        if (af_unix_path != NULL) {
            char tmp[FAKECHROOT_PATH_MAX];
            tmp[af_unix_path_max] = '\0';
            snprintf(tmp, af_unix_path_max, "%s/%s", af_unix_path, path);
            path = tmp;
        }

where the contents of tmp pointed to by path can evaporate anytime.

fakechroot_base is appended always

expand_chroot_rel_path macro, at libfakechroot.h adds fakechroot_base to the new path always.

Bellow is an example of the attempted path running make on fakechroot src itself:

/home/local/project/cnovo/work/trunk/bin/sh: line 20: /home/local/project/cnovo/work/trunk/home/local/project/cnovo/work/trunk/home/local/project/cnovo/work/trunk/usr/bin/make: No such file or directory

This patch seems to solve the issue:

--- /tmp/libfakechroot.h        2017-11-29 16:14:20.689114145 +0000
+++ ./libfakechroot.h   2017-11-29 16:14:48.001226429 +0000
@@ -109,7 +109,13 @@
                 const char *fakechroot_base = getenv("FAKECHROOT_BASE"); \
                 if (fakechroot_base != NULL ) { \
                     char fakechroot_buf[FAKECHROOT_PATH_MAX]; \
-                    snprintf(fakechroot_buf, FAKECHROOT_PATH_MAX, "%s%s", fakechroot_base, (path)); \
+                    int fakechroot_base_len = strlen(fakechroot_base); \
+                    if (strncmp(fakechroot_base, path, fakechroot_base_len) == 0) { \
+                        snprintf(fakechroot_buf, FAKECHROOT_PATH_MAX, "%s", (path)); \
+                    } \
+                    else { \
+                        snprintf(fakechroot_buf, FAKECHROOT_PATH_MAX, "%s%s", fakechroot_base, (path)); \
+                    } \
                     (path) = fakechroot_buf; \
                 } \
             } \

symbolic link resolution fails and files outside fakechroot can be accessed

Following test setup:

sudo debootstrap --variant=minbase sid /tmp/test-chroot
echo foo > /tmp/foo
echo bar > /tmp/test-chroot/tmp/bar
ln -s /tmp/bar /tmp/test-chroot/link1
ln -s /tmp/foo /tmp/test-chroot/link2
ln -s /tmp/test-chroot/tmp/bar /tmp/test-chroot/link3

First test: readlink

$ fakeroot fakechroot chroot /tmp/test-chroot/ readlink /link1
/tmp/bar
$ fakeroot fakechroot chroot /tmp/test-chroot/ readlink /link2
/tmp/foo
$ fakeroot fakechroot chroot /tmp/test-chroot/ readlink /link3
/tmp/bar

The third link should read /tmp/test-chroot/tmp/bar as it was created
like that. To check:

$ sudo chroot /tmp/test-chroot/ readlink /link1
/tmp/bar
$ sudo chroot /tmp/test-chroot/ readlink /link2
/tmp/foo
$ sudo chroot /tmp/test-chroot/ readlink /link3
/tmp/test-chroot/tmp/bar

Second test: cat links

$ fakeroot fakechroot chroot /tmp/test-chroot/ cat /link1
cat: /link1: No such file or directory
$ fakeroot fakechroot chroot /tmp/test-chroot/ cat /link2
foo
$ fakeroot fakechroot chroot /tmp/test-chroot/ cat /link3
bar

/link1 should've been resolved correctly, because /tmp/bar exists in
/tmp/test-chroot. /link2 should not have resolved because /tmp/foo only
exists outside the chroot. /link3 should not have been resolved either
because /tmp/test-chroot/tmp/bar is only visible like that from outside
the chroot. To check:

$ sudo chroot /tmp/test-chroot/ cat /link1
bar
$ sudo chroot /tmp/test-chroot/ cat /link2
cat: /link2: No such file or directory
$ sudo chroot /tmp/test-chroot/ cat /link3
cat: /link3: No such file or directory

Third test: cat files

$ fakeroot fakechroot chroot /tmp/test-chroot/ cat /tmp/bar
bar
$ fakeroot fakechroot chroot /tmp/test-chroot/ cat /tmp/foo
cat: /tmp/foo: No such file or directory
$ fakeroot fakechroot chroot /tmp/test-chroot/ cat /tmp/test-chroot/tmp/bar
cat: /tmp/test-chroot/tmp/bar: No such file or directory

all works as expected

$ sudo chroot /tmp/test-chroot/ cat /tmp/bar
bar
$ sudo chroot /tmp/test-chroot/ cat /tmp/foo
cat: /tmp/foo: No such file or directory
$ sudo chroot /tmp/test-chroot/ cat /tmp/test-chroot/tmp/bar
cat: /tmp/test-chroot/tmp/bar: No such file or directory

As a result I suspect there is something wrong with readlink and open?

Hope all this helps a bit to fix the issue.

cheers, josch

fakechroot seems to resolve symlinks incorrectly

I'm trying to emulate a chroot and execute update-initramfs -u to create an initrd image for a foreign system, without needing real root on the host system.

The chroot directory is an exact copy of the foreign system (an image is unpacked while inside fakeroot, so it is pretending to have the correct root permissions on everything).

In this directory, /usr/sbin/update-initramfs happens to be a symlink to /bin/live-update-initramfs. This is of course referencing a file that is also inside the chroot directory.

If I open a shell using fakechroot 2.18 and try to run update-initramfs I just get "command not found". If I run /usr/sbin/update-initramfs I get "No such file or directory". If I run /bin/live-update-initramfs then it actually runs.

Is it trying to interpret symlinks in the host FS rather than inside the fake chroot? That seems incorrect; is there a way to make it stop that?

Q: Is it Possible to use fakechroot/fakeroot-ng with Golang Binaries

Golang uses syscalls directly and does not use glibc.

I was trying to get syncthing to work inside a fakechroot. However it fails with /usr/bin/syncthing not in path. It is in path, however since it uses syscalls directly, it does not work. This error is similar to #67.

Is it possible to use fakeroot-ng with fakechroot ? I checked the documentation for fakechroot but couldn't find the use of fakeroot-ng ?

fakechroot + debootstrap doesn't work on current distributions

I realize this repo looks quite dead, but since noone else has posted this issue yet here it is: The "debootstrap without root" use case doesn't actually seem to work with any recent distro anymore. I've tested Fedora, Mint and Ubuntu (all vanilla installations in VMs) by running

fakechroot fakeroot debootstrap sid /tmp/sid

as suggested in the README. In all three cases, the error

W: Failure trying to run: chroot /tmp/sid dpkg --force-depends --install /var/cache/apt/archives/base-passwd_3.5.38_amd64.deb

halted the bootstrapping process. Looking at debootstrap.log as suggested by the output revealed the following details:

Fedora 22

cannot get security labeling handle: No such file or directory

Mint 17.2 + Ubuntu 15.04

dpkg: symbol lookup error: dpkg: undefined symbol: setexecfilecon

Furthermore, I can confirm that the following modifications, found by a web search for similar issues, do not fix the problem:

  • Invoking fakechroot with --use-system-libs
  • Adding /usr/sbin / /sbin to the PATH
  • Invoking debootstrap with --variant=fakechroot
  • Invoking debootstrap with --foreign and two-staging the installation

Alas, there currently seems to be no way to actually get debootstrap to work without superuser privileges.

Building on Darwin?

Hi there!
So I understand this may not exactly be your top priority? But since I've noticed this project has some regained some life in recent months, I though I might as well ask...

I've been trying to see if I can hack fakechroot to work of Darwin, and I think it is theoretically feasible (adapting the script and loader from mackyle/fakeroot). But I'm running into what looks like three or four libc incompatibilities that I'm not really sure what to do about. I'm not sure if these are big deal-breakers or not... If anyone felt like lending any guidance, that would be fantastic; otherwise, I do understand.

  1. __opendir2.c
    A. On Darwin, dd_foo is always __dd_foo. I swear I've seen a macro for handling this somewhere; but unfortunately, I can't find it, and I'm not confident enough in my own skills to write one myself without breaking stuff.
    B. After manually accounting for above, it chokes on dirp->__dd_lock = NULL: something about NULL being of an incompatible type to assign to a pthread mutex? (No idea... sorry.)
  2. ftw.c
    Darwin does not seem to know about the __nftw_func_t type nor the macros AT_SYMLINK_NOFOLLOW, FTW_ACTIONRETVAL, FTW_SKIP_SUBTREE, FTW_SKIP_SIBLINGS, and FTW_STOP.
  3. statfs64.c
    <sys/statfs.h> doesn't exist on Darwin.

Thanks! G.

Please support the renameat2 systemcall

Currently, when I try to use mv from coreutils inside a Debian unstable chroot I get an EACCESS:

$ fakechroot fakeroot chroot debian-unstable /bin/mv /etc/fstab /etc/blub
/bin/mv: cannot move '/etc/fstab' to '/etc/blub': Permission denied

Using strace I found:

[pid  7379] renameat2(AT_FDCWD, "/etc/fstab", AT_FDCWD, "/etc/blub", RENAME_NOREPLACE) = -1 EACCES (Permission denied)

And indeed it seems that fakechroot does not yet support the renameat2 systemcall.

can't build 2.18 on NetBSD 7.0/amd64

For experimentation, I'm trying to build 2.18 on NetBSD 7.0/amd64 - I'm running across the following error build error:

__opendir2.c: In function ‘__opendir_common’:
__opendir2.c:199:13: error: ‘DIR’ has no member named ‘dd_td’
         dirp->dd_td = (struct _telldir *)((char *)dirp + sizeof(DIR));
             ^

I also had to remove the __FBSDID line near the beginning of src/__opendir2.c as such, which (AFAIK) is only used for "tagging" a binary with some version information and seems to trip up the compiler (it thinks you are attempting to define a function at 'top level' here)

diff --git a/src/__opendir2.c b/src/__opendir2.c
index f7a4eef..e780526 100644
--- a/src/__opendir2.c
+++ b/src/__opendir2.c
@@ -59,7 +59,6 @@
 static char sccsid[] = "@(#)opendir.c   8.8 (Berkeley) 5/1/95";
 #endif /* LIBC_SCCS and not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/gen/opendir.c,v 1.25.2.2.2.1 2010/06/14 02:09:06 kensmith Exp $");

 /*#include "namespace.h"*/
 #include <sys/param.h>

I'm not sure what exactly is involved in this part of the build, so should you need any particulars just ask. These ones I do know you'll probably want?

gcc (nb2 20150115) 4.8.4
GNU Make 4.1
NetBSD {snip} 7.0 NetBSD 7.0 (GENERIC.201509250726Z) amd64

libfakechroot.so linking fails when LTO

libtool: link: gcc -shared -fPIC -DPIC .libs/__fxstatat.o .libs/__fxstatat64.o .libs/__getcwd_chk.o .libs/__getwd_chk.o .libs/__lxstat.o .libs/__lxstat64.o .libs/__open.o .libs/__open64.o .libs/__open64_2.o .libs/__open_2.o .libs/__openat64_2.o .libs/__openat_2.o .libs/__opendir2.o .libs/__readlink_chk.o .libs/__readlinkat_chk.o .libs/__realpath_chk.o .libs/__statfs.o .libs/__xmknod.o .libs/__xmknodat.o .libs/__xstat.o .libs/__xstat64.o .libs/_xftw.o .libs/_xftw64.o .libs/access.o .libs/acct.o .libs/audit_log_acct_message.o .libs/bind.o .libs/bindtextdomain.o .libs/canonicalize_file_name.o .libs/chdir.o .libs/chmod.o .libs/chown.o .libs/chroot.o .libs/clearenv.o .libs/connect.o .libs/creat.o .libs/creat64.o .libs/dedotdot.o .libs/dl_iterate_phdr.o .libs/dladdr.o .libs/dlmopen.o .libs/dlopen.o .libs/eaccess.o .libs/euidaccess.o .libs/execl.o .libs/execle.o .libs/execlp.o .libs/execv.o .libs/execve.o .libs/execvp.o .libs/faccessat.o .libs/fchmodat.o .libs/fchownat.o .libs/fopen.o .libs/fopen64.o .libs/freopen.o .libs/freopen64.o .libs/fts.o .libs/fts64.o .libs/ftw.o .libs/ftw64.o .libs/futimesat.o .libs/get_current_dir_name.o .libs/getcwd.o .libs/getcwd_real.o .libs/getpeername.o .libs/getsockname.o .libs/getwd.o .libs/getxattr.o .libs/glob.o .libs/glob64.o .libs/glob_pattern_p.o .libs/inotify_add_watch.o .libs/lchmod.o .libs/lchown.o .libs/lckpwdf.o .libs/lgetxattr.o .libs/libfakechroot.o .libs/link.o .libs/linkat.o .libs/listxattr.o .libs/llistxattr.o .libs/lremovexattr.o .libs/lsetxattr.o .libs/lstat.o .libs/lstat64.o .libs/lutimes.o .libs/mkdir.o .libs/mkdirat.o .libs/mkdtemp.o .libs/mkfifo.o .libs/mkfifoat.o .libs/mknod.o .libs/mknodat.o .libs/mkostemp.o .libs/mkostemp64.o .libs/mkostemps.o .libs/mkostemps64.o .libs/mkstemp.o .libs/mkstemp64.o .libs/mkstemps.o .libs/mkstemps64.o .libs/mktemp.o .libs/open.o .libs/open64.o .libs/openat.o .libs/openat64.o .libs/opendir.o .libs/pathconf.o .libs/popen.o .libs/posix_spawn.o .libs/posix_spawnp.o .libs/rawmemchr.o .libs/readlink.o .libs/readlinkat.o .libs/realpath.o .libs/rel2abs.o .libs/rel2absat.o .libs/remove.o .libs/removexattr.o .libs/rename.o .libs/renameat.o .libs/revoke.o .libs/rmdir.o .libs/rpl_lstat.o .libs/scandir.o .libs/scandir64.o .libs/setenv.o .libs/setxattr.o .libs/stat.o .libs/stat64.o .libs/statfs.o .libs/statfs64.o .libs/statvfs.o .libs/statvfs64.o .libs/stpcpy.o .libs/strchrnul.o .libs/strlcpy.o .libs/symlink.o .libs/symlinkat.o .libs/system.o .libs/tempnam.o .libs/tmpnam.o .libs/truncate.o .libs/truncate64.o .libs/ulckpwdf.o .libs/unlink.o .libs/unlinkat.o .libs/utime.o .libs/utimensat.o .libs/utimes.o -ldl -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -O2 -g -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -flto -Wl,-z -Wl,relro -Wl,--as-needed -Wl,-z -Wl,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -flto -fuse-linker-plugin -Wl,-soname -Wl,libfakechroot.so -o .libs/libfakechroot.so
__lxstat64.h:40:5: warning: type of '__lxstat64_rel' does not match original declaration [-Wlto-type-mismatch]
int __lxstat64_rel(int, const char *, struct stat64 *);
^
__lxstat64.c:53:11: note: '__lxstat64_rel' was previously declared here
LOCAL int __lxstat64_rel(int ver, const char * filename, struct stat64 * buf)
^
__lxstat64.c:53:11: note: code may be misoptimized unless -fno-strict-aliasing is used
In function '__open64_alias':
lto1: fatal error: Cgraph edge statement index out of range

t/fts.t test is failing

FAIL: t/fts.t
make[4]: Leaving directory '/home/tkloczko/rpmbuild/BUILD/fakechroot-2.19/test'
make[4]: Entering directory '/home/tkloczko/rpmbuild/BUILD/fakechroot-2.19/test'
PASS: t/opendir.t
make[4]: Leaving directory '/home/tkloczko/rpmbuild/BUILD/fakechroot-2.19/test'
make[4]: Entering directory '/home/tkloczko/rpmbuild/BUILD/fakechroot-2.19/test'
PASS: t/mktemp.t
make[4]: Leaving directory '/home/tkloczko/rpmbuild/BUILD/fakechroot-2.19/test'
make[4]: Entering directory '/home/tkloczko/rpmbuild/BUILD/fakechroot-2.19/test'
PASS: t/popen.t
make[4]: Leaving directory '/home/tkloczko/rpmbuild/BUILD/fakechroot-2.19/test'
make[4]: Entering directory '/home/tkloczko/rpmbuild/BUILD/fakechroot-2.19/test'
PASS: t/posix_spawn.t
make[4]: Leaving directory '/home/tkloczko/rpmbuild/BUILD/fakechroot-2.19/test'
make[4]: Entering directory '/home/tkloczko/rpmbuild/BUILD/fakechroot-2.19/test'
PASS: t/posix_spawnp.t
make[4]: Leaving directory '/home/tkloczko/rpmbuild/BUILD/fakechroot-2.19/test'
make[4]: Entering directory '/home/tkloczko/rpmbuild/BUILD/fakechroot-2.19/test'
PASS: t/pwd.t
make[4]: Leaving directory '/home/tkloczko/rpmbuild/BUILD/fakechroot-2.19/test'
make[4]: Entering directory '/home/tkloczko/rpmbuild/BUILD/fakechroot-2.19/test'
PASS: t/realpath.t
make[4]: Leaving directory '/home/tkloczko/rpmbuild/BUILD/fakechroot-2.19/test'
make[4]: Entering directory '/home/tkloczko/rpmbuild/BUILD/fakechroot-2.19/test'
PASS: t/statfs.t
make[4]: Leaving directory '/home/tkloczko/rpmbuild/BUILD/fakechroot-2.19/test'
make[4]: Entering directory '/home/tkloczko/rpmbuild/BUILD/fakechroot-2.19/test'
PASS: t/statvfs.t
make[4]: Leaving directory '/home/tkloczko/rpmbuild/BUILD/fakechroot-2.19/test'
make[4]: Entering directory '/home/tkloczko/rpmbuild/BUILD/fakechroot-2.19/test'
PASS: t/symlink.t
make[4]: Leaving directory '/home/tkloczko/rpmbuild/BUILD/fakechroot-2.19/test'
make[4]: Entering directory '/home/tkloczko/rpmbuild/BUILD/fakechroot-2.19/test'
PASS: t/system.t
make[4]: Leaving directory '/home/tkloczko/rpmbuild/BUILD/fakechroot-2.19/test'
make[4]: Entering directory '/home/tkloczko/rpmbuild/BUILD/fakechroot-2.19/test'
PASS: t/socket-af_unix.t
make[4]: Leaving directory '/home/tkloczko/rpmbuild/BUILD/fakechroot-2.19/test'
make[4]: Entering directory '/home/tkloczko/rpmbuild/BUILD/fakechroot-2.19/test'
PASS: t/zzarchlinux.t
make[4]: Leaving directory '/home/tkloczko/rpmbuild/BUILD/fakechroot-2.19/test'
make[4]: Entering directory '/home/tkloczko/rpmbuild/BUILD/fakechroot-2.19/test'
PASS: t/zzdebootstrap.t
make[4]: Leaving directory '/home/tkloczko/rpmbuild/BUILD/fakechroot-2.19/test'
make[4]: Entering directory '/home/tkloczko/rpmbuild/BUILD/fakechroot-2.19/test'
PASS: t/test-r.t
make[4]: Leaving directory '/home/tkloczko/rpmbuild/BUILD/fakechroot-2.19/test'
make[4]: Entering directory '/home/tkloczko/rpmbuild/BUILD/fakechroot-2.19/test'
PASS: t/touch.t
make[4]: Leaving directory '/home/tkloczko/rpmbuild/BUILD/fakechroot-2.19/test'
make[4]: Entering directory '/home/tkloczko/rpmbuild/BUILD/fakechroot-2.19/test'
PASS: t/readlink.t
make[4]: Leaving directory '/home/tkloczko/rpmbuild/BUILD/fakechroot-2.19/test'
make[4]: Entering directory '/home/tkloczko/rpmbuild/BUILD/fakechroot-2.19/test'
============================================================================
Testsuite summary for fakechroot 2.19
============================================================================
# TOTAL: 35
# PASS:  34
# SKIP:  0
# XFAIL: 0
# FAIL:  1
# XPASS: 0
# ERROR: 0
============================================================================
See test/test-suite.log
Please report to [email protected]
============================================================================

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.