Commit Graph

23 Commits

Author SHA1 Message Date
Andrew Haberlandt
12df56b9f1 Setup cgroup.subtree_control controllers when necessary in cgroupsv2
This commit adds extra setup when cgroupsv2 is enabled. In particular,
we make sure that the root namespace has setup cgroup.subtree_control
with the controllers we need.

If the necessary controller are not listed, we have to move all
processes out of the root namespace before we can change this
(the 'no internal processes' rule:
https://unix.stackexchange.com/a/713343). Currently we only
handle the case where the nsjail process is the only process in
the cgroup. It seems like this would be relatively rare, but since
nsjail is frequently the root process in a Docker container (e.g.
for hosting CTF challenges), I think this case is common enough to
make it worth implementing.

This also adds `--detect_cgroupv2`, which will attempt to detect
whether `--cgroupv2_mount` is a valid cgroupv2 mount, and if so
it will set `use_cgroupv2`. This is useful in containerized
environments where you may not know the kernel version ahead of time.

References:
https://github.com/redpwn/jail/blob/master/internal/cgroup/cgroup2.go
2022-11-17 17:09:40 -05:00
Robert Swiecki
f628f74b00 mnt: quote paths in log messages 2022-08-09 12:06:42 +02:00
Robert Swiecki
83a28cd0d3 use TEMP_FAILURE_RETRY with some restartable funcs 2019-04-17 23:10:18 +02:00
Robert Swiecki
9782f7bb39 util: call ::syscall for syscall() 2019-01-21 22:42:34 +01:00
Robert Swiecki
681fce1cc4 util: introduce syscall to avoid vararg argument parsing 2019-01-21 22:25:37 +01:00
Robert Swiecki
f2fc5a9406 open might return EINTR 2019-01-06 00:03:36 +01:00
disconnect3d
25a7791d34 Fix utils::writeToFd return type
The `writeToFd` function in `util.cc` returns `ssize_t` but the only
returned values are either `false` or `true`.

```
ssize_t writeToFd(int fd, const void* buf, size_t len) {

(...) return false;

(...) return true;
```
2018-11-24 16:40:30 +01:00
Robert Swiecki
d6e825ddb3 util: c++ version of sprintf 2018-06-16 02:16:24 +02:00
Robert Swiecki
86b36088cf util: remove unused sSnPrintf 2018-05-24 18:32:01 +02:00
Robert Swiecki
2b6955e48c A few c++isms more 2018-05-23 18:19:17 +02:00
Robert Swiecki
c365eb1766 More c++ isms 2018-05-22 14:27:18 +02:00
Robert Swiecki
c4a7af980f util: simplify string splitting 2018-02-20 14:16:28 +01:00
Robert Swiecki
e0374b4642 util: remove file only of O_CREAT was specified 2018-02-17 15:27:00 +01:00
Robert Swiecki
11195999a3 rename ARRAYSIZE to ARR_SZ due to clash with protobufs headers 2018-02-13 16:53:45 +01:00
Robert Swiecki
ff43c5b44b util: int -> size_t 2018-02-12 16:28:45 +01:00
Robert Swiecki
810394cf16 switc all == false cmps to ! 2018-02-12 15:17:33 +01:00
Robert Swiecki
f1a6b08962 cmdline: simplify string splitting 2018-02-11 14:56:30 +01:00
Robert Swiecki
b7f0acb021 util: remove unused functions 2018-02-10 23:54:36 +01:00
Robert Swiecki
f2a52533be convert some funcs returning pointers to to TLS to std::string 2018-02-10 21:19:47 +01:00
Robert Swiecki
97278f191b log: rename log to logs due to clash with glibc's log 2018-02-10 17:49:15 +01:00
Robert Swiecki
1761ed4fdc move common.h to macros.h 2018-02-10 05:25:55 +01:00
Robert Swiecki
7f72cbd497 all: move to C++ 2018-02-09 18:55:42 +01:00
Robert Swiecki
a6c34999f2 util: move to C++ 2018-02-09 18:45:50 +01:00