How many files are required to download a program on Linux?

The situation (hypothetical at the moment) is that the user of my system will be provided with a piece of C code and I need my system to compile and run it in chroot , which is generated on the fly, and I want to require the smallest number of files as quickly as possible in field. I am only ready to play with the compiler and linker settings (for example, static links, all I can expect to find them) and make some moderate restrictions on what the code can expect (for example, they cannot use arbitrary libraries).

The question is how simple can I get a sandbox. Obviously I need an executable, but what about the ELF and .so loader for system calls? Can I reset any of them, and is there anything else I need?

+3
source share
2 answers

You do not need anything but an executable to run the statically linked world of greeting. Of course, you will need a lot more to compile it.

You can check this pretty easily, I did it with the following trivial C code:

#include <stdio.h>
int main() {
    puts("Hello, world\n");
    return 0;
}

gcc -. ( "chroot-dir" ), ( "hello" ) . , chroot . chroot chroot-dir ./hello, Hello, world.

, , . , ( PAM), PAM . , /etc. getpw * getgr *, .. nsswitch.conf ( , , , , ). /etc/hosts, /etc/services /etc/protocols, , .

, , - strace. , .

+3

ELF. , ldd <executable>. , .so. , , .

, /usr/bin/chroot; int chroot(const char *path); , , , . .

: : TCC (, libtcc, , , C. "" chroot-, "" () (, fork(), "" "" ). libtcc.

0

Source: https://habr.com/ru/post/1744438/


All Articles