Hi all, Before writing any code I'd like to ask whether an optional, Linux-only sandbox based on Landlock would be welcome, and if so, how you'd want it scoped.
Motivation ---------- Once initialization is done, OpenVPN spends its life parsing untrusted input: TLS records, the control channel, pushed options. If a memory-safety bug there is ever exploitable, the attacker gets whatever the process can do as its uid: with --user nobody that is still every world-readable file and the ability to write wherever "nobody" can. --chroot narrows this, but it needs a prepared directory tree and in practice is rarely configured. Landlock (Linux 5.13+) lets an unprivileged process permanently restrict its own filesystem access to a set of paths. OpenVPN already knows, from its own options, nearly every file it touches after startup, so the allowlist can be computed automatically rather than configured by hand. Proposal (first step) --------------------- A new option, e.g. --landlock (name open to suggestions), default off. It would be applied at the end of do_uid_gid_chroot() in init.c, after the user/group drop, so it covers the same window. The allowlist would be derived from the options in use: read: crl-verify file (tls_ctx_reload_crl() re-stats and reloads it), ca/cert/key/tls-auth/tls-crypt files unless --persist-key (SIGUSR1 re-reads them), capath directory, auth-user-pass file when it may be re-read, and the resolver files needed to re-resolve --remote on reconnect (/etc/resolv.conf, /etc/hosts, /etc/nsswitch.conf, /etc/gai.conf) write: status file, ifconfig-pool-persist, replay-persist, log / log-append, tmp-dir execute: nothing, in this first step (see below) Everything not on the list becomes inaccessible for the rest of the process lifetime, including after SIGUSR1/SIGHUP restarts. Known constraints ----------------- 1. Scripts and plugins. A Landlock domain is inherited by child processes, and restricting an unprivileged process requires PR_SET_NO_NEW_PRIVS, which would break scripts that rely on setuid helpers such as sudo. My suggestion for the first step is to refuse --landlock together with --script-security 2 or --plugin, with a clear error, rather than half-supporting it. Is that acceptable, or would you rather see script paths added as execute-allowed from the start? 2. Older kernels. Landlock ABI support varies (v1 in 5.13, network rules in v4/6.7). Should an unsupported kernel be a hard error when --landlock is given, or a warning and continue? 3. SIGHUP re-reads the configuration file (per the signals section of the man page), so the config file and anything it references would need to stay readable, or SIGHUP would have to be documented as unsupported with --landlock. Which do you prefer? Possible later steps, only if the first one is useful: Landlock network rules (restrict TCP connect/bind to the configured remotes and management port) and a small seccomp denylist for clearly unneeded syscalls (ptrace, kexec, module loading, bpf, userfaultfd). Why Landlock and not seccomp first ---------------------------------- It needs no syscall allowlist that would have to track libc, OpenSSL, mbedTLS and DCO changes; it is path-based, so it maps directly onto existing options; and a missing path fails with EACCES rather than killing the process. What I'd send ------------- A small patch series through Gerrit: 1. configure/CMake detection of <linux/landlock.h> 2. a sandbox module with Landlock ABI negotiation 3. option parsing, option conflict checks, and the man page entry 4. tests: unit tests for building the allowlist, plus a server/client run checking that CRL reload, status and pool-persist writes still work while an unrelated file becomes unreadable Disclosure: I'm preparing this proposal, and would prepare the patches, with substantial help from an AI coding assistant (Claude). Every patch would be built and run against the full test suite before I send it, and I'll say so in each one. Feedback on whether this is wanted at all, and on the three questions above, would be much appreciated before I start. Thanks, Robson Pereira
_______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel
