librlimit: rlimit sandbox for any process
- C 78.2%
- Shell 14.4%
- Makefile 7.4%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| test | ||
| .gitignore | ||
| librlimit.c | ||
| LICENSE | ||
| Makefile | ||
| README.md | ||
librlimit
librlimit: rlimit sandbox for any process
DESCRIPTION
librlimit sets up rlimit process restrictions for dynamically linked executables. The restrictions are enforced after the executable has loaded any shared libraries.
The shell ulimit or daemontools softlimit apply to the process
lifetime from fork() to exec(). The process will typically need to
perform operations like opening a file descriptor to linked libraries:
- fork a subprocess
- load shared libraries
- nsswitch: read configuration files
For example:
- ulimit
$ (ulimit -n 0; ls)
ls: error while loading shared libraries: libselinux.so.1: cannot open shared object file: Error 24
- softlimit
$ softlimit -o 0 ls
ls: error while loading shared libraries: libselinux.so.1: cannot open shared object file: Error 24
- librlimit
LD_PRELOAD=librlimit.so RLIMIT_NOFILE=0 ls
ls: cannot open directory '.': Too many open files
EXAMPLES
$ LD_PRELOAD=librlimit.so RLIMIT_FSIZE=0 yes > test
File size limit exceeded (core dumped)
$ LD_PRELOAD=librlimit.so RLIMIT_NPROC=0 sh -c "sleep 60 & sleep 60 & sleep 60 & sleep 60"
sh: 0: Cannot fork
$ LD_PRELOAD=librlimit.so RLIMIT_NOFILE=0 cat -n
abc
1 abc
ENVIRONMENT VARIABLES
- LIBRLIMIT_OPT
- set options for the library behaviour (default: 1)
- 0: no options enabled
- 1: exit with status 111 if setting rlimit fails
- 2: enable debug
- 3: exit on failure and debug enabled
Supported resources are platform dependent. See setrlimit(3).
- RLIMIT_AS
- maximum size of process' virtual memory (address space)
- RLIMIT_CORE
- maximum size of a core file
- RLIMIT_CPU
- limit in seconds on CPU time
- RLIMIT_DATA
- maximum size of the process' data segment
- RLIMIT_FSIZE
- maximum file size in bytes
- RLIMIT_LOCKS
- limits the number of
flock(2)locks andfcntl(2)leases - RLIMIT_MEMLOCK
- maximum number of bytes available to be locked into memory
- RLIMIT_MSGQUEUE
- maximum of bytes allocated for POSIX message queues
- RLIMIT_NICE
- limits priority of process
- RLIMIT_NOFILE
- maximum number of file descriptors
- RLIMIT_NPROC
- maximum number of processes
- RLIMIT_RSS
- maximum number of bytes for a process resident set size
- RLIMIT_RTPRIO
- maximum real-time priority of process
- RLIMIT_RTTIME
- limit in microseconds for real-time scheduled CPU time
- RLIMIT_SIGPENDING
- maximum number of queued signals
- RLIMIT_STACK
- maximum size of process stack
- RLIMIT_SBSIZE
- maximum size of all socket buffers (FreeBSD)
- RLIMIT_VMEM
- virtual process size (incl. mmap) (equivalent to RLIMIT_AS) (FreeBSD)
- RLIMIT_NPTS
- pseudo-terminals (FreeBSD)
- RLIMIT_SWAP
- swap used (FreeBSD)
- RLIMIT_KQUEUES
- kqueues allocated (FreeBSD)
- RLIMIT_UMTXP
- process-shared umtx (FreeBSD)