Skip to content

Error while loading shared libraries only when using config file #229

@crazynds

Description

@crazynds

Setup

I'm running nsjail inside a docker container, using the last version from github repository today (27/04/2024). The container has the necessary privileges.

The steps I'm using to build nsjail in the Dockerfile:

FROM ubuntu:22.04
# Install the necessary libs...
# Download and install NSJail
RUN git clone https://github.com/google/nsjail.git  /nsjail
RUN cd /nsjail && make && mv /nsjail/nsjail /bin && rm -rf -- /nsjail
# End of dockerfile

Problem

When I execute nsjail with the following args all works fine:
nsjail -Mo -R /bin/ -R /lib -R /lib64/ -R /usr/ -R /sbin/ -T /dev -R /dev/urandom -- /usr/bin/pypy --version
The output is as following:

[I][2024-04-27T23:12:02+0000] Mode: STANDALONE_ONCE
[I][2024-04-27T23:12:02+0000] Jail parameters: hostname:'NSJAIL', chroot:'', process:'/usr/bin/pypy', bind:[::]:0, max_conns:0, max_conns_per_ip:0, time_limit:0, personality:0, daemonize:false, clone_newnet:true, clone_newuser:true, clone_newns:true, clone_newpid:true, clone_newipc:true, clone_newuts:true, clone_newcgroup:true, clone_newtime:false, keep_caps:false, disable_no_new_privs:false, max_cpus:0
[I][2024-04-27T23:12:02+0000] Mount: '/' flags:MS_RDONLY type:'tmpfs' options:'' dir:true
[I][2024-04-27T23:12:02+0000] Mount: '/bin/' -> '/bin/' flags:MS_RDONLY|MS_BIND|MS_REC|MS_PRIVATE type:'' options:'' dir:true
[I][2024-04-27T23:12:02+0000] Mount: '/lib' -> '/lib' flags:MS_RDONLY|MS_BIND|MS_REC|MS_PRIVATE type:'' options:'' dir:true
[I][2024-04-27T23:12:02+0000] Mount: '/lib64/' -> '/lib64/' flags:MS_RDONLY|MS_BIND|MS_REC|MS_PRIVATE type:'' options:'' dir:true
[I][2024-04-27T23:12:02+0000] Mount: '/usr/' -> '/usr/' flags:MS_RDONLY|MS_BIND|MS_REC|MS_PRIVATE type:'' options:'' dir:true
[I][2024-04-27T23:12:02+0000] Mount: '/sbin/' -> '/sbin/' flags:MS_RDONLY|MS_BIND|MS_REC|MS_PRIVATE type:'' options:'' dir:true
[I][2024-04-27T23:12:02+0000] Mount: '/dev' flags: type:'tmpfs' options:'size=4194304' dir:true
[I][2024-04-27T23:12:02+0000] Mount: '/dev/urandom' -> '/dev/urandom' flags:MS_RDONLY|MS_BIND|MS_REC|MS_PRIVATE type:'' options:'' dir:false
[I][2024-04-27T23:12:02+0000] Mount: '/proc' flags:MS_RDONLY type:'proc' options:'' dir:true
[I][2024-04-27T23:12:02+0000] Uid map: inside_uid:0 outside_uid:0 count:1 newuidmap:false
[W][2024-04-27T23:12:02+0000][192] logParams():313 Process will be UID/EUID=0 in the global user namespace, and will have user root-level access to files
[I][2024-04-27T23:12:02+0000] Gid map: inside_gid:0 outside_gid:0 count:1 newgidmap:false
[W][2024-04-27T23:12:02+0000][192] logParams():323 Process will be GID/EGID=0 in the global user namespace, and will have group root-level access to files
[I][2024-04-27T23:12:02+0000] Executing '/usr/bin/pypy' for '[STANDALONE MODE]'
Python 3.10.14 (75b3de9d9035, Apr 21 2024, 10:54:48)
[PyPy 7.3.16 with GCC 10.2.1 20210130 (Red Hat 10.2.1-11)]
[I][2024-04-27T23:12:02+0000] pid=193 ([STANDALONE MODE]) exited with status: 0, (PIDs left: 0)

But when I create a config file with the same specs this dont work:
nsjail --config pypy-env.conf -- /usr/bin/pypy --version

pypy-env.conf

# Example config for nsjail

name: "pypy3.10-env"

mode: ONCE

mount {
	src: "/bin"
	dst: "/bin"
	is_bind: true
}
mount {
	src: "/lib"
	dst: "/lib"
	is_bind: true
}
mount {
	src: "/lib64"
	dst: "/lib64"
	is_bind: true
}
mount {
	src: "/usr"
	dst: "/usr"
	is_bind: true
}
mount {
	src: "/sbin"
	dst: "/sbin"
	is_bind: true
}
mount {
	dst: "/dev"
	fstype: "tmpfs"
	rw: true
	is_bind: false
}

The output is as following:

[I][2024-04-27T23:13:55+0000] Mode: STANDALONE_ONCE
[I][2024-04-27T23:13:55+0000] Jail parameters: hostname:'NSJAIL', chroot:'', process:'/usr/bin/pypy', bind:[::]:0, max_conns:0, max_conns_per_ip:0, time_limit:600, personality:0, daemonize:false, clone_newnet:true, clone_newuser:true, clone_newns:true, clone_newpid:true, clone_newipc:true, clone_newuts:true, clone_newcgroup:true, clone_newtime:false, keep_caps:false, disable_no_new_privs:false, max_cpus:0
[I][2024-04-27T23:13:55+0000] Mount: '/' flags:MS_RDONLY type:'tmpfs' options:'' dir:true
[I][2024-04-27T23:13:55+0000] Mount: '/bin' -> '/bin' flags:MS_RDONLY|MS_BIND|MS_REC|MS_PRIVATE type:'' options:'' dir:true
[I][2024-04-27T23:13:55+0000] Mount: '/lib' -> '/lib' flags:MS_RDONLY|MS_BIND|MS_REC|MS_PRIVATE type:'' options:'' dir:true
[I][2024-04-27T23:13:55+0000] Mount: '/lib64' -> '/lib64' flags:MS_RDONLY|MS_BIND|MS_REC|MS_PRIVATE type:'' options:'' dir:true
[I][2024-04-27T23:13:55+0000] Mount: '/usr' -> '/usr' flags:MS_RDONLY|MS_BIND|MS_REC|MS_PRIVATE type:'' options:'' dir:true
[I][2024-04-27T23:13:55+0000] Mount: '/sbin' -> '/sbin' flags:MS_RDONLY|MS_BIND|MS_REC|MS_PRIVATE type:'' options:'' dir:true
[I][2024-04-27T23:13:55+0000] Mount: '/dev' flags: type:'tmpfs' options:'' dir:true
[I][2024-04-27T23:13:55+0000] Mount: '/var/nsjail/b.py' -> '/var/nsjail/b.py' flags:MS_RDONLY|MS_BIND|MS_REC|MS_PRIVATE type:'' options:'' dir:false
[I][2024-04-27T23:13:55+0000] Uid map: inside_uid:0 outside_uid:0 count:1 newuidmap:false
[W][2024-04-27T23:13:55+0000][196] logParams():313 Process will be UID/EUID=0 in the global user namespace, and will have user root-level access to files
[I][2024-04-27T23:13:55+0000] Gid map: inside_gid:0 outside_gid:0 count:1 newgidmap:false
[W][2024-04-27T23:13:55+0000][196] logParams():323 Process will be GID/EGID=0 in the global user namespace, and will have group root-level access to files
[I][2024-04-27T23:13:55+0000] Executing '/usr/bin/pypy' for '[STANDALONE MODE]'
/usr/bin/pypy: error while loading shared libraries: libpypy3.10-c.so: cannot open shared object file: No such file or directory
[I][2024-04-27T23:13:55+0000] pid=197 ([STANDALONE MODE]) exited with status: 127, (PIDs left: 0)

I notice if I use the same first command but pass in the first arg an empty config file, the error is the same:
nsjail --config empty.conf -Mo -R /bin/ -R /lib -R /lib64/ -R /usr/ -R /sbin/ -T /dev -R /dev/urandom -- /usr/bin/pypy --version

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions