Commit Graph

1233 Commits

Author SHA1 Message Date
Robert Swiecki
61250ea20b pid: more logging 2023-10-22 22:39:30 +02:00
Robert Swiecki
e67e8dc2f1 sandbox: better logging 2023-10-21 23:36:00 +02:00
Robert Swiecki
84f6d75d26 convert strcmp() to util::StrEq 2023-10-21 18:37:57 +02:00
Robert Swiecki
98ec95ca85 Use nullptr where appropriate 2023-10-20 18:01:36 +02:00
Robert Swiecki
94b022fece util: implement rLimName() to use in cmdline/config 2023-10-10 01:23:52 +02:00
Robert Swiecki
e7c7583aaa .clangd: Add -Ikafel/include for kafel 2023-10-05 15:39:34 +02:00
Wiktor Garbacz
0c9f755764 update kafel 2023-10-04 15:02:38 +02:00
Robert Swiecki
079d70dda4 .cland: add include to libnl3 2023-10-04 08:34:57 +02:00
Robert Swiecki
3d0bbf6927 cgroups2: make a function declaration-less by moving it earlier 2023-10-04 08:28:18 +02:00
Robert Swiecki
c0e13eebca .clangd: remove unnecessary empty line 2023-10-03 23:22:49 +02:00
Robert Swiecki
ca29f292b6 mnt: reformat messages for PLOG 2023-10-03 23:16:55 +02:00
Robert Swiecki
d99e530134 cmdline: log to stdout if -h or --help was used 2023-10-02 21:12:08 +02:00
Robert Swiecki
50a741cf65 config: adjust identifiers, so they don't repeat config::config.. in method names 2023-10-01 12:57:40 +02:00
Robert Swiecki
fd9a7029d4 .clangd: for nvim/clangd 2023-10-01 12:51:04 +02:00
Robert Swiecki
c1515459d7 contain: fail of fcntl(F_GETFD) fails for a fd with something else then EBADFD 2023-10-01 00:32:29 +02:00
Robert Swiecki
f388cad3e0 contain: use prlimit64 instead of setrlimit64 which seems to be glibc-specific, so it compiles with musl too 2023-09-29 18:11:40 +02:00
Robert Swiecki
fbeac46568 .clang-format: proto specific section 2023-09-22 17:02:01 +02:00
Robert Swiecki
db7f0d0a23 .clang-format: use formatting based on .clang-format 2023-09-22 16:52:19 +02:00
Robert Swiecki
29f0a5b985 Makefile: indent .proto with the same cmd as *.cc *.h 2023-09-22 16:46:52 +02:00
Robert Swiecki
275de833ba indent: use 'AlignEscapedNewlines: Right' to put backslashed in macros at ends of lines 2023-09-22 16:43:40 +02:00
Robert Swiecki
d1b74c2238 util: put QC() in () 2023-09-22 16:40:56 +02:00
Robert Swiecki
d7cf1a9c0d make indent 2023-09-21 08:31:47 +02:00
Robert Swiecki
557633c1de Makefile: move to c++17 to use [[maybe_unused]] and remove DEFER (actually not used) from macros.h 2023-09-21 08:29:36 +02:00
Robert Swiecki
439606be70 Makefile/indent: add AlwaysBreakBeforeMultilineStrings:false 2023-09-19 20:31:57 +02:00
Robert Swiecki
2e27593482 make indent: clang-format-18 2023-09-19 08:45:42 +02:00
Robert Swiecki
b32146cd78 Makefile: simplifications around config.pb.* 2023-09-18 21:29:30 +02:00
Robert Swiecki
3af3eac80f caps: define new CAP_* unconditionally 2023-09-17 10:48:17 +02:00
Robert Swiecki
bc4e7fdd52 cmdline: constify structs 2023-09-15 15:38:37 +02:00
Robert Swiecki
6c5c13017d util/signal: sort signals according to asm/signal.h 2023-09-15 08:47:16 +02:00
Robert Swiecki
47d0e8e6eb pid: clear sigaction before use 2023-09-06 16:50:26 +02:00
Robert Swiecki
d92957c95a util: missing SIGPWR 2023-08-29 09:09:51 +02:00
Robert Swiecki
8308b91c04 subproc: mark cloneFunc as [[noreturn]] 2023-08-18 13:34:09 +02:00
Robert Swiecki
611ef1c435 subproc: support CLONE_CLEAR_SIGHAND 2023-08-18 13:26:01 +02:00
Robert Swiecki
5e494a6a78 subproc: display additional clone3 flags 2023-08-09 18:19:37 +02:00
Robert Swiecki
e507a64e09 configs/: formatting 2023-06-25 12:36:47 +02:00
Robert Swiecki
8804792862 configs/telegram: telegram is 64 bit only 2023-06-25 12:35:25 +02:00
Robert Swiecki
e736d55438 configs/telegram: a new config for the telegram-desktop 2023-06-24 21:04:29 +02:00
okunz
14f1e6852d formatting fix 2023-06-13 11:55:54 +02:00
okunz
924c8fa9f9
Better output formatting for --help 2023-06-13 11:47:21 +02:00
robertswiecki
e1402ed775
Merge pull request #219 from disconnect3d/patch-3
cgroup2.cc: improve note about using Docker
2023-05-30 21:32:12 +02:00
Disconnect3d
f7265e0690
cgroup2.cc: improve note about using Docker
Improve the error log message when Nsjail fails to write to the `/sys/fs/cgroup/cgroup.subtree_control` file when it attempts to setup the cgroupv2 configuration.

The previous message looked like this:

```
[E][2023-05-28T21:52:56+0000][8807] writeBufToFile():105 Couldn't write '7' bytes to file '/sys/fs/cgroup/cgroup.subtree_control' (fd='4'): Device or resource busy
[E][2023-05-28T21:52:56+0000][8807] enableCgroupSubtree():95 Could not apply '+memory' to cgroup.subtree_control in '/sys/fs/cgroup'. If you are running in Docker, nsjail MUST be the root process to use cgroups.
[E][2023-05-28T21:52:56+0000][8807] main():354 Couldn't setup parent cgroup (cgroupv2)
```

It could have been confusing because the nsjail may have already been running as real root with full capabilities, e.g., when the user ran the container with the `--privileged --user 0:0` flags. In such a case, the issue is that Docker enters new pid, uts, network, ipc, mount and cgroup namespaces (but not user or time namespaces, fwiw) and I believe that if you do so after the cgroupv2 filesystem is mounted, the root of its filesystem hierarchy will start to render only a subtree, or, generally a limited view of the cgroup.

This can be seen below. On the host, we can see the cgroup sub-hierarchies and the `cgroup.subtree_control` shows us the controllers properly:

```
# ls /sys/fs/cgroup/
cgroup.controllers      cgroup.threads         dev-mqueue.mount  memory.numa_stat               system.slice
cgroup.max.depth        cpu.pressure           init.scope        memory.pressure                user.slice
cgroup.max.descendants  cpuset.cpus.effective  io.cost.model     memory.stat
cgroup.procs            cpuset.mems.effective  io.cost.qos       sys-fs-fuse-connections.mount
cgroup.stat             cpu.stat               io.pressure       sys-kernel-config.mount
cgroup.subtree_control  dev-hugepages.mount    io.stat           sys-kernel-debug.mount

# cat /sys/fs/cgroup/cgroup.subtree_control 
cpuset cpu io memory hugetlb pids rdma
```

However, even in a privileged container, we can't see the same:

```
# sudo docker run --rm -it --privileged nsjail ls /sys/fs/cgroup
cgroup.controllers	cpuset.cpus		  memory.events.local
cgroup.events		cpuset.cpus.effective	  memory.high
cgroup.freeze		cpuset.cpus.partition	  memory.low
cgroup.kill		cpuset.mems		  memory.max
cgroup.max.depth	cpuset.mems.effective	  memory.min
cgroup.max.descendants	hugetlb.2MB.current	  memory.numa_stat
cgroup.procs		hugetlb.2MB.events	  memory.oom.group
cgroup.stat		hugetlb.2MB.events.local  memory.pressure
cgroup.subtree_control	hugetlb.2MB.max		  memory.stat
cgroup.threads		hugetlb.2MB.rsvd.current  memory.swap.current
cgroup.type		hugetlb.2MB.rsvd.max	  memory.swap.events
cpu.idle		io.latency		  memory.swap.high
cpu.max			io.max			  memory.swap.max
cpu.max.burst		io.pressure		  pids.current
cpu.pressure		io.stat			  pids.events
cpu.stat		io.weight		  pids.max
cpu.weight		memory.current		  rdma.current
cpu.weight.nice		memory.events		  rdma.max

# sudo docker run --rm -it --privileged nsjail cat /sys/fs/cgroup/cgroup.subtree_control
 
# 
```

Of course, the namespaces itself can be seen by comparing them like this:

```
// HOST
# ls -la /proc/self/ns
total 0
dr-x--x--x 2 root root 0 May 28 22:17 .
dr-xr-xr-x 9 root root 0 May 28 22:17 ..
lrwxrwxrwx 1 root root 0 May 28 22:17 cgroup -> 'cgroup:[4026531835]'
lrwxrwxrwx 1 root root 0 May 28 22:17 ipc -> 'ipc:[4026531839]'
lrwxrwxrwx 1 root root 0 May 28 22:17 mnt -> 'mnt:[4026531841]'
lrwxrwxrwx 1 root root 0 May 28 22:17 net -> 'net:[4026531840]'
lrwxrwxrwx 1 root root 0 May 28 22:17 pid -> 'pid:[4026531836]'
lrwxrwxrwx 1 root root 0 May 28 22:17 pid_for_children -> 'pid:[4026531836]'
lrwxrwxrwx 1 root root 0 May 28 22:17 time -> 'time:[4026531834]'
lrwxrwxrwx 1 root root 0 May 28 22:17 time_for_children -> 'time:[4026531834]'
lrwxrwxrwx 1 root root 0 May 28 22:17 user -> 'user:[4026531837]'
lrwxrwxrwx 1 root root 0 May 28 22:17 uts -> 'uts:[4026531838]'

// CONTAINER
# sudo docker run --rm -it --privileged nsjail ls -la /proc/self/ns
total 0
dr-x--x--x 2 user user 0 May 28 22:17 .
dr-xr-xr-x 9 user user 0 May 28 22:17 ..
lrwxrwxrwx 1 user user 0 May 28 22:17 cgroup -> 'cgroup:[4026532381]'
lrwxrwxrwx 1 user user 0 May 28 22:17 ipc -> 'ipc:[4026532317]'
lrwxrwxrwx 1 user user 0 May 28 22:17 mnt -> 'mnt:[4026532315]'
lrwxrwxrwx 1 user user 0 May 28 22:17 net -> 'net:[4026532319]'
lrwxrwxrwx 1 user user 0 May 28 22:17 pid -> 'pid:[4026532318]'
lrwxrwxrwx 1 user user 0 May 28 22:17 pid_for_children -> 'pid:[4026532318]'
lrwxrwxrwx 1 user user 0 May 28 22:17 time -> 'time:[4026531834]'
lrwxrwxrwx 1 user user 0 May 28 22:17 time_for_children -> 'time:[4026531834]'
lrwxrwxrwx 1 user user 0 May 28 22:17 user -> 'user:[4026531837]'
lrwxrwxrwx 1 user user 0 May 28 22:17 uts -> 'uts:[4026532316]'
```

Anyway, passing `--cgroupns=host` solves this problem, which can be seen below:

```
# ls -la /proc/self/ns | grep cgroup
lrwxrwxrwx 1 root root 0 May 28 22:18 cgroup -> cgroup:[4026531835]

# sudo docker run --rm -it --cgroupns=host --privileged nsjail ls -la /proc/self/ns | grep cgroup
lrwxrwxrwx 1 user user 0 May 28 22:19 cgroup -> 'cgroup:[4026531835]'

# sudo docker run --rm -it --privileged nsjail ls -la /proc/self/ns | grep cgroup
lrwxrwxrwx 1 user user 0 May 28 22:19 cgroup -> 'cgroup:[4026532381]'
```
2023-05-29 00:19:31 +02:00
Robert Swiecki
603ba857e9 logs: respect getenv(NO_COLOR) 2023-05-28 09:12:23 +02:00
Robert Swiecki
454cfb509f configs/hexchat: new config based on xchat 2023-05-26 08:42:52 +02:00
Wiktor Garbacz
f920c9194e Mount read-only directly if mounting rw fails
For new mounts if MNT_LOCK_READONLY is locked on the visible mnt
mount_too_revealing will fail and the whole mount will fail.
Those mounts need to be created with the readonly flag set.
2023-05-16 14:07:22 +02:00
Robert Swiecki
5b48117a09 configs/xchat: mount whole /tmp/.X11-unix 2023-01-03 08:11:47 +01:00
Robert Swiecki
c7c0adfffe config.prot: document disable_tsc 2022-11-22 22:25:15 +01:00
Robert Swiecki
2d9b694ca2 Readme: new output 2022-11-22 22:21:50 +01:00
Robert Swiecki
f2dc5966e3 all: unify comments on /**/ 2022-11-22 22:19:05 +01:00
Robert Swiecki
cc4245d23a make indent depend + style of comments 2022-11-22 22:15:01 +01:00
robertswiecki
4437810830
Merge pull request #208 from ndrewh/cgroupsv2-fix
Setup cgroup.subtree_control controllers when necessary in cgroupsv2
2022-11-22 22:12:12 +01:00