145ec3b38SPoul-Henning Kamp /*- 245ec3b38SPoul-Henning Kamp * Copyright (c) 1982, 1986, 1989, 1993 345ec3b38SPoul-Henning Kamp * The Regents of the University of California. All rights reserved. 445ec3b38SPoul-Henning Kamp * 545ec3b38SPoul-Henning Kamp * This code is derived from software contributed to Berkeley by 645ec3b38SPoul-Henning Kamp * Mike Karels at Berkeley Software Design, Inc. 745ec3b38SPoul-Henning Kamp * 845ec3b38SPoul-Henning Kamp * Quite extensively rewritten by Poul-Henning Kamp of the FreeBSD 945ec3b38SPoul-Henning Kamp * project, to make these variables more userfriendly. 1045ec3b38SPoul-Henning Kamp * 1145ec3b38SPoul-Henning Kamp * Redistribution and use in source and binary forms, with or without 1245ec3b38SPoul-Henning Kamp * modification, are permitted provided that the following conditions 1345ec3b38SPoul-Henning Kamp * are met: 1445ec3b38SPoul-Henning Kamp * 1. Redistributions of source code must retain the above copyright 1545ec3b38SPoul-Henning Kamp * notice, this list of conditions and the following disclaimer. 1645ec3b38SPoul-Henning Kamp * 2. Redistributions in binary form must reproduce the above copyright 1745ec3b38SPoul-Henning Kamp * notice, this list of conditions and the following disclaimer in the 1845ec3b38SPoul-Henning Kamp * documentation and/or other materials provided with the distribution. 1945ec3b38SPoul-Henning Kamp * 4. Neither the name of the University nor the names of its contributors 2045ec3b38SPoul-Henning Kamp * may be used to endorse or promote products derived from this software 2145ec3b38SPoul-Henning Kamp * without specific prior written permission. 2245ec3b38SPoul-Henning Kamp * 2345ec3b38SPoul-Henning Kamp * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2445ec3b38SPoul-Henning Kamp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2545ec3b38SPoul-Henning Kamp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2645ec3b38SPoul-Henning Kamp * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2745ec3b38SPoul-Henning Kamp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2845ec3b38SPoul-Henning Kamp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2945ec3b38SPoul-Henning Kamp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3045ec3b38SPoul-Henning Kamp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3145ec3b38SPoul-Henning Kamp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3245ec3b38SPoul-Henning Kamp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3345ec3b38SPoul-Henning Kamp * SUCH DAMAGE. 3445ec3b38SPoul-Henning Kamp * 3545ec3b38SPoul-Henning Kamp * @(#)kern_sysctl.c 8.4 (Berkeley) 4/14/94 3645ec3b38SPoul-Henning Kamp */ 3745ec3b38SPoul-Henning Kamp 38677b542eSDavid E. O'Brien #include <sys/cdefs.h> 39677b542eSDavid E. O'Brien __FBSDID("$FreeBSD$"); 40677b542eSDavid E. O'Brien 412c179010SJohn Baldwin #include "opt_compat.h" 42eacb362fSRobert Watson #include "opt_posix.h" 435f9974aeSWojciech A. Koszek #include "opt_config.h" 44c175d222SRobert Watson 4545ec3b38SPoul-Henning Kamp #include <sys/param.h> 4645ec3b38SPoul-Henning Kamp #include <sys/kernel.h> 47744b947eSWojciech A. Koszek #include <sys/sbuf.h> 4845ec3b38SPoul-Henning Kamp #include <sys/systm.h> 4945ec3b38SPoul-Henning Kamp #include <sys/sysctl.h> 5045ec3b38SPoul-Henning Kamp #include <sys/proc.h> 5101137630SRobert Watson #include <sys/lock.h> 5201137630SRobert Watson #include <sys/mutex.h> 5375c13541SPoul-Henning Kamp #include <sys/jail.h> 546caa8a15SJohn Baldwin #include <sys/smp.h> 550304c731SJamie Gritton #include <sys/sx.h> 56eeea998cSMike Barcroft #include <sys/unistd.h> 57662f9a69SKATO Takenori 5845ec3b38SPoul-Henning Kamp SYSCTL_NODE(, 0, sysctl, CTLFLAG_RW, 0, 5945ec3b38SPoul-Henning Kamp "Sysctl internal magic"); 6045ec3b38SPoul-Henning Kamp SYSCTL_NODE(, CTL_KERN, kern, CTLFLAG_RW, 0, 6145ec3b38SPoul-Henning Kamp "High kernel, proc, limits &c"); 6245ec3b38SPoul-Henning Kamp SYSCTL_NODE(, CTL_VM, vm, CTLFLAG_RW, 0, 6345ec3b38SPoul-Henning Kamp "Virtual memory"); 644a8b9660SBruce Evans SYSCTL_NODE(, CTL_VFS, vfs, CTLFLAG_RW, 0, 6545ec3b38SPoul-Henning Kamp "File system"); 6645ec3b38SPoul-Henning Kamp SYSCTL_NODE(, CTL_NET, net, CTLFLAG_RW, 0, 6745ec3b38SPoul-Henning Kamp "Network, (see socket.h)"); 6845ec3b38SPoul-Henning Kamp SYSCTL_NODE(, CTL_DEBUG, debug, CTLFLAG_RW, 0, 6945ec3b38SPoul-Henning Kamp "Debugging"); 706f13bfc2SPoul-Henning Kamp SYSCTL_NODE(_debug, OID_AUTO, sizeof, CTLFLAG_RW, 0, 716f13bfc2SPoul-Henning Kamp "Sizeof various things"); 7245ec3b38SPoul-Henning Kamp SYSCTL_NODE(, CTL_HW, hw, CTLFLAG_RW, 0, 7345ec3b38SPoul-Henning Kamp "hardware"); 7445ec3b38SPoul-Henning Kamp SYSCTL_NODE(, CTL_MACHDEP, machdep, CTLFLAG_RW, 0, 7545ec3b38SPoul-Henning Kamp "machine dependent"); 7645ec3b38SPoul-Henning Kamp SYSCTL_NODE(, CTL_USER, user, CTLFLAG_RW, 0, 7745ec3b38SPoul-Henning Kamp "user-level"); 788a6472b7SPeter Dufault SYSCTL_NODE(, CTL_P1003_1B, p1003_1b, CTLFLAG_RW, 0, 798a6472b7SPeter Dufault "p1003_1b, (see p1003_1b.h)"); 80644d85f4SPeter Dufault 81c6dfea0eSMarcel Moolenaar SYSCTL_NODE(, OID_AUTO, compat, CTLFLAG_RW, 0, 82c6dfea0eSMarcel Moolenaar "Compatibility code"); 83d0615c64SAndrew R. Reiter SYSCTL_NODE(, OID_AUTO, security, CTLFLAG_RW, 0, 84d0615c64SAndrew R. Reiter "Security"); 85eacb362fSRobert Watson #ifdef REGRESSION 86eacb362fSRobert Watson SYSCTL_NODE(, OID_AUTO, regression, CTLFLAG_RW, 0, 87eacb362fSRobert Watson "Regression test MIB"); 88eacb362fSRobert Watson #endif 89c6dfea0eSMarcel Moolenaar 90f3b86a5fSEd Schouten SYSCTL_STRING(_kern, OID_AUTO, ident, CTLFLAG_RD|CTLFLAG_MPSAFE, 91c02d7621SJuli Mallett kern_ident, 0, "Kernel identifier"); 92da1186f2SJuli Mallett 93f3b86a5fSEd Schouten SYSCTL_STRING(_kern, KERN_OSRELEASE, osrelease, CTLFLAG_RD|CTLFLAG_MPSAFE, 94af1408e3SLuigi Rizzo osrelease, 0, "Operating system release"); 9545ec3b38SPoul-Henning Kamp 963d177f46SBill Fumerola SYSCTL_INT(_kern, KERN_OSREV, osrevision, CTLFLAG_RD, 973d177f46SBill Fumerola 0, BSD, "Operating system revision"); 9845ec3b38SPoul-Henning Kamp 99f3b86a5fSEd Schouten SYSCTL_STRING(_kern, KERN_VERSION, version, CTLFLAG_RD|CTLFLAG_MPSAFE, 1003d177f46SBill Fumerola version, 0, "Kernel version"); 10145ec3b38SPoul-Henning Kamp 102f3b86a5fSEd Schouten SYSCTL_STRING(_kern, KERN_OSTYPE, ostype, CTLFLAG_RD|CTLFLAG_MPSAFE, 1033d177f46SBill Fumerola ostype, 0, "Operating system type"); 10445ec3b38SPoul-Henning Kamp 105effb9ebdSEivind Eklund /* 106effb9ebdSEivind Eklund * NOTICE: The *userland* release date is available in 107effb9ebdSEivind Eklund * /usr/include/osreldate.h 108effb9ebdSEivind Eklund */ 1093d177f46SBill Fumerola SYSCTL_INT(_kern, KERN_OSRELDATE, osreldate, CTLFLAG_RD, 110effb9ebdSEivind Eklund &osreldate, 0, "Kernel release date"); 11145ec3b38SPoul-Henning Kamp 112184dcdc7SMike Silbersack SYSCTL_INT(_kern, KERN_MAXPROC, maxproc, CTLFLAG_RDTUN, 1133d177f46SBill Fumerola &maxproc, 0, "Maximum number of processes"); 11445ec3b38SPoul-Henning Kamp 1153d177f46SBill Fumerola SYSCTL_INT(_kern, KERN_MAXPROCPERUID, maxprocperuid, CTLFLAG_RW, 1163d177f46SBill Fumerola &maxprocperuid, 0, "Maximum processes allowed per userid"); 11745ec3b38SPoul-Henning Kamp 118184dcdc7SMike Silbersack SYSCTL_INT(_kern, OID_AUTO, maxusers, CTLFLAG_RDTUN, 119ee342e1bSPeter Wemm &maxusers, 0, "Hint for kernel tuning"); 120ee342e1bSPeter Wemm 1213d177f46SBill Fumerola SYSCTL_INT(_kern, KERN_ARGMAX, argmax, CTLFLAG_RD, 1223d177f46SBill Fumerola 0, ARG_MAX, "Maximum bytes of argument to execve(2)"); 12345ec3b38SPoul-Henning Kamp 1243d177f46SBill Fumerola SYSCTL_INT(_kern, KERN_POSIX1, posix1version, CTLFLAG_RD, 125eeea998cSMike Barcroft 0, _POSIX_VERSION, "Version of POSIX attempting to comply to"); 12645ec3b38SPoul-Henning Kamp 12793833c1dSBrooks Davis SYSCTL_INT(_kern, KERN_NGROUPS, ngroups, CTLFLAG_RDTUN, 128412f9500SBrooks Davis &ngroups_max, 0, 1295feedc25SBrooks Davis "Maximum number of supplemental groups a user can belong to"); 13045ec3b38SPoul-Henning Kamp 1313d177f46SBill Fumerola SYSCTL_INT(_kern, KERN_JOB_CONTROL, job_control, CTLFLAG_RD, 1323d177f46SBill Fumerola 0, 1, "Whether job control is available"); 13345ec3b38SPoul-Henning Kamp 13445ec3b38SPoul-Henning Kamp #ifdef _POSIX_SAVED_IDS 1353d177f46SBill Fumerola SYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD, 1363d177f46SBill Fumerola 0, 1, "Whether saved set-group/user ID is available"); 13745ec3b38SPoul-Henning Kamp #else 1383d177f46SBill Fumerola SYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD, 1393d177f46SBill Fumerola 0, 0, "Whether saved set-group/user ID is available"); 14045ec3b38SPoul-Henning Kamp #endif 14145ec3b38SPoul-Henning Kamp 14245ec3b38SPoul-Henning Kamp char kernelname[MAXPATHLEN] = "/kernel"; /* XXX bloat */ 14345ec3b38SPoul-Henning Kamp 1443d177f46SBill Fumerola SYSCTL_STRING(_kern, KERN_BOOTFILE, bootfile, CTLFLAG_RW, 1453d177f46SBill Fumerola kernelname, sizeof kernelname, "Name of kernel file booted"); 14645ec3b38SPoul-Henning Kamp 1473d177f46SBill Fumerola SYSCTL_INT(_hw, HW_NCPU, ncpu, CTLFLAG_RD, 1483d177f46SBill Fumerola &mp_ncpus, 0, "Number of active CPUs"); 14945ec3b38SPoul-Henning Kamp 1503d177f46SBill Fumerola SYSCTL_INT(_hw, HW_BYTEORDER, byteorder, CTLFLAG_RD, 1513d177f46SBill Fumerola 0, BYTE_ORDER, "System byte order"); 15245ec3b38SPoul-Henning Kamp 1533d177f46SBill Fumerola SYSCTL_INT(_hw, HW_PAGESIZE, pagesize, CTLFLAG_RD, 1543d177f46SBill Fumerola 0, PAGE_SIZE, "System memory page size"); 15545ec3b38SPoul-Henning Kamp 1560fca57b8SThomas Moestl static int 157ee9f4661SAlexander Kabaev sysctl_kern_arnd(SYSCTL_HANDLER_ARGS) 158ee9f4661SAlexander Kabaev { 159370f990dSAntoine Brodin char buf[256]; 160370f990dSAntoine Brodin size_t len; 161ee9f4661SAlexander Kabaev 162370f990dSAntoine Brodin len = req->oldlen; 163370f990dSAntoine Brodin if (len > sizeof(buf)) 164370f990dSAntoine Brodin len = sizeof(buf); 165370f990dSAntoine Brodin arc4rand(buf, len, 0); 166370f990dSAntoine Brodin return (SYSCTL_OUT(req, buf, len)); 167ee9f4661SAlexander Kabaev } 168ee9f4661SAlexander Kabaev 169f3b86a5fSEd Schouten SYSCTL_PROC(_kern, KERN_ARND, arandom, 170f3b86a5fSEd Schouten CTLTYPE_OPAQUE | CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, 0, 171f3b86a5fSEd Schouten sysctl_kern_arnd, "", "arc4rand"); 172ee9f4661SAlexander Kabaev 173ee9f4661SAlexander Kabaev static int 1740fca57b8SThomas Moestl sysctl_hw_physmem(SYSCTL_HANDLER_ARGS) 1750fca57b8SThomas Moestl { 1760fca57b8SThomas Moestl u_long val; 1770fca57b8SThomas Moestl 1780fca57b8SThomas Moestl val = ctob(physmem); 1790fca57b8SThomas Moestl return (sysctl_handle_long(oidp, &val, 0, req)); 1800fca57b8SThomas Moestl } 1810fca57b8SThomas Moestl 1820fca57b8SThomas Moestl SYSCTL_PROC(_hw, HW_PHYSMEM, physmem, CTLTYPE_ULONG | CTLFLAG_RD, 1830fca57b8SThomas Moestl 0, 0, sysctl_hw_physmem, "LU", ""); 1840fca57b8SThomas Moestl 1850fca57b8SThomas Moestl static int 186a0915044SWes Peters sysctl_hw_realmem(SYSCTL_HANDLER_ARGS) 187a0915044SWes Peters { 188a0915044SWes Peters u_long val; 189a0915044SWes Peters val = ctob(realmem); 190a0915044SWes Peters return (sysctl_handle_long(oidp, &val, 0, req)); 191a0915044SWes Peters } 192a0915044SWes Peters SYSCTL_PROC(_hw, HW_REALMEM, realmem, CTLTYPE_ULONG | CTLFLAG_RD, 193a0915044SWes Peters 0, 0, sysctl_hw_realmem, "LU", ""); 194a0915044SWes Peters static int 1950fca57b8SThomas Moestl sysctl_hw_usermem(SYSCTL_HANDLER_ARGS) 1960fca57b8SThomas Moestl { 1970fca57b8SThomas Moestl u_long val; 1980fca57b8SThomas Moestl 1992feb50bfSAttilio Rao val = ctob(physmem - cnt.v_wire_count); 2000fca57b8SThomas Moestl return (sysctl_handle_long(oidp, &val, 0, req)); 2010fca57b8SThomas Moestl } 2020fca57b8SThomas Moestl 2030fca57b8SThomas Moestl SYSCTL_PROC(_hw, HW_USERMEM, usermem, CTLTYPE_ULONG | CTLFLAG_RD, 2040fca57b8SThomas Moestl 0, 0, sysctl_hw_usermem, "LU", ""); 2050fca57b8SThomas Moestl 2060fca57b8SThomas Moestl SYSCTL_ULONG(_hw, OID_AUTO, availpages, CTLFLAG_RD, &physmem, 0, ""); 2070fca57b8SThomas Moestl 208fe105d45SAlan Cox u_long pagesizes[MAXPAGESIZES] = { PAGE_SIZE }; 209fe105d45SAlan Cox 210fe105d45SAlan Cox static int 211fe105d45SAlan Cox sysctl_hw_pagesizes(SYSCTL_HANDLER_ARGS) 212fe105d45SAlan Cox { 213fe105d45SAlan Cox int error; 214fe105d45SAlan Cox #ifdef SCTL_MASK32 215fe105d45SAlan Cox int i; 216fe105d45SAlan Cox uint32_t pagesizes32[MAXPAGESIZES]; 217fe105d45SAlan Cox 218fe105d45SAlan Cox if (req->flags & SCTL_MASK32) { 219fe105d45SAlan Cox /* 220fe105d45SAlan Cox * Recreate the "pagesizes" array with 32-bit elements. Truncate 221fe105d45SAlan Cox * any page size greater than UINT32_MAX to zero. 222fe105d45SAlan Cox */ 223fe105d45SAlan Cox for (i = 0; i < MAXPAGESIZES; i++) 224fe105d45SAlan Cox pagesizes32[i] = (uint32_t)pagesizes[i]; 225fe105d45SAlan Cox 226fe105d45SAlan Cox error = SYSCTL_OUT(req, pagesizes32, sizeof(pagesizes32)); 227fe105d45SAlan Cox } else 228fe105d45SAlan Cox #endif 229fe105d45SAlan Cox error = SYSCTL_OUT(req, pagesizes, sizeof(pagesizes)); 230fe105d45SAlan Cox return (error); 231fe105d45SAlan Cox } 232fe105d45SAlan Cox SYSCTL_PROC(_hw, OID_AUTO, pagesizes, CTLTYPE_ULONG | CTLFLAG_RD, 233fe105d45SAlan Cox NULL, 0, sysctl_hw_pagesizes, "LU", "Supported page sizes"); 234fe105d45SAlan Cox 235664f8517SKATO Takenori static char machine_arch[] = MACHINE_ARCH; 236664f8517SKATO Takenori SYSCTL_STRING(_hw, HW_MACHINE_ARCH, machine_arch, CTLFLAG_RD, 2373d177f46SBill Fumerola machine_arch, 0, "System architecture"); 238664f8517SKATO Takenori 23975c13541SPoul-Henning Kamp static int 24082d9ae4eSPoul-Henning Kamp sysctl_hostname(SYSCTL_HANDLER_ARGS) 24175c13541SPoul-Henning Kamp { 24276ca6f88SJamie Gritton struct prison *pr, *cpr; 24376ca6f88SJamie Gritton size_t pr_offset; 24476ca6f88SJamie Gritton char tmpname[MAXHOSTNAMELEN]; 24576ca6f88SJamie Gritton int descend, error, len; 24676ca6f88SJamie Gritton 24776ca6f88SJamie Gritton /* 24876ca6f88SJamie Gritton * This function can set: hostname domainname hostuuid. 24976ca6f88SJamie Gritton * Keep that in mind when comments say "hostname". 25076ca6f88SJamie Gritton */ 25176ca6f88SJamie Gritton pr_offset = (size_t)arg1; 25276ca6f88SJamie Gritton len = arg2; 25376ca6f88SJamie Gritton KASSERT(len <= sizeof(tmpname), 25476ca6f88SJamie Gritton ("length %d too long for %s", len, __func__)); 25575c13541SPoul-Henning Kamp 256a854ed98SJohn Baldwin pr = req->td->td_ucred->cr_prison; 2570304c731SJamie Gritton if (!(pr->pr_allow & PR_ALLOW_SET_HOSTNAME) && req->newptr) 2586c144e75SRobert Watson return (EPERM); 25901137630SRobert Watson /* 26076ca6f88SJamie Gritton * Make a local copy of hostname to get/set so we don't have to hold 26176ca6f88SJamie Gritton * the jail mutex during the sysctl copyin/copyout activities. 26201137630SRobert Watson */ 26301137630SRobert Watson mtx_lock(&pr->pr_mtx); 26476ca6f88SJamie Gritton bcopy((char *)pr + pr_offset, tmpname, len); 26501137630SRobert Watson mtx_unlock(&pr->pr_mtx); 26601137630SRobert Watson 26776ca6f88SJamie Gritton error = sysctl_handle_string(oidp, tmpname, len, req); 26801137630SRobert Watson 26901137630SRobert Watson if (req->newptr != NULL && error == 0) { 27001137630SRobert Watson /* 27176ca6f88SJamie Gritton * Copy the locally set hostname to all jails that share 27276ca6f88SJamie Gritton * this host info. 27301137630SRobert Watson */ 27476ca6f88SJamie Gritton sx_slock(&allprison_lock); 27576ca6f88SJamie Gritton while (!(pr->pr_flags & PR_HOST)) 27676ca6f88SJamie Gritton pr = pr->pr_parent; 27701137630SRobert Watson mtx_lock(&pr->pr_mtx); 27876ca6f88SJamie Gritton bcopy(tmpname, (char *)pr + pr_offset, len); 27976ca6f88SJamie Gritton FOREACH_PRISON_DESCENDANT_LOCKED(pr, cpr, descend) 28076ca6f88SJamie Gritton if (cpr->pr_flags & PR_HOST) 28176ca6f88SJamie Gritton descend = 0; 28276ca6f88SJamie Gritton else 28376ca6f88SJamie Gritton bcopy(tmpname, (char *)cpr + pr_offset, len); 28401137630SRobert Watson mtx_unlock(&pr->pr_mtx); 28576ca6f88SJamie Gritton sx_sunlock(&allprison_lock); 2864f7d1876SRobert Watson } 28775c13541SPoul-Henning Kamp return (error); 28875c13541SPoul-Henning Kamp } 28975c13541SPoul-Henning Kamp 29075c13541SPoul-Henning Kamp SYSCTL_PROC(_kern, KERN_HOSTNAME, hostname, 291f3b86a5fSEd Schouten CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE, 292c1f19219SJamie Gritton (void *)(offsetof(struct prison, pr_hostname)), MAXHOSTNAMELEN, 29376ca6f88SJamie Gritton sysctl_hostname, "A", "Hostname"); 29476ca6f88SJamie Gritton SYSCTL_PROC(_kern, KERN_NISDOMAINNAME, domainname, 29576ca6f88SJamie Gritton CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE, 296c1f19219SJamie Gritton (void *)(offsetof(struct prison, pr_domainname)), MAXHOSTNAMELEN, 29776ca6f88SJamie Gritton sysctl_hostname, "A", "Name of the current YP/NIS domain"); 29876ca6f88SJamie Gritton SYSCTL_PROC(_kern, KERN_HOSTUUID, hostuuid, 29976ca6f88SJamie Gritton CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE, 300c1f19219SJamie Gritton (void *)(offsetof(struct prison, pr_hostuuid)), HOSTUUIDLEN, 30176ca6f88SJamie Gritton sysctl_hostname, "A", "Host UUID"); 30245ec3b38SPoul-Henning Kamp 303eacb362fSRobert Watson static int regression_securelevel_nonmonotonic = 0; 304c175d222SRobert Watson 3051e4b531bSRobert Watson #ifdef REGRESSION 306c175d222SRobert Watson SYSCTL_INT(_regression, OID_AUTO, securelevel_nonmonotonic, CTLFLAG_RW, 307c175d222SRobert Watson ®ression_securelevel_nonmonotonic, 0, "securelevel may be lowered"); 308eacb362fSRobert Watson #endif 309c175d222SRobert Watson 31045ec3b38SPoul-Henning Kamp static int 31182d9ae4eSPoul-Henning Kamp sysctl_kern_securelvl(SYSCTL_HANDLER_ARGS) 31245ec3b38SPoul-Henning Kamp { 3130304c731SJamie Gritton struct prison *pr, *cpr; 3140304c731SJamie Gritton int descend, error, level; 31545ec3b38SPoul-Henning Kamp 316a854ed98SJohn Baldwin pr = req->td->td_ucred->cr_prison; 317d3c9fa04SRobert Watson 3188a528812SRobert Watson /* 3190304c731SJamie Gritton * Reading the securelevel is easy, since the current jail's level 3200304c731SJamie Gritton * is known to be at least as secure as any higher levels. Perform 3210304c731SJamie Gritton * a lockless read since the securelevel is an integer. 3228a528812SRobert Watson */ 3230304c731SJamie Gritton level = pr->pr_securelevel; 32445ec3b38SPoul-Henning Kamp error = sysctl_handle_int(oidp, &level, 0, req); 32545ec3b38SPoul-Henning Kamp if (error || !req->newptr) 32645ec3b38SPoul-Henning Kamp return (error); 3270304c731SJamie Gritton /* Permit update only if the new securelevel exceeds the old. */ 3280304c731SJamie Gritton sx_slock(&allprison_lock); 32901137630SRobert Watson mtx_lock(&pr->pr_mtx); 3301e4b531bSRobert Watson if (!regression_securelevel_nonmonotonic && 3310304c731SJamie Gritton level < pr->pr_securelevel) { 33201137630SRobert Watson mtx_unlock(&pr->pr_mtx); 3330304c731SJamie Gritton sx_sunlock(&allprison_lock); 3348a528812SRobert Watson return (EPERM); 33501137630SRobert Watson } 336d3c9fa04SRobert Watson pr->pr_securelevel = level; 3370304c731SJamie Gritton /* 3380304c731SJamie Gritton * Set all child jails to be at least this level, but do not lower 3390304c731SJamie Gritton * them (even if regression_securelevel_nonmonotonic). 3400304c731SJamie Gritton */ 3410304c731SJamie Gritton FOREACH_PRISON_DESCENDANT_LOCKED(pr, cpr, descend) { 3420304c731SJamie Gritton if (cpr->pr_securelevel < level) 3430304c731SJamie Gritton cpr->pr_securelevel = level; 3440304c731SJamie Gritton } 34501137630SRobert Watson mtx_unlock(&pr->pr_mtx); 3460304c731SJamie Gritton sx_sunlock(&allprison_lock); 34745ec3b38SPoul-Henning Kamp return (error); 34845ec3b38SPoul-Henning Kamp } 34945ec3b38SPoul-Henning Kamp 3508a528812SRobert Watson SYSCTL_PROC(_kern, KERN_SECURELVL, securelevel, 3518a528812SRobert Watson CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_PRISON, 0, 0, sysctl_kern_securelvl, 3528a528812SRobert Watson "I", "Current secure level"); 353e812e491SRobert Watson 3545f9974aeSWojciech A. Koszek #ifdef INCLUDE_CONFIG_FILE 355744b947eSWojciech A. Koszek /* Actual kernel configuration options. */ 356744b947eSWojciech A. Koszek extern char kernconfstring[]; 357744b947eSWojciech A. Koszek 358744b947eSWojciech A. Koszek static int 359744b947eSWojciech A. Koszek sysctl_kern_config(SYSCTL_HANDLER_ARGS) 360744b947eSWojciech A. Koszek { 361cfa7a8beSWarner Losh return (sysctl_handle_string(oidp, kernconfstring, 362cfa7a8beSWarner Losh strlen(kernconfstring), req)); 363cfa7a8beSWarner Losh } 364744b947eSWojciech A. Koszek 365744b947eSWojciech A. Koszek SYSCTL_PROC(_kern, OID_AUTO, conftxt, CTLTYPE_STRING|CTLFLAG_RW, 366744b947eSWojciech A. Koszek 0, 0, sysctl_kern_config, "", "Kernel configuration file"); 3673627f737SWarner Losh #endif 368744b947eSWojciech A. Koszek 3694f7d1876SRobert Watson static int 37076ca6f88SJamie Gritton sysctl_hostid(SYSCTL_HANDLER_ARGS) 3714f7d1876SRobert Watson { 37276ca6f88SJamie Gritton struct prison *pr, *cpr; 37376ca6f88SJamie Gritton u_long tmpid; 37476ca6f88SJamie Gritton int descend, error; 3754f7d1876SRobert Watson 37676ca6f88SJamie Gritton /* 37776ca6f88SJamie Gritton * Like sysctl_hostname, except it operates on a u_long 37876ca6f88SJamie Gritton * instead of a string, and is used only for hostid. 37976ca6f88SJamie Gritton */ 38076ca6f88SJamie Gritton pr = req->td->td_ucred->cr_prison; 38176ca6f88SJamie Gritton if (!(pr->pr_allow & PR_ALLOW_SET_HOSTNAME) && req->newptr) 38276ca6f88SJamie Gritton return (EPERM); 38376ca6f88SJamie Gritton tmpid = pr->pr_hostid; 38476ca6f88SJamie Gritton error = sysctl_handle_long(oidp, &tmpid, 0, req); 38576ca6f88SJamie Gritton 3864f7d1876SRobert Watson if (req->newptr != NULL && error == 0) { 38776ca6f88SJamie Gritton sx_slock(&allprison_lock); 38876ca6f88SJamie Gritton while (!(pr->pr_flags & PR_HOST)) 38976ca6f88SJamie Gritton pr = pr->pr_parent; 39076ca6f88SJamie Gritton mtx_lock(&pr->pr_mtx); 39176ca6f88SJamie Gritton pr->pr_hostid = tmpid; 39276ca6f88SJamie Gritton FOREACH_PRISON_DESCENDANT_LOCKED(pr, cpr, descend) 39376ca6f88SJamie Gritton if (cpr->pr_flags & PR_HOST) 39476ca6f88SJamie Gritton descend = 0; 39576ca6f88SJamie Gritton else 39676ca6f88SJamie Gritton cpr->pr_hostid = tmpid; 39776ca6f88SJamie Gritton mtx_unlock(&pr->pr_mtx); 39876ca6f88SJamie Gritton sx_sunlock(&allprison_lock); 3994f7d1876SRobert Watson } 4004f7d1876SRobert Watson return (error); 4014f7d1876SRobert Watson } 4024f7d1876SRobert Watson 40376ca6f88SJamie Gritton SYSCTL_PROC(_kern, KERN_HOSTID, hostid, 40476ca6f88SJamie Gritton CTLTYPE_ULONG | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE, 40576ca6f88SJamie Gritton NULL, 0, sysctl_hostid, "LU", "Host ID"); 40645ec3b38SPoul-Henning Kamp 4070deabe7eSJohn Baldwin SYSCTL_NODE(_kern, OID_AUTO, features, CTLFLAG_RD, 0, "Kernel Features"); 4080deabe7eSJohn Baldwin 4092c179010SJohn Baldwin #ifdef COMPAT_FREEBSD4 4102c179010SJohn Baldwin FEATURE(compat_freebsd4, "Compatible with FreeBSD 4"); 4112c179010SJohn Baldwin #endif 4122c179010SJohn Baldwin 4132c179010SJohn Baldwin #ifdef COMPAT_FREEBSD5 4142c179010SJohn Baldwin FEATURE(compat_freebsd5, "Compatible with FreeBSD 5"); 4152c179010SJohn Baldwin #endif 4162c179010SJohn Baldwin 4172c179010SJohn Baldwin #ifdef COMPAT_FREEBSD6 4182c179010SJohn Baldwin FEATURE(compat_freebsd6, "Compatible with FreeBSD 6"); 4192c179010SJohn Baldwin #endif 4202c179010SJohn Baldwin 4212c179010SJohn Baldwin #ifdef COMPAT_FREEBSD7 4222c179010SJohn Baldwin FEATURE(compat_freebsd7, "Compatible with FreeBSD 7"); 4232c179010SJohn Baldwin #endif 4242c179010SJohn Baldwin 42545ec3b38SPoul-Henning Kamp /* 42645ec3b38SPoul-Henning Kamp * This is really cheating. These actually live in the libc, something 42745ec3b38SPoul-Henning Kamp * which I'm not quite sure is a good idea anyway, but in order for 42845ec3b38SPoul-Henning Kamp * getnext and friends to actually work, we define dummies here. 42945ec3b38SPoul-Henning Kamp */ 4303d177f46SBill Fumerola SYSCTL_STRING(_user, USER_CS_PATH, cs_path, CTLFLAG_RD, 4313d177f46SBill Fumerola "", 0, "PATH that finds all the standard utilities"); 4323d177f46SBill Fumerola SYSCTL_INT(_user, USER_BC_BASE_MAX, bc_base_max, CTLFLAG_RD, 4333d177f46SBill Fumerola 0, 0, "Max ibase/obase values in bc(1)"); 4343d177f46SBill Fumerola SYSCTL_INT(_user, USER_BC_DIM_MAX, bc_dim_max, CTLFLAG_RD, 4353d177f46SBill Fumerola 0, 0, "Max array size in bc(1)"); 4363d177f46SBill Fumerola SYSCTL_INT(_user, USER_BC_SCALE_MAX, bc_scale_max, CTLFLAG_RD, 4373d177f46SBill Fumerola 0, 0, "Max scale value in bc(1)"); 4383d177f46SBill Fumerola SYSCTL_INT(_user, USER_BC_STRING_MAX, bc_string_max, CTLFLAG_RD, 4393d177f46SBill Fumerola 0, 0, "Max string length in bc(1)"); 4403d177f46SBill Fumerola SYSCTL_INT(_user, USER_COLL_WEIGHTS_MAX, coll_weights_max, CTLFLAG_RD, 4413d177f46SBill Fumerola 0, 0, "Maximum number of weights assigned to an LC_COLLATE locale entry"); 4427c1aacb5SBruce Evans SYSCTL_INT(_user, USER_EXPR_NEST_MAX, expr_nest_max, CTLFLAG_RD, 0, 0, ""); 4433d177f46SBill Fumerola SYSCTL_INT(_user, USER_LINE_MAX, line_max, CTLFLAG_RD, 4443d177f46SBill Fumerola 0, 0, "Max length (bytes) of a text-processing utility's input line"); 4453d177f46SBill Fumerola SYSCTL_INT(_user, USER_RE_DUP_MAX, re_dup_max, CTLFLAG_RD, 4463d177f46SBill Fumerola 0, 0, "Maximum number of repeats of a regexp permitted"); 4473d177f46SBill Fumerola SYSCTL_INT(_user, USER_POSIX2_VERSION, posix2_version, CTLFLAG_RD, 4483d177f46SBill Fumerola 0, 0, 4493d177f46SBill Fumerola "The version of POSIX 1003.2 with which the system attempts to comply"); 4503d177f46SBill Fumerola SYSCTL_INT(_user, USER_POSIX2_C_BIND, posix2_c_bind, CTLFLAG_RD, 4513d177f46SBill Fumerola 0, 0, "Whether C development supports the C bindings option"); 4523d177f46SBill Fumerola SYSCTL_INT(_user, USER_POSIX2_C_DEV, posix2_c_dev, CTLFLAG_RD, 4533d177f46SBill Fumerola 0, 0, "Whether system supports the C development utilities option"); 4543d177f46SBill Fumerola SYSCTL_INT(_user, USER_POSIX2_CHAR_TERM, posix2_char_term, CTLFLAG_RD, 4553d177f46SBill Fumerola 0, 0, ""); 4563d177f46SBill Fumerola SYSCTL_INT(_user, USER_POSIX2_FORT_DEV, posix2_fort_dev, CTLFLAG_RD, 4573d177f46SBill Fumerola 0, 0, "Whether system supports FORTRAN development utilities"); 4583d177f46SBill Fumerola SYSCTL_INT(_user, USER_POSIX2_FORT_RUN, posix2_fort_run, CTLFLAG_RD, 4593d177f46SBill Fumerola 0, 0, "Whether system supports FORTRAN runtime utilities"); 4603d177f46SBill Fumerola SYSCTL_INT(_user, USER_POSIX2_LOCALEDEF, posix2_localedef, CTLFLAG_RD, 4613d177f46SBill Fumerola 0, 0, "Whether system supports creation of locales"); 4623d177f46SBill Fumerola SYSCTL_INT(_user, USER_POSIX2_SW_DEV, posix2_sw_dev, CTLFLAG_RD, 4633d177f46SBill Fumerola 0, 0, "Whether system supports software development utilities"); 4643d177f46SBill Fumerola SYSCTL_INT(_user, USER_POSIX2_UPE, posix2_upe, CTLFLAG_RD, 4653d177f46SBill Fumerola 0, 0, "Whether system supports the user portability utilities"); 4663d177f46SBill Fumerola SYSCTL_INT(_user, USER_STREAM_MAX, stream_max, CTLFLAG_RD, 4673d177f46SBill Fumerola 0, 0, "Min Maximum number of streams a process may have open at one time"); 4683d177f46SBill Fumerola SYSCTL_INT(_user, USER_TZNAME_MAX, tzname_max, CTLFLAG_RD, 4693d177f46SBill Fumerola 0, 0, "Min Maximum number of types supported for timezone names"); 4706f13bfc2SPoul-Henning Kamp 4716f13bfc2SPoul-Henning Kamp #include <sys/vnode.h> 4726f13bfc2SPoul-Henning Kamp SYSCTL_INT(_debug_sizeof, OID_AUTO, vnode, CTLFLAG_RD, 4736f13bfc2SPoul-Henning Kamp 0, sizeof(struct vnode), "sizeof(struct vnode)"); 4746f13bfc2SPoul-Henning Kamp 4756f13bfc2SPoul-Henning Kamp SYSCTL_INT(_debug_sizeof, OID_AUTO, proc, CTLFLAG_RD, 4766f13bfc2SPoul-Henning Kamp 0, sizeof(struct proc), "sizeof(struct proc)"); 477d7bf417dSPoul-Henning Kamp 4789626b608SPoul-Henning Kamp #include <sys/bio.h> 4798c125869SPoul-Henning Kamp #include <sys/buf.h> 4808c125869SPoul-Henning Kamp SYSCTL_INT(_debug_sizeof, OID_AUTO, bio, CTLFLAG_RD, 4818c125869SPoul-Henning Kamp 0, sizeof(struct bio), "sizeof(struct bio)"); 4828c125869SPoul-Henning Kamp SYSCTL_INT(_debug_sizeof, OID_AUTO, buf, CTLFLAG_RD, 4838c125869SPoul-Henning Kamp 0, sizeof(struct buf), "sizeof(struct buf)"); 484d5a08a60SJake Burkholder 485d5a08a60SJake Burkholder #include <sys/user.h> 486d5a08a60SJake Burkholder SYSCTL_INT(_debug_sizeof, OID_AUTO, kinfo_proc, CTLFLAG_RD, 487d5a08a60SJake Burkholder 0, sizeof(struct kinfo_proc), "sizeof(struct kinfo_proc)"); 488a360a43dSJake Burkholder 489e548a1d4SJake Burkholder /* XXX compatibility, remove for 6.0 */ 490e548a1d4SJake Burkholder #include <sys/imgact.h> 491e548a1d4SJake Burkholder #include <sys/imgact_elf.h> 492e548a1d4SJake Burkholder SYSCTL_INT(_kern, OID_AUTO, fallback_elf_brand, CTLFLAG_RW, 493e548a1d4SJake Burkholder &__elfN(fallback_brand), sizeof(__elfN(fallback_brand)), 494e548a1d4SJake Burkholder "compatibility for kern.fallback_elf_brand"); 495