115103Sphk/*- 215103Sphk * Copyright (c) 1982, 1986, 1989, 1993 315103Sphk * The Regents of the University of California. All rights reserved. 415103Sphk * 515103Sphk * This code is derived from software contributed to Berkeley by 615103Sphk * Mike Karels at Berkeley Software Design, Inc. 715103Sphk * 815103Sphk * Quite extensively rewritten by Poul-Henning Kamp of the FreeBSD 915103Sphk * project, to make these variables more userfriendly. 1015103Sphk * 1115103Sphk * Redistribution and use in source and binary forms, with or without 1215103Sphk * modification, are permitted provided that the following conditions 1315103Sphk * are met: 1415103Sphk * 1. Redistributions of source code must retain the above copyright 1515103Sphk * notice, this list of conditions and the following disclaimer. 1615103Sphk * 2. Redistributions in binary form must reproduce the above copyright 1715103Sphk * notice, this list of conditions and the following disclaimer in the 1815103Sphk * documentation and/or other materials provided with the distribution. 1915103Sphk * 4. Neither the name of the University nor the names of its contributors 2015103Sphk * may be used to endorse or promote products derived from this software 2115103Sphk * without specific prior written permission. 2215103Sphk * 2315103Sphk * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2415103Sphk * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2515103Sphk * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2615103Sphk * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2715103Sphk * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2815103Sphk * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2915103Sphk * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3015103Sphk * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3115103Sphk * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3215103Sphk * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3315103Sphk * SUCH DAMAGE. 3415103Sphk * 3515103Sphk * @(#)kern_sysctl.c 8.4 (Berkeley) 4/14/94 3615103Sphk */ 3715103Sphk 38116182Sobrien#include <sys/cdefs.h> 39116182Sobrien__FBSDID("$FreeBSD: stable/11/sys/kern/kern_mib.c 361212 2020-05-18 14:38:27Z kib $"); 40116182Sobrien 41175417Sjhb#include "opt_compat.h" 4286190Srwatson#include "opt_posix.h" 43169604Swkoszek#include "opt_config.h" 4484611Srwatson 4515103Sphk#include <sys/param.h> 46284959Smarkm#include <sys/jail.h> 4715103Sphk#include <sys/kernel.h> 48342781Skib#include <sys/limits.h> 4987275Srwatson#include <sys/lock.h> 5087275Srwatson#include <sys/mutex.h> 51284959Smarkm#include <sys/proc.h> 52284959Smarkm#include <sys/random.h> 53284959Smarkm#include <sys/sbuf.h> 5476078Sjhb#include <sys/smp.h> 55192895Sjamie#include <sys/sx.h> 56331017Skevans#include <sys/vmmeter.h> 57284959Smarkm#include <sys/sysctl.h> 58284959Smarkm#include <sys/systm.h> 59105046Smike#include <sys/unistd.h> 6028918Skato 61267992ShselaskySYSCTL_ROOT_NODE(0, sysctl, CTLFLAG_RW, 0, 6215103Sphk "Sysctl internal magic"); 63267992ShselaskySYSCTL_ROOT_NODE(CTL_KERN, kern, CTLFLAG_RW|CTLFLAG_CAPRD, 0, 6415103Sphk "High kernel, proc, limits &c"); 65267992ShselaskySYSCTL_ROOT_NODE(CTL_VM, vm, CTLFLAG_RW, 0, 6615103Sphk "Virtual memory"); 67267992ShselaskySYSCTL_ROOT_NODE(CTL_VFS, vfs, CTLFLAG_RW, 0, 6815103Sphk "File system"); 69267992ShselaskySYSCTL_ROOT_NODE(CTL_NET, net, CTLFLAG_RW, 0, 7015103Sphk "Network, (see socket.h)"); 71267992ShselaskySYSCTL_ROOT_NODE(CTL_DEBUG, debug, CTLFLAG_RW, 0, 7215103Sphk "Debugging"); 7348891SphkSYSCTL_NODE(_debug, OID_AUTO, sizeof, CTLFLAG_RW, 0, 7448891Sphk "Sizeof various things"); 75267992ShselaskySYSCTL_ROOT_NODE(CTL_HW, hw, CTLFLAG_RW, 0, 7615103Sphk "hardware"); 77267992ShselaskySYSCTL_ROOT_NODE(CTL_MACHDEP, machdep, CTLFLAG_RW, 0, 7815103Sphk "machine dependent"); 79354762SscottlSYSCTL_NODE(_machdep, OID_AUTO, mitigations, CTLFLAG_RW, 0, 80354762Sscottl "Machine dependent platform mitigations."); 81267992ShselaskySYSCTL_ROOT_NODE(CTL_USER, user, CTLFLAG_RW, 0, 8215103Sphk "user-level"); 83267992ShselaskySYSCTL_ROOT_NODE(CTL_P1003_1B, p1003_1b, CTLFLAG_RW, 0, 8434925Sdufault "p1003_1b, (see p1003_1b.h)"); 8534029Sdufault 86267992ShselaskySYSCTL_ROOT_NODE(OID_AUTO, compat, CTLFLAG_RW, 0, 8750465Smarcel "Compatibility code"); 88267992ShselaskySYSCTL_ROOT_NODE(OID_AUTO, security, CTLFLAG_RW, 0, 8989414Sarr "Security"); 9086190Srwatson#ifdef REGRESSION 91267992ShselaskySYSCTL_ROOT_NODE(OID_AUTO, regression, CTLFLAG_RW, 0, 9286190Srwatson "Regression test MIB"); 9386190Srwatson#endif 9450465Smarcel 95187864SedSYSCTL_STRING(_kern, OID_AUTO, ident, CTLFLAG_RD|CTLFLAG_MPSAFE, 96116105Sjmallett kern_ident, 0, "Kernel identifier"); 97116090Sjmallett 98224159SrwatsonSYSCTL_INT(_kern, KERN_OSREV, osrevision, CTLFLAG_RD|CTLFLAG_CAPRD, 99273377Shselasky SYSCTL_NULL_INT_PTR, BSD, "Operating system revision"); 10015103Sphk 101187864SedSYSCTL_STRING(_kern, KERN_VERSION, version, CTLFLAG_RD|CTLFLAG_MPSAFE, 10246381Sbillf version, 0, "Kernel version"); 10315103Sphk 104246254SavgSYSCTL_STRING(_kern, OID_AUTO, compiler_version, CTLFLAG_RD|CTLFLAG_MPSAFE, 105246246Savg compiler_version, 0, "Version of compiler used to compile kernel"); 106246246Savg 107224159SrwatsonSYSCTL_STRING(_kern, KERN_OSTYPE, ostype, CTLFLAG_RD|CTLFLAG_MPSAFE| 108224159Srwatson CTLFLAG_CAPRD, ostype, 0, "Operating system type"); 10915103Sphk 110267992ShselaskySYSCTL_INT(_kern, KERN_MAXPROC, maxproc, CTLFLAG_RDTUN | CTLFLAG_NOFETCH, 11146381Sbillf &maxproc, 0, "Maximum number of processes"); 11215103Sphk 11386189SrwatsonSYSCTL_INT(_kern, KERN_MAXPROCPERUID, maxprocperuid, CTLFLAG_RW, 11446381Sbillf &maxprocperuid, 0, "Maximum processes allowed per userid"); 11515103Sphk 116267992ShselaskySYSCTL_INT(_kern, OID_AUTO, maxusers, CTLFLAG_RDTUN | CTLFLAG_NOFETCH, 11780418Speter &maxusers, 0, "Hint for kernel tuning"); 11880418Speter 119224159SrwatsonSYSCTL_INT(_kern, KERN_ARGMAX, argmax, CTLFLAG_RD|CTLFLAG_CAPRD, 120273377Shselasky SYSCTL_NULL_INT_PTR, ARG_MAX, "Maximum bytes of argument to execve(2)"); 12115103Sphk 122224159SrwatsonSYSCTL_INT(_kern, KERN_POSIX1, posix1version, CTLFLAG_RD|CTLFLAG_CAPRD, 123273377Shselasky SYSCTL_NULL_INT_PTR, _POSIX_VERSION, "Version of POSIX attempting to comply to"); 12415103Sphk 125267992ShselaskySYSCTL_INT(_kern, KERN_NGROUPS, ngroups, CTLFLAG_RDTUN | 126267992Shselasky CTLFLAG_NOFETCH | CTLFLAG_CAPRD, &ngroups_max, 0, 127201953Sbrooks "Maximum number of supplemental groups a user can belong to"); 12815103Sphk 129224159SrwatsonSYSCTL_INT(_kern, KERN_JOB_CONTROL, job_control, CTLFLAG_RD|CTLFLAG_CAPRD, 130273377Shselasky SYSCTL_NULL_INT_PTR, 1, "Whether job control is available"); 13115103Sphk 13215103Sphk#ifdef _POSIX_SAVED_IDS 133224159SrwatsonSYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD|CTLFLAG_CAPRD, 134273377Shselasky SYSCTL_NULL_INT_PTR, 1, "Whether saved set-group/user ID is available"); 13515103Sphk#else 136224159SrwatsonSYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD|CTLFLAG_CAPRD, 137273377Shselasky SYSCTL_NULL_INT_PTR, 0, "Whether saved set-group/user ID is available"); 13815103Sphk#endif 13915103Sphk 140347637Sgonzochar kernelname[MAXPATHLEN] = "/boot/kernel/kernel"; /* XXX bloat */ 14115103Sphk 142310970SmjgSYSCTL_STRING(_kern, KERN_BOOTFILE, bootfile, CTLFLAG_RW | CTLFLAG_MPSAFE, 14346381Sbillf kernelname, sizeof kernelname, "Name of kernel file booted"); 14415103Sphk 145224159SrwatsonSYSCTL_INT(_hw, HW_NCPU, ncpu, CTLFLAG_RD|CTLFLAG_CAPRD, 14646381Sbillf &mp_ncpus, 0, "Number of active CPUs"); 14715103Sphk 148224159SrwatsonSYSCTL_INT(_hw, HW_BYTEORDER, byteorder, CTLFLAG_RD|CTLFLAG_CAPRD, 149273377Shselasky SYSCTL_NULL_INT_PTR, BYTE_ORDER, "System byte order"); 15015103Sphk 151224159SrwatsonSYSCTL_INT(_hw, HW_PAGESIZE, pagesize, CTLFLAG_RD|CTLFLAG_CAPRD, 152273377Shselasky SYSCTL_NULL_INT_PTR, PAGE_SIZE, "System memory page size"); 15315103Sphk 154106605Stmmstatic int 155169727Skansysctl_kern_arnd(SYSCTL_HANDLER_ARGS) 156169727Skan{ 157176367Santoine char buf[256]; 158176367Santoine size_t len; 159169727Skan 160284959Smarkm /*- 161284959Smarkm * This is one of the very few legitimate uses of read_random(9). 162284959Smarkm * Use of arc4random(9) is not recommended as that will ignore 163284959Smarkm * an unsafe (i.e. unseeded) random(4). 164284959Smarkm * 165284959Smarkm * If random(4) is not seeded, then this returns 0, so the 166284959Smarkm * sysctl will return a zero-length buffer. 167284959Smarkm */ 168284959Smarkm len = read_random(buf, MIN(req->oldlen, sizeof(buf))); 169176367Santoine return (SYSCTL_OUT(req, buf, len)); 170169727Skan} 171169727Skan 172187864SedSYSCTL_PROC(_kern, KERN_ARND, arandom, 173224159Srwatson CTLTYPE_OPAQUE | CTLFLAG_RD | CTLFLAG_MPSAFE | CTLFLAG_CAPRD, NULL, 0, 174187864Sed sysctl_kern_arnd, "", "arc4rand"); 175169727Skan 176169727Skanstatic int 177106605Stmmsysctl_hw_physmem(SYSCTL_HANDLER_ARGS) 178106605Stmm{ 179342781Skib u_long val, p; 180106605Stmm 181342781Skib p = SIZE_T_MAX >> PAGE_SHIFT; 182342781Skib if (physmem < p) 183342781Skib p = physmem; 184342781Skib val = ctob(p); 185106605Stmm return (sysctl_handle_long(oidp, &val, 0, req)); 186106605Stmm} 187106605StmmSYSCTL_PROC(_hw, HW_PHYSMEM, physmem, CTLTYPE_ULONG | CTLFLAG_RD, 188345827Srpokala 0, 0, sysctl_hw_physmem, "LU", 189345827Srpokala "Amount of physical memory (in bytes)"); 190106605Stmm 191106605Stmmstatic int 192142834Swessysctl_hw_realmem(SYSCTL_HANDLER_ARGS) 193142834Swes{ 194342781Skib u_long val, p; 195342781Skib 196342781Skib p = SIZE_T_MAX >> PAGE_SHIFT; 197342781Skib if (realmem < p) 198342781Skib p = realmem; 199342781Skib val = ctob(p); 200142834Swes return (sysctl_handle_long(oidp, &val, 0, req)); 201142834Swes} 202142834SwesSYSCTL_PROC(_hw, HW_REALMEM, realmem, CTLTYPE_ULONG | CTLFLAG_RD, 203345827Srpokala 0, 0, sysctl_hw_realmem, "LU", 204345827Srpokala "Amount of memory (in bytes) reported by the firmware"); 205342781Skib 206142834Swesstatic int 207106605Stmmsysctl_hw_usermem(SYSCTL_HANDLER_ARGS) 208106605Stmm{ 209342781Skib u_long val, p, p1; 210106605Stmm 211342781Skib p1 = physmem - vm_cnt.v_wire_count; 212342781Skib p = SIZE_T_MAX >> PAGE_SHIFT; 213342781Skib if (p1 < p) 214342781Skib p = p1; 215342781Skib val = ctob(p); 216106605Stmm return (sysctl_handle_long(oidp, &val, 0, req)); 217106605Stmm} 218106605StmmSYSCTL_PROC(_hw, HW_USERMEM, usermem, CTLTYPE_ULONG | CTLFLAG_RD, 219345827Srpokala 0, 0, sysctl_hw_usermem, "LU", 220345827Srpokala "Amount of memory (in bytes) which is not wired"); 221106605Stmm 222345827SrpokalaSYSCTL_LONG(_hw, OID_AUTO, availpages, CTLFLAG_RD, &physmem, 0, 223345827Srpokala "Amount of physical memory (in pages)"); 224106605Stmm 225197316Salcu_long pagesizes[MAXPAGESIZES] = { PAGE_SIZE }; 226197316Salc 227197316Salcstatic int 228197316Salcsysctl_hw_pagesizes(SYSCTL_HANDLER_ARGS) 229197316Salc{ 230197316Salc int error; 231361109Skib size_t len; 232197316Salc#ifdef SCTL_MASK32 233197316Salc int i; 234197316Salc uint32_t pagesizes32[MAXPAGESIZES]; 235197316Salc 236197316Salc if (req->flags & SCTL_MASK32) { 237197316Salc /* 238361212Skib * Recreate the "pagesizes" array with 32-bit elements. 239361212Skib * Truncate any page size greater than UINT32_MAX to zero, 240361212Skib * which assumes that page sizes are powers of two. 241197316Salc */ 242197316Salc for (i = 0; i < MAXPAGESIZES; i++) 243197316Salc pagesizes32[i] = (uint32_t)pagesizes[i]; 244197316Salc 245361109Skib len = sizeof(pagesizes32); 246361109Skib if (len > req->oldlen) 247361109Skib len = req->oldlen; 248361109Skib error = SYSCTL_OUT(req, pagesizes32, len); 249197316Salc } else 250197316Salc#endif 251361109Skib { 252361109Skib len = sizeof(pagesizes); 253361109Skib if (len > req->oldlen) 254361109Skib len = req->oldlen; 255361109Skib error = SYSCTL_OUT(req, pagesizes, len); 256361109Skib } 257197316Salc return (error); 258197316Salc} 259197316SalcSYSCTL_PROC(_hw, OID_AUTO, pagesizes, CTLTYPE_ULONG | CTLFLAG_RD, 260197316Salc NULL, 0, sysctl_hw_pagesizes, "LU", "Supported page sizes"); 261197316Salc 262210369Skib#ifdef SCTL_MASK32 263210369Skibint adaptive_machine_arch = 1; 264210369SkibSYSCTL_INT(_debug, OID_AUTO, adaptive_machine_arch, CTLFLAG_RW, 265210369Skib &adaptive_machine_arch, 1, 266210369Skib "Adapt reported machine architecture to the ABI of the binary"); 267210369Skib#endif 26828885Skato 26946155Sphkstatic int 270210369Skibsysctl_hw_machine_arch(SYSCTL_HANDLER_ARGS) 271210369Skib{ 272210369Skib int error; 273210369Skib static const char machine_arch[] = MACHINE_ARCH; 274210369Skib#ifdef SCTL_MASK32 275210369Skib static const char machine_arch32[] = MACHINE_ARCH32; 276210369Skib 277210369Skib if ((req->flags & SCTL_MASK32) != 0 && adaptive_machine_arch) 278210369Skib error = SYSCTL_OUT(req, machine_arch32, sizeof(machine_arch32)); 279210369Skib else 280210369Skib#endif 281210369Skib error = SYSCTL_OUT(req, machine_arch, sizeof(machine_arch)); 282210369Skib return (error); 283210369Skib 284210369Skib} 285310970SmjgSYSCTL_PROC(_hw, HW_MACHINE_ARCH, machine_arch, CTLTYPE_STRING | CTLFLAG_RD | 286310970Smjg CTLFLAG_MPSAFE, NULL, 0, sysctl_hw_machine_arch, "A", 287310970Smjg "System architecture"); 288210369Skib 289258928SnwhitehornSYSCTL_STRING(_kern, OID_AUTO, supported_archs, CTLFLAG_RD | CTLFLAG_MPSAFE, 290258819Snwhitehorn#ifdef COMPAT_FREEBSD32 291258928Snwhitehorn MACHINE_ARCH " " MACHINE_ARCH32, 0, "Supported architectures for binaries"); 292258819Snwhitehorn#else 293258928Snwhitehorn MACHINE_ARCH, 0, "Supported architectures for binaries"); 294258819Snwhitehorn#endif 295258819Snwhitehorn 296210369Skibstatic int 29762573Sphksysctl_hostname(SYSCTL_HANDLER_ARGS) 29846155Sphk{ 299193066Sjamie struct prison *pr, *cpr; 300193066Sjamie size_t pr_offset; 301193066Sjamie char tmpname[MAXHOSTNAMELEN]; 302193066Sjamie int descend, error, len; 30315103Sphk 304193066Sjamie /* 305193066Sjamie * This function can set: hostname domainname hostuuid. 306193066Sjamie * Keep that in mind when comments say "hostname". 307193066Sjamie */ 308193066Sjamie pr_offset = (size_t)arg1; 309193066Sjamie len = arg2; 310193066Sjamie KASSERT(len <= sizeof(tmpname), 311193066Sjamie ("length %d too long for %s", len, __func__)); 312193066Sjamie 31391406Sjhb pr = req->td->td_ucred->cr_prison; 314193066Sjamie if (!(pr->pr_allow & PR_ALLOW_SET_HOSTNAME) && req->newptr) 315193066Sjamie return (EPERM); 316193066Sjamie /* 317193066Sjamie * Make a local copy of hostname to get/set so we don't have to hold 318193066Sjamie * the jail mutex during the sysctl copyin/copyout activities. 319193066Sjamie */ 320193066Sjamie mtx_lock(&pr->pr_mtx); 321193066Sjamie bcopy((char *)pr + pr_offset, tmpname, len); 322193066Sjamie mtx_unlock(&pr->pr_mtx); 323193066Sjamie 324193066Sjamie error = sysctl_handle_string(oidp, tmpname, len, req); 325193066Sjamie 326193066Sjamie if (req->newptr != NULL && error == 0) { 32787275Srwatson /* 328193066Sjamie * Copy the locally set hostname to all jails that share 329193066Sjamie * this host info. 33087275Srwatson */ 331193066Sjamie sx_slock(&allprison_lock); 332193066Sjamie while (!(pr->pr_flags & PR_HOST)) 333193066Sjamie pr = pr->pr_parent; 33487275Srwatson mtx_lock(&pr->pr_mtx); 335193066Sjamie bcopy(tmpname, (char *)pr + pr_offset, len); 336193066Sjamie FOREACH_PRISON_DESCENDANT_LOCKED(pr, cpr, descend) 337193066Sjamie if (cpr->pr_flags & PR_HOST) 338193066Sjamie descend = 0; 339193066Sjamie else 340193066Sjamie bcopy(tmpname, (char *)cpr + pr_offset, len); 34187275Srwatson mtx_unlock(&pr->pr_mtx); 342193066Sjamie sx_sunlock(&allprison_lock); 343180291Srwatson } 34446155Sphk return (error); 34546155Sphk} 34646155Sphk 34786189SrwatsonSYSCTL_PROC(_kern, KERN_HOSTNAME, hostname, 348193066Sjamie CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE, 349194118Sjamie (void *)(offsetof(struct prison, pr_hostname)), MAXHOSTNAMELEN, 350193066Sjamie sysctl_hostname, "A", "Hostname"); 351193066SjamieSYSCTL_PROC(_kern, KERN_NISDOMAINNAME, domainname, 352193066Sjamie CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE, 353194118Sjamie (void *)(offsetof(struct prison, pr_domainname)), MAXHOSTNAMELEN, 354193066Sjamie sysctl_hostname, "A", "Name of the current YP/NIS domain"); 355193066SjamieSYSCTL_PROC(_kern, KERN_HOSTUUID, hostuuid, 356193066Sjamie CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE, 357194118Sjamie (void *)(offsetof(struct prison, pr_hostuuid)), HOSTUUIDLEN, 358193066Sjamie sysctl_hostname, "A", "Host UUID"); 35946155Sphk 36086190Srwatsonstatic int regression_securelevel_nonmonotonic = 0; 36184611Srwatson 36287072Srwatson#ifdef REGRESSION 36384611SrwatsonSYSCTL_INT(_regression, OID_AUTO, securelevel_nonmonotonic, CTLFLAG_RW, 36484611Srwatson ®ression_securelevel_nonmonotonic, 0, "securelevel may be lowered"); 36586190Srwatson#endif 36684611Srwatson 36715103Sphkstatic int 36862573Sphksysctl_kern_securelvl(SYSCTL_HANDLER_ARGS) 36915103Sphk{ 370192895Sjamie struct prison *pr, *cpr; 371192895Sjamie int descend, error, level; 37215103Sphk 37391406Sjhb pr = req->td->td_ucred->cr_prison; 37486145Srwatson 37586140Srwatson /* 376192895Sjamie * Reading the securelevel is easy, since the current jail's level 377192895Sjamie * is known to be at least as secure as any higher levels. Perform 378192895Sjamie * a lockless read since the securelevel is an integer. 37986140Srwatson */ 380192895Sjamie level = pr->pr_securelevel; 38186140Srwatson error = sysctl_handle_int(oidp, &level, 0, req); 38286140Srwatson if (error || !req->newptr) 38386140Srwatson return (error); 384192895Sjamie /* Permit update only if the new securelevel exceeds the old. */ 385192895Sjamie sx_slock(&allprison_lock); 386192895Sjamie mtx_lock(&pr->pr_mtx); 387192895Sjamie if (!regression_securelevel_nonmonotonic && 388192895Sjamie level < pr->pr_securelevel) { 389192895Sjamie mtx_unlock(&pr->pr_mtx); 390192895Sjamie sx_sunlock(&allprison_lock); 391192895Sjamie return (EPERM); 392192895Sjamie } 393192895Sjamie pr->pr_securelevel = level; 39486140Srwatson /* 395192895Sjamie * Set all child jails to be at least this level, but do not lower 396192895Sjamie * them (even if regression_securelevel_nonmonotonic). 39786140Srwatson */ 398192895Sjamie FOREACH_PRISON_DESCENDANT_LOCKED(pr, cpr, descend) { 399192895Sjamie if (cpr->pr_securelevel < level) 400192895Sjamie cpr->pr_securelevel = level; 40186140Srwatson } 402192895Sjamie mtx_unlock(&pr->pr_mtx); 403192895Sjamie sx_sunlock(&allprison_lock); 40486140Srwatson return (error); 40515103Sphk} 40615103Sphk 40783990SrwatsonSYSCTL_PROC(_kern, KERN_SECURELVL, securelevel, 40883990Srwatson CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_PRISON, 0, 0, sysctl_kern_securelvl, 40983990Srwatson "I", "Current secure level"); 41061370Srwatson 411169604Swkoszek#ifdef INCLUDE_CONFIG_FILE 412169507Swkoszek/* Actual kernel configuration options. */ 413169507Swkoszekextern char kernconfstring[]; 414169507Swkoszek 415310970SmjgSYSCTL_STRING(_kern, OID_AUTO, conftxt, CTLFLAG_RD | CTLFLAG_MPSAFE, 416310970Smjg kernconfstring, 0, "Kernel configuration file"); 417169650Simp#endif 418169507Swkoszek 419180291Srwatsonstatic int 420193066Sjamiesysctl_hostid(SYSCTL_HANDLER_ARGS) 421180291Srwatson{ 422193066Sjamie struct prison *pr, *cpr; 423193066Sjamie u_long tmpid; 424193066Sjamie int descend, error; 425180291Srwatson 426193066Sjamie /* 427193066Sjamie * Like sysctl_hostname, except it operates on a u_long 428193066Sjamie * instead of a string, and is used only for hostid. 429193066Sjamie */ 430193066Sjamie pr = req->td->td_ucred->cr_prison; 431193066Sjamie if (!(pr->pr_allow & PR_ALLOW_SET_HOSTNAME) && req->newptr) 432193066Sjamie return (EPERM); 433193066Sjamie tmpid = pr->pr_hostid; 434193066Sjamie error = sysctl_handle_long(oidp, &tmpid, 0, req); 435193066Sjamie 436180291Srwatson if (req->newptr != NULL && error == 0) { 437193066Sjamie sx_slock(&allprison_lock); 438193066Sjamie while (!(pr->pr_flags & PR_HOST)) 439193066Sjamie pr = pr->pr_parent; 440193066Sjamie mtx_lock(&pr->pr_mtx); 441193066Sjamie pr->pr_hostid = tmpid; 442193066Sjamie FOREACH_PRISON_DESCENDANT_LOCKED(pr, cpr, descend) 443193066Sjamie if (cpr->pr_flags & PR_HOST) 444193066Sjamie descend = 0; 445193066Sjamie else 446193066Sjamie cpr->pr_hostid = tmpid; 447193066Sjamie mtx_unlock(&pr->pr_mtx); 448193066Sjamie sx_sunlock(&allprison_lock); 449180291Srwatson } 450180291Srwatson return (error); 451180291Srwatson} 452180291Srwatson 453193066SjamieSYSCTL_PROC(_kern, KERN_HOSTID, hostid, 454295941Sbdrewery CTLTYPE_ULONG | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE | CTLFLAG_CAPRD, 455193066Sjamie NULL, 0, sysctl_hostid, "LU", "Host ID"); 456180291Srwatson 457279361Sian/* 458279361Sian * The osrelease string is copied from the global (osrelease in vers.c) into 459279361Sian * prison0 by a sysinit and is inherited by child jails if not changed at jail 460279361Sian * creation, so we always return the copy from the current prison data. 461279361Sian */ 462279361Sianstatic int 463279361Siansysctl_osrelease(SYSCTL_HANDLER_ARGS) 464279361Sian{ 465279361Sian struct prison *pr; 466279361Sian 467279361Sian pr = req->td->td_ucred->cr_prison; 468279361Sian return (SYSCTL_OUT(req, pr->pr_osrelease, strlen(pr->pr_osrelease) + 1)); 469279361Sian 470279361Sian} 471279361Sian 472279361SianSYSCTL_PROC(_kern, KERN_OSRELEASE, osrelease, 473279361Sian CTLTYPE_STRING | CTLFLAG_CAPRD | CTLFLAG_RD | CTLFLAG_MPSAFE, 474279361Sian NULL, 0, sysctl_osrelease, "A", "Operating system release"); 475279361Sian 476279361Sian/* 477279361Sian * The osreldate number is copied from the global (osreldate in vers.c) into 478279361Sian * prison0 by a sysinit and is inherited by child jails if not changed at jail 479279361Sian * creation, so we always return the value from the current prison data. 480279361Sian */ 481279361Sianstatic int 482279361Siansysctl_osreldate(SYSCTL_HANDLER_ARGS) 483279361Sian{ 484279361Sian struct prison *pr; 485279361Sian 486279361Sian pr = req->td->td_ucred->cr_prison; 487279361Sian return (SYSCTL_OUT(req, &pr->pr_osreldate, sizeof(pr->pr_osreldate))); 488279361Sian 489279361Sian} 490279361Sian 491279361Sian/* 492279361Sian * NOTICE: The *userland* release date is available in 493279361Sian * /usr/include/osreldate.h 494279361Sian */ 495279361SianSYSCTL_PROC(_kern, KERN_OSRELDATE, osreldate, 496279361Sian CTLTYPE_INT | CTLFLAG_CAPRD | CTLFLAG_RD | CTLFLAG_MPSAFE, 497279361Sian NULL, 0, sysctl_osreldate, "I", "Kernel release date"); 498279361Sian 499175021SjhbSYSCTL_NODE(_kern, OID_AUTO, features, CTLFLAG_RD, 0, "Kernel Features"); 500175021Sjhb 501175417Sjhb#ifdef COMPAT_FREEBSD4 502175417SjhbFEATURE(compat_freebsd4, "Compatible with FreeBSD 4"); 503175417Sjhb#endif 504175417Sjhb 505175417Sjhb#ifdef COMPAT_FREEBSD5 506175417SjhbFEATURE(compat_freebsd5, "Compatible with FreeBSD 5"); 507175417Sjhb#endif 508175417Sjhb 509175417Sjhb#ifdef COMPAT_FREEBSD6 510175417SjhbFEATURE(compat_freebsd6, "Compatible with FreeBSD 6"); 511175417Sjhb#endif 512175417Sjhb 513175417Sjhb#ifdef COMPAT_FREEBSD7 514175417SjhbFEATURE(compat_freebsd7, "Compatible with FreeBSD 7"); 515175417Sjhb#endif 516175417Sjhb 51715103Sphk/* 51815103Sphk * This is really cheating. These actually live in the libc, something 51986189Srwatson * which I'm not quite sure is a good idea anyway, but in order for 52015103Sphk * getnext and friends to actually work, we define dummies here. 521224159Srwatson * 522224159Srwatson * XXXRW: These probably should be CTLFLAG_CAPRD. 52315103Sphk */ 52486189SrwatsonSYSCTL_STRING(_user, USER_CS_PATH, cs_path, CTLFLAG_RD, 52546381Sbillf "", 0, "PATH that finds all the standard utilities"); 52686189SrwatsonSYSCTL_INT(_user, USER_BC_BASE_MAX, bc_base_max, CTLFLAG_RD, 527273377Shselasky SYSCTL_NULL_INT_PTR, 0, "Max ibase/obase values in bc(1)"); 52886189SrwatsonSYSCTL_INT(_user, USER_BC_DIM_MAX, bc_dim_max, CTLFLAG_RD, 529273377Shselasky SYSCTL_NULL_INT_PTR, 0, "Max array size in bc(1)"); 53086189SrwatsonSYSCTL_INT(_user, USER_BC_SCALE_MAX, bc_scale_max, CTLFLAG_RD, 531273377Shselasky SYSCTL_NULL_INT_PTR, 0, "Max scale value in bc(1)"); 53286189SrwatsonSYSCTL_INT(_user, USER_BC_STRING_MAX, bc_string_max, CTLFLAG_RD, 533273377Shselasky SYSCTL_NULL_INT_PTR, 0, "Max string length in bc(1)"); 53486189SrwatsonSYSCTL_INT(_user, USER_COLL_WEIGHTS_MAX, coll_weights_max, CTLFLAG_RD, 535273377Shselasky SYSCTL_NULL_INT_PTR, 0, "Maximum number of weights assigned to an LC_COLLATE locale entry"); 536273377ShselaskySYSCTL_INT(_user, USER_EXPR_NEST_MAX, expr_nest_max, CTLFLAG_RD, 537273377Shselasky SYSCTL_NULL_INT_PTR, 0, ""); 53886189SrwatsonSYSCTL_INT(_user, USER_LINE_MAX, line_max, CTLFLAG_RD, 539273377Shselasky SYSCTL_NULL_INT_PTR, 0, "Max length (bytes) of a text-processing utility's input line"); 54086189SrwatsonSYSCTL_INT(_user, USER_RE_DUP_MAX, re_dup_max, CTLFLAG_RD, 541273377Shselasky SYSCTL_NULL_INT_PTR, 0, "Maximum number of repeats of a regexp permitted"); 54286189SrwatsonSYSCTL_INT(_user, USER_POSIX2_VERSION, posix2_version, CTLFLAG_RD, 543273377Shselasky SYSCTL_NULL_INT_PTR, 0, 54446381Sbillf "The version of POSIX 1003.2 with which the system attempts to comply"); 54586189SrwatsonSYSCTL_INT(_user, USER_POSIX2_C_BIND, posix2_c_bind, CTLFLAG_RD, 546273377Shselasky SYSCTL_NULL_INT_PTR, 0, "Whether C development supports the C bindings option"); 54786189SrwatsonSYSCTL_INT(_user, USER_POSIX2_C_DEV, posix2_c_dev, CTLFLAG_RD, 548273377Shselasky SYSCTL_NULL_INT_PTR, 0, "Whether system supports the C development utilities option"); 54986189SrwatsonSYSCTL_INT(_user, USER_POSIX2_CHAR_TERM, posix2_char_term, CTLFLAG_RD, 550273377Shselasky SYSCTL_NULL_INT_PTR, 0, ""); 55186189SrwatsonSYSCTL_INT(_user, USER_POSIX2_FORT_DEV, posix2_fort_dev, CTLFLAG_RD, 552273377Shselasky SYSCTL_NULL_INT_PTR, 0, "Whether system supports FORTRAN development utilities"); 55386189SrwatsonSYSCTL_INT(_user, USER_POSIX2_FORT_RUN, posix2_fort_run, CTLFLAG_RD, 554273377Shselasky SYSCTL_NULL_INT_PTR, 0, "Whether system supports FORTRAN runtime utilities"); 55586189SrwatsonSYSCTL_INT(_user, USER_POSIX2_LOCALEDEF, posix2_localedef, CTLFLAG_RD, 556273377Shselasky SYSCTL_NULL_INT_PTR, 0, "Whether system supports creation of locales"); 55786189SrwatsonSYSCTL_INT(_user, USER_POSIX2_SW_DEV, posix2_sw_dev, CTLFLAG_RD, 558273377Shselasky SYSCTL_NULL_INT_PTR, 0, "Whether system supports software development utilities"); 55986189SrwatsonSYSCTL_INT(_user, USER_POSIX2_UPE, posix2_upe, CTLFLAG_RD, 560273377Shselasky SYSCTL_NULL_INT_PTR, 0, "Whether system supports the user portability utilities"); 56186189SrwatsonSYSCTL_INT(_user, USER_STREAM_MAX, stream_max, CTLFLAG_RD, 562273377Shselasky SYSCTL_NULL_INT_PTR, 0, "Min Maximum number of streams a process may have open at one time"); 56386189SrwatsonSYSCTL_INT(_user, USER_TZNAME_MAX, tzname_max, CTLFLAG_RD, 564273377Shselasky SYSCTL_NULL_INT_PTR, 0, "Min Maximum number of types supported for timezone names"); 56548891Sphk 56648891Sphk#include <sys/vnode.h> 56786189SrwatsonSYSCTL_INT(_debug_sizeof, OID_AUTO, vnode, CTLFLAG_RD, 568273377Shselasky SYSCTL_NULL_INT_PTR, sizeof(struct vnode), "sizeof(struct vnode)"); 56948891Sphk 57086189SrwatsonSYSCTL_INT(_debug_sizeof, OID_AUTO, proc, CTLFLAG_RD, 571273377Shselasky SYSCTL_NULL_INT_PTR, sizeof(struct proc), "sizeof(struct proc)"); 57248927Sphk 573239301Skibstatic int 574239301Skibsysctl_kern_pid_max(SYSCTL_HANDLER_ARGS) 575239301Skib{ 576239301Skib int error, pm; 577239301Skib 578239301Skib pm = pid_max; 579239301Skib error = sysctl_handle_int(oidp, &pm, 0, req); 580239301Skib if (error || !req->newptr) 581239301Skib return (error); 582239301Skib sx_xlock(&proctree_lock); 583239301Skib sx_xlock(&allproc_lock); 584239329Skib 585239329Skib /* 586239329Skib * Only permit the values less then PID_MAX. 587239329Skib * As a safety measure, do not allow to limit the pid_max too much. 588239329Skib */ 589239329Skib if (pm < 300 || pm > PID_MAX) 590239301Skib error = EINVAL; 591239301Skib else 592239301Skib pid_max = pm; 593239301Skib sx_xunlock(&allproc_lock); 594239301Skib sx_xunlock(&proctree_lock); 595239301Skib return (error); 596239301Skib} 597267992ShselaskySYSCTL_PROC(_kern, OID_AUTO, pid_max, CTLTYPE_INT | 598267992Shselasky CTLFLAG_RWTUN | CTLFLAG_NOFETCH | CTLFLAG_MPSAFE, 599267992Shselasky 0, 0, sysctl_kern_pid_max, "I", "Maximum allowed pid"); 600239301Skib 60160041Sphk#include <sys/bio.h> 60258926Sphk#include <sys/buf.h> 60358926SphkSYSCTL_INT(_debug_sizeof, OID_AUTO, bio, CTLFLAG_RD, 604273377Shselasky SYSCTL_NULL_INT_PTR, sizeof(struct bio), "sizeof(struct bio)"); 60558926SphkSYSCTL_INT(_debug_sizeof, OID_AUTO, buf, CTLFLAG_RD, 606273377Shselasky SYSCTL_NULL_INT_PTR, sizeof(struct buf), "sizeof(struct buf)"); 60772376Sjake 60872376Sjake#include <sys/user.h> 60972376SjakeSYSCTL_INT(_debug_sizeof, OID_AUTO, kinfo_proc, CTLFLAG_RD, 610273377Shselasky SYSCTL_NULL_INT_PTR, sizeof(struct kinfo_proc), "sizeof(struct kinfo_proc)"); 611108685Sjake 612290728Sjhb/* Used by kernel debuggers. */ 613290728Sjhbconst int pcb_size = sizeof(struct pcb); 614290728SjhbSYSCTL_INT(_debug_sizeof, OID_AUTO, pcb, CTLFLAG_RD, 615290728Sjhb SYSCTL_NULL_INT_PTR, sizeof(struct pcb), "sizeof(struct pcb)"); 616290728Sjhb 617108696Sjake/* XXX compatibility, remove for 6.0 */ 618108696Sjake#include <sys/imgact.h> 619108696Sjake#include <sys/imgact_elf.h> 620108696SjakeSYSCTL_INT(_kern, OID_AUTO, fallback_elf_brand, CTLFLAG_RW, 621108696Sjake &__elfN(fallback_brand), sizeof(__elfN(fallback_brand)), 622108696Sjake "compatibility for kern.fallback_elf_brand"); 623