summaryrefslogtreecommitdiff
path: root/jail
Commit message (Collapse)AuthorAgeFilesLines
* jail: don't assume positive return value of creatDaniel Golle2023-01-161-2/+6
| | | | | | | | Handle a (theoretical) error case when calling creat in create_dev_console function. Coverity CID: 1490100 (Argument cannot be negative) Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* jail: fs: don't overwrite existing mount targetDaniel Golle2023-01-161-22/+22
| | | | | | | | | | | | | | Using the creat() function overwrites existing files which is unintended when it comes to making sure the target of a single-file mount exists. Instead, use open() with the O_EXCL flag to make sure mount targets are only created if actually needed. While at it also clean up various error paths of the do_mounts function, making sure the additionally allocated string being created for the path inside the jail's root filesystem is always freed and also making it a bit more readable and less bloated. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* jail: ignore missing .dynamic sectYuteng Zhong2022-11-101-8/+8
| | | | | | | | | | A static-linked binary doesn't have a .dynamic section, but when starting ujail with -r or -w will automatically search for PT_DYNAMIC in ELF and exit with failure if it is not found. github issue: https://github.com/openwrt/openwrt/issues/10933 Signed-off-by: Yuteng Zhong <zonyitoo@qq.com>
* jail: correctly check for null pointerPhilipp Meier2022-11-101-0/+4
| | | | | | Handle case where opts.sysctl is not used. Signed-off-by: Philipp Meier <philipp.meier@westermo.com>
* jail: fix various ignoring return value compilation warningChristian Marangi2022-07-171-8/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fix the following compilation error: jail/jail.c: In function 'main': jail/jail.c:2733:33: error: ignoring return value of 'asprintf' declared with attribute 'warn_unused_result' [-Werror=unused-result] 2733 | asprintf(&opts.envp[envc++], "%s=%s", enve->envarg, tmp); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ jail/jail.c: In function 'build_jail_fs': jail/jail.c:740:24: error: ignoring return value of 'symlink' declared with attribute 'warn_unused_result' [-Werror=unused-result] 740 | (void) symlink("../dev/resolv.conf.d/resolv.conf.auto", jaillink); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ jail/jail.c: In function 'create_devices': jail/jail.c:643:16: error: ignoring return value of 'symlink' declared with attribute 'warn_unused_result' [-Werror=unused-result] 643 | (void) symlink("/dev/pts/ptmx", "/dev/ptmx"); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ jail/jail.c:644:16: error: ignoring return value of 'symlink' declared with attribute 'warn_unused_result' [-Werror=unused-result] 644 | (void) symlink("/proc/self/fd", "/dev/fd"); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ jail/jail.c:645:16: error: ignoring return value of 'symlink' declared with attribute 'warn_unused_result' [-Werror=unused-result] 645 | (void) symlink("/proc/self/fd/0", "/dev/stdin"); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ jail/jail.c:646:16: error: ignoring return value of 'symlink' declared with attribute 'warn_unused_result' [-Werror=unused-result] 646 | (void) symlink("/proc/self/fd/1", "/dev/stdout"); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ jail/jail.c:647:16: error: ignoring return value of 'symlink' declared with attribute 'warn_unused_result' [-Werror=unused-result] 647 | (void) symlink("/proc/self/fd/2", "/dev/stderr"); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
* jail: add WARNING macro to log non critical warning messageChristian Marangi2022-07-171-0/+4
| | | | | | Add an additional WARNING macro to log non critical warning message. Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
* jail: include necessary files for per-netns netifd instanceDaniel Golle2022-04-131-8/+23
| | | | | | | | | | | Up to now only proto 'static' and 'none' have been supported for in-jail interfaces as Shell-based protocol handlers needed some more utilities, PATH set in the environment and /var/ubus/ubus.sock to be mounted on the per-netns-jail ubus socket. Include files needed by shell proto handler, set PATH in env and bend ubus socket path to get DHCP client to work for per-jail netns. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* procd: jail/cgroups: correctly enable "rdma" when requestedRoman Azarenko2022-01-111-1/+1
| | | | | | Fixes a copy-paste error, where "pids" cgroup was enabled instead of "rdma". Signed-off-by: Roman Azarenko <roman.azarenko@iopsys.eu>
* remove ujail-consoleDaniel Golle2021-12-201-221/+0
| | | | | | ujail-console is now integrated in uxc. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* jail: make sure jailed process is terminatedDaniel Golle2021-12-111-2/+15
| | | | | | | | | Don't ever send SIGKILL to ujail, as that will kill ujail but not the jailed process. Instead, let ujail send SIGKILL in case of SIGTERM not succeeding after the term_timeout which procd now passes down to ujail. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* jail: allow passing environment variable to procd jailed processDaniel Golle2021-11-111-1/+44
| | | | | | | | | Introduce new option '-e' to ujail which can be stated multiple times to import environment variables to the jailed process environment. Use that option to import selected environment variables defined for a jailed service instance to its environment. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* jail: elf: Remove MIPS 64 warningHauke Mehrtens2021-11-011-12/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Revert commit 33b799b ("ujail: elf: work around GCC bug on MIPS64") The procd jails are working fine on MIPS64 too now. I saw this error message when add_path_and_deps() was called which calls elf_load_deps() again under some conditions. This is happening because gcc_mips64_bug_work_around is stored in the data segment. We have a call trace like this: elf_load_deps() gcc_mips64_bug_work_around = 1; call add_path_and_deps() call elf_load_deps() gcc_mips64_bug_work_around = 1; error if gcc_mips64_bug_work_around =! 1 gcc_mips64_bug_work_around = 0; return; return; error if gcc_mips64_bug_work_around =! 1 return; I got the same error messages on MIPS 32 BE, when I removed the compile check. This was tested in qemu on MIPS 64 BE and MIPS64 LE. Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
* jail: elf: Use 64 bit variables for elf offsetsHauke Mehrtens2021-11-011-8/+8
| | | | | | | | | | | | | | | | | | | | | | The members p_offset, p_filesz and p_vaddr of the structure Elf64_Phdr are all uint64_t. This structure is used for 64 bit applications. Without this change we would convert the 64 bit values into 32 bit values and an overflow could happen in this conversion. On MIPS 64 BE the variable load_vaddr has the value 0x120000000 which sets the 32th bit which will overflow when converted to a 32 bit value. On 32 bit systems Elf32_Phdr is used with uint32_t, converting this to 64 bit values too should not cause problems as this is not in the hot path. Without this fix I am getting error messages like this at bootup on MIPS 64 BE: [ 16.622602] do_page_fault(): sending SIGSEGV to ujail for invalid read access from 00000100f37251e3 [ 16.622907] epc = 000000aaab4ed0e0 in ujail[aaab4e0000+18000] [ 16.623237] ra = 000000aaab4ed694 in ujail[aaab4e0000+18000] Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
* jail: Fix build with glibcHauke Mehrtens2021-10-221-0/+1
| | | | | | | Add missing include for open(). This fixes the build with glibc. Fixes: 82dd39024f63 ("jail: make use of per-container netifd via ubus") Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
* jail: netifd: check target netns fd before using itDaniel Golle2021-10-171-0/+4
| | | | | | | Make sure filehandler is non-negative before using it. Coverity CID: 1492888 Negative returns Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* jail: netifd: fix error handling issue reported by coverityDaniel Golle2021-10-171-4/+2
| | | | | | | Check asprintf return value instead of checking for NULL-pointer. Coverity CID: 1492158 Unchecked return value Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* jail: netifd: code cosmeticsDaniel Golle2021-10-171-45/+45
| | | | | | | | | Make code more readable by renaming ambigous variable name 'ctx' to 'host_ubus_ctx' (global) or 'uci_ctx' (local in gen_jail_uci_network). Rename 'netifd_ubus_ctx' to 'jail_ubus_ctx' to make the jail vs. host roles more obvious. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* jail: make use of per-container netifd via ubusDaniel Golle2021-10-133-79/+166
| | | | | | | | | | Make ujail expose 'network_reload' function on ubus so we can reconfigure network interfaces inside containers. Automatically call that function on network config changes by subscribing to ubus 'service' object and waiting for 'config.change' events concerning the network configuration. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* jail: netifd: generate netifd uci config and mount itDaniel Golle2021-10-131-9/+140
| | | | | | | | Generate /etc/config/network by filtering the host config for uci sections which are marked for that specific jail. Feed that configuration to the per-container netifd instance. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* jail: fs: add support for asymmetric mount bindDaniel Golle2021-10-133-8/+33
| | | | | | | Allow mounting absolute path on host to defined mountpoint inside container using ':' character in argument of '-r' and '-w' parameters. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* jail: start ubus and netifd instances for container with netnsDaniel Golle2021-09-153-0/+317
| | | | | | | | Start per-container instances of ubusd and netifd for containers with private network namespace. This netifd instance will be used in future to configure networking inside the container. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* Revert "jail: do not hack /etc/resolv.conf on container rootfs"Daniel Golle2021-09-151-1/+1
| | | | This reverts commit b0a8ea1c3fa844d1006764fae3f0d8382351313b.
* jail: prepare for adding process to existing namespaceDaniel Golle2021-09-151-24/+97
| | | | | | | | | | | Introduce '-j' option to ujail which allows joining namespaces of (a) existing process(es). Usage: ujail -j <pid>:<nstype>[,<nstype>[,...]] In order to join namespaces of different processes the '-j' option can be used multiple times. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* jail: actually check calloc return valueDaniel Golle2021-08-311-1/+1
| | | | | | | | | | Instead of checking the return value of calloc(), the check intended for that would rather check if the pointer passed as an argument. As that doesn't make much sense, rather actually check calloc() return value. Coverity CID: 1490071 Dereference before null check Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* jail: protect against strcat buffer overflowsDaniel Golle2021-08-241-4/+7
| | | | | | Coverity CID: 1490012 Copy into fixed size buffer Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* jail: preload: avoid NULL-dereference in case things go wrongDaniel Golle2021-08-241-2/+6
| | | | | | | Coverity CID: 1446096 Dereference after null check Coverity CID: 1446070 Dereference after null check Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* jail: use portable sizeof(void *)Daniel Golle2021-08-241-1/+1
| | | | | | Coverity CID: 1490010 Sizeof not portable Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* jail: check return value when opening consoleDaniel Golle2021-08-241-0/+3
| | | | | | Coverity CID: 1490048 Argument cannot be negative Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* jail: return to hook callback instead of just calling itDaniel Golle2021-08-241-1/+1
| | | | | | | | Avoid stack pollution and potentially worse things. Coverity CID: 1490056 Dereference after null check Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* jail: devices: create parent folder when creating devicesDaniel Golle2021-08-241-3/+25
| | | | | | | Some device nodes live in subdirectories like /dev/dri. Create those folders when populating /dev. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* ujail-console: add missing error handling discovered by coverityDaniel Golle2021-08-141-1/+8
| | | | | Coverity CID: 1490106 Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* jail: fix several issues discovered by CoverityDaniel Golle2021-08-143-24/+39
| | | | | | | | | | | Coverity CID: 1430874 Untrusted pointer read Coverity CID: 1490028 Resource leak Coverity CID: 1490029 Resource leak Coverity CID: 1490057 Uninitialized scalar variable Coverity CID: 1490069 Resource leak Coverity CID: 1490074 Resource leak Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* jail: cgroups-bpf: fix compile with musl 1.2Daniel Golle2021-08-041-1/+2
| | | | | | | musl 1.2 no longer ships with <sys/cdefs.h>. Use it only on glibc, musl provides __WORDSIZE macro in <sys/regs.h>. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* jail: don't ignore return value of write()Daniel Golle2021-08-041-1/+4
| | | | | | Check return value of write() call when writing to sysctl. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* jail: cgroups: replace wrongly used assert()Daniel Golle2021-08-042-12/+32
| | | | | | | In most cases, what we should do is exit(ENOMEM). In some cases like when checking for filehandlers, handle errors appropriately. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* jail: ignore return value when creating default /dev symlinksDaniel Golle2021-08-041-6/+6
| | | | | | | | Just to silence compiler warning, as failure to create these symlinks doesn't indicate an error in all cases, e.g. in case mount is already defined in place of the symlink. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* jail: don't ignore return value of seteuid()Daniel Golle2021-08-041-2/+9
| | | | | | Error out in case seteuid() fails. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* jail: cgroups-bpf: don't use sys/reg.h when building with glibcDaniel Golle2021-08-041-0/+3
| | | | | | To access __WORDSIZE with glibc sys/cdefs.h is included now. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* jail: refactor directory handling for rootfs and overlaydirDaniel Golle2021-07-181-19/+31
| | | | | | | | | | | Resolve symlinks and check if directories exist before clone() call, it's more clean and allows for more code reuse. This partially reverts commits 0114c6fc8b ("jail: open() extroot folder before mounting") as well as 05459054fb ("jail: make use of realpath() for rootfs and overlaydir") and replaces them with a more generic solution. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* jail: make use of realpath() for rootfs and overlaydirDaniel Golle2021-07-171-24/+20
| | | | | | | | Use realpath() to resolve rootfs and read/write-overlay as they are potentially (and likely, as we are going to use blockd with autofs) symlinks. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* jail: open() extroot folder before mountingDaniel Golle2021-07-151-0/+8
| | | | | | | Use open() to trigger autofs mount and check extroot folder exists before mount-binding it. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* jail: allow rootfs to be a symbolic linkDaniel Golle2021-07-151-0/+17
| | | | | | | Follow symbolic link to rootfs so we can use autofs symlinks in /mnt to reference volumes in config.json. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* jail: increase max additional env records to 64Daniel Golle2021-07-151-1/+1
| | | | | | | | | In the Docker world, people pass a lot of things using env variables it turns out. Increase to 64 for now as a hot fix, will have to be created dynamically in future to support unlimited number of env variables. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* jail: do not hack /etc/resolv.conf on container rootfsDaniel Golle2021-07-151-1/+1
| | | | | | | While useful for slim containers, this violates OCI spec and breaks containers like pihole. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* jail: add support for cgroup devices as in OCI run-time specDaniel Golle2021-07-104-13/+503
| | | | | | | | | | | | | Implement eBPF generator to emulate cgroup-v1 devices.{allow,deny} as we got only cgroup-v2 available while the spec was written having cgroups-v1 in mind. Instead of literally emulating the legacy behavior, do like other runtimes do as well when running on cgroup-v2: simply translate each device rule into a bunch of eBPF instructions and then execute them in reverse order, prepended by some default rules covering /dev/null, /dev/random, /dev/tty, ... Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* jail/seccomp: add support for aarch64Daniel Golle2021-03-191-11/+14
| | | | | | | | | | Add support for Aarch64 in utrace and ujail. Sort and unify architecture-specific definitions in headers. Use new PTRACE_GET_SYSCALL_INFO call (available since Linux 5.3), for now only for aarch64, but this may potentially unify things and get rid of some #ifdef'ery for other platforms as well. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* procd: fix compilation with newer muslRosen Penev2021-03-021-1/+1
| | | | | | An open bracket was missing. Signed-off-by: Rosen Penev <rosenp@gmail.com>
* jail: cgroups: fix uninitialized variableDaniel Golle2021-02-021-1/+1
| | | | | | | Make sure 'limit' is initialized to -1 (==max) when translating cgroups-1 memory controller spec to cgroups-2. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* jail: only output BPF instr. table header if debuggingDaniel Golle2021-02-021-2/+3
| | | | Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* jail: remove duplicate check for hook file permissionsDaniel Golle2021-02-021-3/+0
| | | | Signed-off-by: Daniel Golle <daniel@makrotopia.org>