127 Commits

Author SHA1 Message Date
Alexander Lvov
81784bfbac contain: add core scheduling support (PR_SCHED_CORE)
Adds --use_core_scheduling proto flag that calls prctl(PR_SCHED_CORE_CREATE) in the child process, giving each jail its own SMT scheduling group. Prevents sharing a physical core with other tenants and mitigates L1TF/MDS side-channel attacks in multi-tenant environments. Requires Linux >= 5.14; guarded with #ifdef PR_SCHED_CORE for compatibility with older kernel headers.
2026-06-11 10:33:53 +03:00
Robert Swiecki
ee2d05e874 Integrate a seccomp user notification to trace and log sandboxed filesystem and network operations
* Introduces a dedicated, async worker thread that monitors SECCOMP_RET_USER_NOTIF events
 * Produces telemetry using protobufs to track resolved namespace paths, and network endpoints
2026-04-03 11:20:02 +02:00
Robert Swiecki
0381754dfc nstun: add support for ENCAP_CONNECT - http connect encapsulation 2026-03-31 23:54:57 +02:00
Robert Swiecki
0f8b4a389e nstun: IPv6 implementation 2026-03-31 06:55:27 +02:00
Robert Swiecki
a2bd0b0ad1 nstun: Implement HOST_TO_GUEST forwarding 2026-03-30 07:12:52 +02:00
Robert Swiecki
1d5282c23c net: remove encap for traffic rules (ip-route), it can be done via a backend 2026-03-29 14:37:19 +02:00
Robert Swiecki
95617dd234 config+net: Refactored config.proto to make nstun the default user_net backend. 2026-03-29 13:59:40 +02:00
Robert Swiecki
6276ae6be2 Add nstun, an experimental user-mode networking stack.
It provides lightweight IP-level connectivity for jailed processes via a TUN device and an epoll-based NAT proxy thread, as an alternative to pasta.

Supports TCP, UDP, and ICMP proxying with per-flow tracking, configurable firewall/redirect rules, SOCKS5 encapsulation for TCP and UDP.
2026-03-29 00:30:24 +01:00
Robert Swiecki
91e692a155 net: support for network rules 2026-03-27 21:24:23 +01:00
Robert Swiecki
7a0a622db3 config.proto/net: add explicit ip4_enabled and ip6_enabled 2026-03-24 20:35:01 +01:00
Robert Swiecki
5c21086f89 oom_score_adj + simpler pasta port forwarding config 2026-03-22 21:21:18 +01:00
Robert Swiecki
daea5023b9 net: separate nat from port mappings 2026-03-22 09:56:58 +01:00
Robert Swiecki
d9b197c473 net: add support for mapping tcp/udp ports out 2026-03-22 00:03:15 +01:00
Robert Swiecki
b24be32d38 net/pasta: naming of protocols (ipv4/6 -> ip4/6) 2025-11-23 22:08:52 +01:00
Robert Swiecki
e65aeff358 net/pasta - more config options in config.proto 2025-11-23 21:27:45 +01:00
Robert Swiecki
624ddc6356 net/pasta: control inbound traffic 2025-11-23 15:12:01 +01:00
Robert Swiecki
9e26bdbc63 user-mode networking: use passt (pasta) to provide user-mode networking 2025-11-23 11:23:56 +01:00
Robert Swiecki
86679ca877 config.proto: reflow field numbering 2024-06-27 10:23:31 +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
c7c0adfffe config.prot: document disable_tsc 2022-11-22 22:25:15 +01:00
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
Patrick Steinhardt
df21a972b6 nsjail: Optionally forward fatal signals
Currently, we always kill children by sending them a SIGKILL signal in
case we've got a fatal signal. This is rather inflexible and forbids
some usecases where e.g. child process listen for specific signals to
shut down gracefully.

Add a new command configuration `--forward_signals` that allows the user
to opt-in to forwarding fatal signals to the child process.
2022-06-05 19:38:32 +02:00
Michał Kowalczyk
16b4416d75 Add disable_tsc option
Implemented via prctl(PR_SET_TSC, PR_TSC_SIGSEGV, ...).
2022-02-17 23:53:13 +01:00
Philip
bf93e8a25d cgroup2: use cgroup_mem_swap_max and cgroup_mem_memsw_max 2021-11-01 10:28:41 +01:00
Johan Kartiwa
29a556068a Add support for setting cgroup memory.memsw.limit_in_bytes 2021-10-11 15:46:36 +02:00
Robert Swiecki
d6b9357e6b config.proto: renumerate fields 2021-08-10 19:17:33 +02:00
Wiktor Garbacz
8e13a76b99 Fix duplicate field number 2021-08-04 10:25:38 +02:00
Wiktor Garbacz
95e112cf41 Fix formatting 2021-08-03 17:46:08 +02:00
Wiktor Garbacz
4136dd50d8 Merge branch 'use_switchroot' 2021-08-03 17:44:57 +02:00
Eli Zrihen
7aace9bdc6 rtprio, msgqueue - defaulting to 'soft' 2021-07-20 16:00:13 +03:00
Eli Zrihen
b83d6f7421 Renaming use_switchroot option with no_pivotroot 2021-07-20 15:45:58 +03:00
Eli Zrihen
9f4b4f41e7 Consistentency with RLIMIT_* constant name 2021-07-20 15:20:47 +03:00
Eli Zrihen
0f903ba9a0 Added rt, memlock & msgq limits 2021-07-19 17:21:34 +03:00
Eli Zrihen
dab1713ac9 Added use_switchroot option 2021-06-17 14:57:01 +03:00
Eli Zrihen
5c8b3835b7 MACVLAN modes support 2021-06-16 16:59:12 +03:00
Robert Swiecki
d1f332b911 Enable support for clone3() and for CLONE_NEWTIME 2021-05-18 14:38:01 +02:00
Robert Swiecki
056809ed3b Initial support for CLONE_NEWTIME 2021-05-11 14:48:45 +02:00
Philip Papurt
32f2287fbb net: add support for max_conns 2021-02-09 17:13:35 -05:00
Robert Swiecki
7ca0657316 config.proto: make indent 2020-07-28 14:03:27 +02:00
Robert Swiecki
0a5a5296dd config.proto: renumerate config fields 2020-07-28 14:02:34 +02:00
Disconnect3d
5d103e595a Fixes #146: cgroups_mem_max unit in config.proto
This commit fixes the incorrect cgroups_mem_max unit described in a config.proto comment.

We do not perform any calculations on this value and we don't specify the values unit (k/M/G) when writing to memory cgroup controller files, so the value is specified in bytes.
2020-07-16 14:43:43 +02:00
Robert Swiecki
a2d5b07c76 config: remove deprecated config options 2020-07-09 17:28:56 +02:00
Disconnect3d
7f9ed1ba12 Fix default rlimit_stack value
The default `rlimit_stack` value was set to 1048576. However, this value is in MiB and so is later multiplied by 1024*1024 in b3d544d155/config.cc (L161-L162) and it ends up as a limit of 1 TB for the stack size.

This PR changes it to 8 MB which is a more sane default or, at least I took it from my virtual machine's ulimits:
```
$ ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 31175
max locked memory       (kbytes, -l) 16384
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 31175
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited
```
2019-12-07 17:05:45 +01:00
Robert Swiecki
b3d544d155 config: simplify log/logfd setting 2019-10-02 19:43:58 +02:00
Lukasz Milewski
0bc575063b Fix typo in config.proto: s/lofs/logs/ 2019-09-06 15:08:30 -07:00
Robert Swiecki
e2c5c59bd3 standardize on envar vs envvar 2019-08-28 22:18:58 +02:00
Robert Swiecki
fe762a37b9 config.proto: move disable_rl higher 2019-08-19 14:28:45 +02:00
Jay Lees
86293b052e Add flag to disable rlimits 2019-08-05 03:25:22 -07:00
Robert Swiecki
b120acd5b5 make indent depend 2019-08-04 09:50:34 +02:00
Jay Lees
08f62b6f76 [cgroup-v2] support cgroup v2 for mem, cpu and pids 2019-07-26 07:02:17 -07:00