Commit Graph

48 Commits

Author SHA1 Message Date
Robert Swiecki
229682c59e Merge pull request #292 from M0nd0R/fix-mount-staging-escape
Reject path traversal in mount destinations during jail staging
2026-08-26 21:20:27 +02:00
mundur
9b54e97fd4 Reject path traversal in mount destinations during jail staging
Mount destinations were joined as newroot+"/"+dst and walked with
mkdirat/openat without rejecting "."/".." components or following
symlinks safely. An attacker who can influence mount dst (CLI, config,
or prefix_dst_env) could create directories, symlinks, or mounts outside
the intended staging root on the host before pivot_root.

Add isSafeContainmentPath(), validate destinations in both legacy and
new mount APIs, use O_NOFOLLOW while walking parents, and include a
standalone regression test.
2026-07-27 10:53:58 +00:00
attaboy11
0a21f80078 Reject invalid integer command-line arguments 2026-07-16 19:50:07 +01:00
Robert Swiecki
b7ff9f3018 util/missing_defs: new support functions + a file defining missing syscall numbers/defs 2026-04-09 22:44:32 +02:00
Robert Swiecki
408d49ed48 mnt: consolidate EROFS fallbacks into errno-preserving helpers 2026-04-02 15:00:33 +02:00
robertswiecki
f1a9dc67b1 Merge pull request #260 from nemmyam/fix-erofs-mkdir-readonly-mounts
mnt: handle EROFS from mkdir/open on read-only mounts
2026-04-02 14:56:14 +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
Nemmy
5c5ddf7def mnt: handle EROFS from mkdir/open on read-only mounts
mkdir() can return EROFS instead of EEXIST for existing entries on
read-only mounts (e.g. NFS). Fall back to stat()/fstatat() on EROFS
and proceed if the entry exists with the expected type.
2026-03-20 13:43:23 -03:00
Robert Swiecki
d8ea726682 Implement support for the new Linux mount API and refactor mount logic into dedicated files. Added the --experimental_mnt flag to allow forcing legacy or new mount behaviors. 2026-01-31 16:05:58 +01:00
Robert Swiecki
7041800e8f contain/util: implement global close-on-exec via close_range(2). Available since Linux kernel 5.11 2025-09-23 07:08:57 +02:00
Robert Swiecki
cf6f4f6dfa make indent 2025-01-07 09:42:14 +01:00
Robert Swiecki
0982bc9779 logging: no need to use '%s' with QC() 2024-06-26 21:24:02 +02:00
Robert Swiecki
6ca807a988 util: provide readFromFileToStr primitive, which doesn't throw exceptions 2024-06-26 08:19:38 +02:00
Robert Swiecki
b740dcf57a make indent 2023-12-02 23:24:16 +01:00
happyCoder92
d68db32b06 Fix deleted brace 2023-11-28 14:16:17 +01:00
happyCoder92
23a1b85087 Make util::gerlimit compatible with MSAN 2023-11-28 14:11:08 +01: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
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
439606be70 Makefile/indent: add AlwaysBreakBeforeMultilineStrings:false 2023-09-19 20:31:57 +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
d92957c95a util: missing SIGPWR 2023-08-29 09:09:51 +02:00
Robert Swiecki
cc4245d23a make indent depend + style of comments 2022-11-22 22:15:01 +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
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