Chroot jail environment puzzle


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Chroot jail environment puzzle
# 1  
Old 11-10-2010
Chroot jail environment puzzle

I have a simple sandbox program which runs a command as user "nobody" in a chroot jail. It sets resource limits with setrlimit, changes the user id with setuid, changes the root dir with chroot, and then calls exec to execute the command given as command line parameters. It is of course a setuid root program so that the call to chroot will work. FWIW, this is on a 64-bit machine running the latest Fedora.

It works fine when running as root; I can do things like:
Code:
   export FOO=bar
   export LD_LIBRARY_PATH=xxx
   export PATH=yyy:$PATH
   /usr/bin/printenv
   sandbox /myjail /usr/bin/printenv

(there is of course a copy of /usr/bin/printenv inside /myjail) and the environment outside the sandbox is exactly the same as inside.

Running it as a normal user, the environment outside the sandbox contains FOO, LD_LIBRARY_PATH, the modified PATH, and other things such as USER, HOME and NLSPATH. Inside the sandbox the environment is the same except that LD_LIBRARY_PATH and NLSPATH are missing!

I cannot for the life of me see why it should victimise these two variables and yet leave the rest of the environment. Can anyone help explain this puzzling behaviour?

TIA...
# 2  
Old 11-10-2010
Setuid/setgid processes in Linux ignore LD_LIBRARY_PATH.
This User Gave Thanks to achenle For This Post:
# 3  
Old 11-10-2010
Thanks for your help. I don't see why it should do this, but... c'est la vie.
The real problem is that I'm trying to run Java inside the sandbox and it moans that it can't locate libjli.so. The only way I know around this is to set LD_LIBRARY_PATH. Can anyone suggest a workaround?
# 4  
Old 11-10-2010
Quote:
Originally Posted by john.english
I don't see why it should do this, but... c'est la vie.
Because that would be an easy way for a casual user to compromise a system, i.e. execute malicious code as root.

---------- Post updated at 13:48 ---------- Previous update was at 13:36 ----------

Quote:
Originally Posted by john.english
The only way I know around this is to set LD_LIBRARY_PATH. Can anyone suggest a workaround?
Why do you need to set LD_LIBRARY_PATH for an internal library that should be found by default by the java run time ?
What says:
Code:
ldd /path-to/java

?
This User Gave Thanks to jlliagre For This Post:
# 5  
Old 11-10-2010
Code:
$ ldd /usr/java/jdk1.6.0_20/jre/bin/java
        libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003ba8e00000)
	libjli.so => /usr/java/jdk1.6.0_20/jre/bin/../lib/amd64/jli/libjli.so (0x00002b1a5dcbc000)
	libdl.so.2 => /lib64/libdl.so.2 (0x0000003ba8a00000)
	libc.so.6 => /lib64/libc.so.6 (0x0000003ba8200000)
	/lib64/ld-linux-x86-64.so.2 (0x0000003ba7e00000)

However, there seems to be a problem with the design of the Java linker/loader, which uses LD_LIBRARY_PATH to set the java.library.path system property.
On Windows it uses PATH for this. And you can't redefine java.library.path using -D on the command line.

Googling elsewhere I found this comment: "For linux you set environment variable LD_LIBRARY_PATH, for windows you set PATH.
IMHO the jdk should have added the value of java.library.path to the search path of the linker loader." What a mess!

Thanks for all your help...
# 6  
Old 11-10-2010
The jli library is found so there should be no need to set the library path. Did you run the ldd command inside the chrooted environment ?
# 7  
Old 11-10-2010
The same, but with libjli.so not found. Running java inside the jail gives me "java: error while loading shared libraries: libjli.so: cannot open shared object file: No such file or directory". I modified my sandbox to copy the value of LD_LIBRARY_SANDBOX to LD_LIBRARY_PATH, and then it works if LD_LIBRARY_SANDBOX is set. So dunno why, but it seems it is needed.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Red Hat

sftp jail chroot env setup

Hi I need a specific user to be able to sftp to a server and get files from a specific location. The location is not the users home dir, i don't want the user to be able to view anything else apart from the files in that area. e.g ftp file are is - /logging/phplogs e.g user home is... (1 Reply)
Discussion started by: duckeggs01
1 Replies

2. UNIX for Dummies Questions & Answers

Creating chroot environment with an ISO file.

I decided to try creating a chroot environment with a BT5r2 iso file. I'm just wanting to run Backtrack from inside Debian without having to reboot into my other partition or use vmware. I found some documentation on how to do this with BT4 at this link: ... (0 Replies)
Discussion started by: Azrael
0 Replies

3. Solaris

Swap puzzle

I'm getting confused by swap # swap -l swapfile dev swaplo blocks free /dev/zvol/dsk/rpool/swap 256,2 16 16777200 16777200 /dev/zvol/dsk/swappool/swap2 256,1 16 50331632 50331632 # swap -s total: 6710256k bytes allocated + 3402944k reserved = 10113200k used,... (6 Replies)
Discussion started by: redstone
6 Replies

4. Debian

SSH chroot jail problems

Firstly Hi everyone :) I setup SFTP and SSH jail using this tutorial: http://www.howtoforge.com/chrooted-ssh-sftp-tutorial-debian-lenny SFTP jail works however now when I try to SSH it accepts my password and then just goes to a blank screen. Type any command and the shell session is... (11 Replies)
Discussion started by: pokey144
11 Replies

5. IP Networking

Puzzle about sctp_bindx in UNP

It writes in Section 9.3 in Unix Network programming about SCTP: "The sctp_bindx call can be used on a bound or unbound socket." And then it writes: "The port number in all the socket address structures must be the same and must match any port number that is already bound; if it doesn't, then... (0 Replies)
Discussion started by: tomdean001
0 Replies

6. UNIX for Dummies Questions & Answers

How to start a chroot jail?

I was reading an article on how it is very important to setup a chroot jail to run bind. I can follow what the article says but one thing I am unclear about is now on system boot the BIND process in the chroot jail will start since it the owner will no longer be root but some other user. Can... (1 Reply)
Discussion started by: mojoman
1 Replies

7. Linux

It's a puzzle

Hi, Recently I installed Fedora 9 on the following hardware - Asus A8N-SLI Deluxe motherboard bios version 1805 - 2GB twinmos ram - AMD 4400 CPU - Tagan PSU 550 W - Asus EN6200LE video card - WD 74 GB Raptor - Areca ARC-1222 raid controller - 4x 1TB Seagate Baracudas - Symbios Logic... (6 Replies)
Discussion started by: jwoude
6 Replies

8. Shell Programming and Scripting

Alias escape puzzle

Here is "escape puzzle" from real life task: Conditions: We need to create an alias which will Save current directory path Will ssh to particular server Then will cd to saved path (it's mounted via NFS) Then will find all files with name patter as "All*.bld" and run particular editor... (0 Replies)
Discussion started by: BaruchLi
0 Replies

9. AIX

chroot environment

Hi!! I'm currently running AIX 4.3.3 and i'm trying to setup a chroot environment for the users who use SFTP, i spend a lot time SFTW but i can't make it work. I got openssh3.9p1 whit the chroot patch. Any help is greatly appreciated. (0 Replies)
Discussion started by: samurai79
0 Replies
Login or Register to Ask a Question