DF-2738 / fix.diff
--- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -47,6 +47,7 @@ #include <sys/malloc.h> #include <sys/proc.h> #include <sys/caps.h> +#include <sys/jail.h> #include <sys/sysmsg.h> #include <sys/lock.h> #include <sys/sbuf.h> @@ -1449,6 +1450,20 @@ return (error); } + /* + * A confined (jailed) root may only write nodes explicitly + * marked CTLFLAG_PRISON ("prisoned roots can fiddle"). + * prison_priv_check() deliberately allows SYSCAP_NOSYSCTL_WR + * inside jails, so without this check a jailed uid-0 can mutate + * host-global state (kern.maxfiles, kern.securelevel, debug.*, + * net.*, ...) even though CTLFLAG_PRISON exists for exactly + * this purpose and is honored nowhere. + */ + if (req->newptr && td->td_ucred && jailed(td->td_ucred) && + (oid->oid_kind & CTLFLAG_PRISON) == 0) { + return (EPERM); + } + if (oid->oid_handler == NULL) return EINVAL; --- a/sys/kern/kern_proc.c +++ b/sys/kern/kern_proc.c @@ -2202,7 +2202,7 @@ SYSCTL_NODE(_kern_proc, KERN_PROC_ARGS, args, - CTLFLAG_RW | CTLFLAG_ANYBODY | CTLFLAG_NOLOCK, + CTLFLAG_RW | CTLFLAG_ANYBODY | CTLFLAG_PRISON | CTLFLAG_NOLOCK, sysctl_kern_proc_args, "Process argument list"); SYSCTL_NODE(_kern_proc, KERN_PROC_CWD, cwd, |