4

I want to run a simple Haskell program from a jailed environment that I construct myself. The following Haskell program I want to run:

import System.IO

main = do
    hPutStrLn stderr "test standard error!"
    hPutStrLn stdout "test standard out!"

It just outputs a string to stderr and stdout, works perfectly fine outside of the jail. The code is compiled as follows:

ghc -O2 --make -static -optc-static -optl-static $MAINHS -optl-pthread -o bin/run_ai

I get a run_ai executable that runs the program, as I said, this works fine outside of the jail. Below is the stuff that's put inside of the jailed environment and I think there's something missing here, because when I run the program in the jail it does absolutely nothing, it doesn't even exit and no error/output dumps are given at all.

mkdir -p lib64 lib bin

cp /bin/sh bin/

# Binaries
cp /lib64/ld-linux-x86-64.so.2 lib64/

cp /lib/x86_64-linux-gnu/libpthread.so.0 lib/
cp /lib/x86_64-linux-gnu/libc.so.6 lib/
cp /lib/x86_64-linux-gnu/libdl.so.2 lib/
cp /lib/x86_64-linux-gnu/librt.so.1 lib/
cp /lib/x86_64-linux-gnu/libm.so.6 lib/
cp /lib/x86_64-linux-gnu/libtinfo.so.5 lib/
cp /lib/x86_64-linux-gnu/libutil.so.1 lib/
cp /usr/lib/x86_64-linux-gnu/libffi.so.6 lib/
cp /usr/lib/x86_64-linux-gnu/libgmp.so.10 lib/
cp /usr/lib/libgmp.so.3 lib/

I know the jail itself works great, because I've successfully used it for a dozen other programming languages, but Haskell is giving me a headache because I get absolutely nothing on what might be going wrong. Sadly, I'm not an expert on Haskell, but I just need it to compile, and run inside of the jail. Am I missing something that is actually needed to run the executable Haskell file?

So my question is: What am I missing/doing wrong?

AIJim
  • 73
  • 3
  • Does running `ldd` on the binary ghc makes give you any hints that you're missing a .so ? – Squidly Sep 30 '14 at 09:34
  • 6
    Run the program outside of jail under `strace`, look which files it opens. – n. m. could be an AI Sep 30 '14 at 09:55
  • 1
    Probably not right for you, but note that with [PureIO](https://hackage.haskell.org/package/pure-io-0.2.0/docs/PureIO.html) you can "jail" a Haskell `main` all from within the language. – leftaroundabout Sep 30 '14 at 10:20
  • 6
    strace! That's awesome, didn't know that existed and it solved my problem. Apparently Haskell uses /usr/lib/locale/locale-archive to run, so I added that and it works. – AIJim Sep 30 '14 at 11:17

1 Answers1

3

Outside of the jail, run

strace -e open yourprogram

This will print names of all the files your program opens.

n. m. could be an AI
  • 112,515
  • 14
  • 128
  • 243