44#include "opt_config.h"
50#include <sys/kernel.h>
51#include <sys/limits.h>
55#include <sys/random.h>
59#include <sys/sysent.h>
60#include <sys/vmmeter.h>
61#include <sys/sysctl.h>
63#include <sys/unistd.h>
66 "Sysctl internal magic");
68 "High kernel, proc, limits &c");
74 "Network, (see socket.h)");
77SYSCTL_NODE(_debug, OID_AUTO,
sizeof, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
78 "Sizeof various things");
83SYSCTL_NODE(_machdep, OID_AUTO, mitigations, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
84 "Machine dependent platform mitigations.");
88 "p1003_1b, (see p1003_1b.h)");
91 "Compatibility code");
96 "Regression test MIB");
100 kern_ident, 0,
"Kernel identifier");
102SYSCTL_INT(_kern, KERN_OSREV, osrevision, CTLFLAG_RD|CTLFLAG_CAPRD,
103 SYSCTL_NULL_INT_PTR, BSD,
"Operating system revision");
106 version, 0,
"Kernel version");
109 compiler_version, 0,
"Version of compiler used to compile kernel");
112 CTLFLAG_CAPRD, ostype, 0,
"Operating system type");
115 &
maxproc, 0,
"Maximum number of processes");
121 &
maxusers, 0,
"Hint for kernel tuning");
123SYSCTL_INT(_kern, KERN_ARGMAX, argmax, CTLFLAG_RD|CTLFLAG_CAPRD,
124 SYSCTL_NULL_INT_PTR, ARG_MAX,
"Maximum bytes of argument to execve(2)");
126SYSCTL_INT(_kern, KERN_POSIX1, posix1version, CTLFLAG_RD|CTLFLAG_CAPRD,
127 SYSCTL_NULL_INT_PTR, _POSIX_VERSION,
"Version of POSIX attempting to comply to");
131 "Maximum number of supplemental groups a user can belong to");
133SYSCTL_INT(_kern, KERN_JOB_CONTROL, job_control, CTLFLAG_RD|CTLFLAG_CAPRD,
134 SYSCTL_NULL_INT_PTR, 1,
"Whether job control is available");
136#ifdef _POSIX_SAVED_IDS
137SYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD|CTLFLAG_CAPRD,
138 SYSCTL_NULL_INT_PTR, 1,
"Whether saved set-group/user ID is available");
140SYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD|CTLFLAG_CAPRD,
141 SYSCTL_NULL_INT_PTR, 0,
"Whether saved set-group/user ID is available");
149#ifdef COMPAT_FREEBSD12
151sysctl_maxphys(SYSCTL_HANDLER_ARGS)
157 if (
sizeof(
int) ==
sizeof(u_long) || req->oldlen >=
sizeof(u_long))
159 if (lvalue > INT_MAX)
165 CTLFLAG_NOFETCH | CTLFLAG_CAPRD | CTLFLAG_MPSAFE,
166 NULL, 0, sysctl_maxphys,
"UL",
"Maximum block I/O access size");
169 CTLFLAG_RDTUN | CTLFLAG_NOFETCH | CTLFLAG_CAPRD,
170 &
maxphys, 0,
"Maximum block I/O access size");
174 &
mp_ncpus, 0,
"Number of active CPUs");
176SYSCTL_INT(_hw, HW_BYTEORDER, byteorder, CTLFLAG_RD|CTLFLAG_CAPRD,
177 SYSCTL_NULL_INT_PTR, BYTE_ORDER,
"System byte order");
179SYSCTL_INT(_hw, HW_PAGESIZE, pagesize, CTLFLAG_RD|CTLFLAG_CAPRD,
180 SYSCTL_NULL_INT_PTR, PAGE_SIZE,
"System memory page size");
188 len = MIN(req->oldlen,
sizeof(
buf));
189 read_random(
buf, len);
190 return (SYSCTL_OUT(req,
buf, len));
194 CTLTYPE_OPAQUE | CTLFLAG_RD | CTLFLAG_MPSAFE | CTLFLAG_CAPRD, NULL, 0,
202 p = SIZE_T_MAX >> PAGE_SHIFT;
209 CTLTYPE_ULONG | CTLFLAG_RD | CTLFLAG_MPSAFE, 0, 0,
211 "Amount of physical memory (in bytes)");
218 p = SIZE_T_MAX >> PAGE_SHIFT;
225 CTLTYPE_ULONG | CTLFLAG_RD | CTLFLAG_MPSAFE, 0, 0,
227 "Amount of memory (in bytes) reported by the firmware");
234 p1 = physmem - vm_wire_count();
235 p = SIZE_T_MAX >> PAGE_SHIFT;
242 CTLTYPE_ULONG | CTLFLAG_RD | CTLFLAG_MPSAFE, 0, 0,
244 "Amount of memory (in bytes) which is not wired");
247 "Amount of physical memory (in pages)");
258 uint32_t pagesizes32[MAXPAGESIZES];
260 if (req->flags & SCTL_MASK32) {
266 for (i = 0; i < MAXPAGESIZES; i++)
269 len =
sizeof(pagesizes32);
270 if (len > req->oldlen && req->oldptr != NULL)
272 error = SYSCTL_OUT(req, pagesizes32, len);
277 if (len > req->oldlen && req->oldptr != NULL)
284 CTLTYPE_OPAQUE | CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, 0,
286 "Supported page sizes");
291 "Adapt reported machine architecture to the ABI of the binary");
297 if (p->p_sysent->sv_machine_arch != NULL)
298 return (p->p_sysent->sv_machine_arch(p));
299#ifdef COMPAT_FREEBSD32
300 if (SV_PROC_FLAG(p, SV_ILP32))
301 return (MACHINE_ARCH32);
303 return (MACHINE_ARCH);
309 const char *machine_arch;
314 machine_arch = MACHINE_ARCH;
315 return (SYSCTL_OUT(req, machine_arch, strlen(machine_arch) + 1));
317SYSCTL_PROC(_hw, HW_MACHINE_ARCH, machine_arch, CTLTYPE_STRING | CTLFLAG_RD |
319 "System architecture");
321#ifndef MACHINE_ARCHES
322#ifdef COMPAT_FREEBSD32
323#define MACHINE_ARCHES MACHINE_ARCH " " MACHINE_ARCH32
325#define MACHINE_ARCHES MACHINE_ARCH
335 struct prison *
pr, *cpr;
337 char tmpname[MAXHOSTNAMELEN];
338 int descend, error, len;
344 pr_offset = (size_t)arg1;
346 KASSERT(len <=
sizeof(tmpname),
347 (
"length %d too long for %s", len, __func__));
353 pr = req->td->td_ucred->cr_prison;
354 mtx_lock(&
pr->pr_mtx);
355 bcopy((
char *)
pr + pr_offset, tmpname, len);
356 mtx_unlock(&
pr->pr_mtx);
359 if (error != 0 || req->newptr == NULL)
367 if (!(
pr->pr_allow & PR_ALLOW_SET_HOSTNAME))
370 while (!(
pr->pr_flags & PR_HOST))
372 mtx_lock(&
pr->pr_mtx);
373 bcopy(tmpname, (
char *)
pr + pr_offset, len);
374 FOREACH_PRISON_DESCENDANT_LOCKED(
pr, cpr, descend)
375 if (cpr->pr_flags & PR_HOST)
378 bcopy(tmpname, (
char *)cpr + pr_offset, len);
379 mtx_unlock(&
pr->pr_mtx);
386 CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_CAPRD | CTLFLAG_MPSAFE,
387 (
void *)(offsetof(
struct prison, pr_hostname)), MAXHOSTNAMELEN,
390 CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_CAPRD | CTLFLAG_MPSAFE,
391 (
void *)(offsetof(
struct prison, pr_domainname)), MAXHOSTNAMELEN,
394 CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_CAPRD | CTLFLAG_MPSAFE,
395 (
void *)(offsetof(
struct prison, pr_hostuuid)), HOSTUUIDLEN,
401SYSCTL_INT(_regression, OID_AUTO, securelevel_nonmonotonic, CTLFLAG_RW,
408 struct prison *
pr, *cpr;
409 int descend, error,
level;
411 pr = req->td->td_ucred->cr_prison;
420 if (error || !req->newptr)
424 mtx_lock(&
pr->pr_mtx);
426 level < pr->pr_securelevel) {
427 mtx_unlock(&
pr->pr_mtx);
436 FOREACH_PRISON_DESCENDANT_LOCKED(
pr, cpr, descend) {
437 if (cpr->pr_securelevel <
level)
438 cpr->pr_securelevel =
level;
440 mtx_unlock(&
pr->pr_mtx);
446 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE, 0, 0,
448 "Current secure level");
450#ifdef INCLUDE_CONFIG_FILE
452extern char kernconfstring[];
454SYSCTL_STRING(_kern, OID_AUTO, conftxt, CTLFLAG_RD | CTLFLAG_MPSAFE,
455 kernconfstring, 0,
"Kernel configuration file");
461 struct prison *
pr, *cpr;
469 pr = req->td->td_ucred->cr_prison;
470 mtx_lock(&
pr->pr_mtx);
471 tmpid =
pr->pr_hostid;
472 mtx_unlock(&
pr->pr_mtx);
475 if (error != 0 || req->newptr == NULL)
479 if (!(
pr->pr_allow & PR_ALLOW_SET_HOSTNAME))
482 while (!(
pr->pr_flags & PR_HOST))
484 mtx_lock(&
pr->pr_mtx);
485 pr->pr_hostid = tmpid;
486 FOREACH_PRISON_DESCENDANT_LOCKED(
pr, cpr, descend)
487 if (cpr->pr_flags & PR_HOST)
490 cpr->pr_hostid = tmpid;
491 mtx_unlock(&
pr->pr_mtx);
498 CTLTYPE_ULONG | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE | CTLFLAG_CAPRD,
507 static uint8_t boot_id[16];
508 static bool initialized =
false;
512 if (!is_random_seeded()) {
516 arc4random_buf(boot_id,
sizeof(boot_id));
521 return (SYSCTL_OUT(req, boot_id,
sizeof(boot_id)));
524 CTLTYPE_STRUCT | CTLFLAG_RD | CTLFLAG_MPSAFE | CTLFLAG_CAPRD,
537 pr = req->td->td_ucred->cr_prison;
538 return (SYSCTL_OUT(req,
pr->pr_osrelease, strlen(
pr->pr_osrelease) + 1));
543 CTLTYPE_STRING | CTLFLAG_CAPRD | CTLFLAG_RD | CTLFLAG_MPSAFE,
556 pr = req->td->td_ucred->cr_prison;
557 return (SYSCTL_OUT(req, &
pr->pr_osreldate,
sizeof(
pr->pr_osreldate)));
566 CTLTYPE_INT | CTLFLAG_CAPRD | CTLFLAG_RD | CTLFLAG_MPSAFE,
579#define BUILD_ID_HEADER_LEN 0x10
580#define BUILD_ID_HASH_MAXLEN 0x14
604 for (
int i = 0; i < hashlen; i++) {
609 return (SYSCTL_OUT(req,
buf, strlen(
buf) + 1));
613 CTLTYPE_STRING | CTLFLAG_CAPRD | CTLFLAG_RD | CTLFLAG_MPSAFE,
616SYSCTL_NODE(_kern, OID_AUTO, features, CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
619#ifdef COMPAT_FREEBSD4
620FEATURE(compat_freebsd4,
"Compatible with FreeBSD 4");
623#ifdef COMPAT_FREEBSD5
624FEATURE(compat_freebsd5,
"Compatible with FreeBSD 5");
627#ifdef COMPAT_FREEBSD6
628FEATURE(compat_freebsd6,
"Compatible with FreeBSD 6");
631#ifdef COMPAT_FREEBSD7
632FEATURE(compat_freebsd7,
"Compatible with FreeBSD 7");
643 "", 0,
"PATH that finds all the standard utilities");
645 SYSCTL_NULL_INT_PTR, 0,
"Max ibase/obase values in bc(1)");
647 SYSCTL_NULL_INT_PTR, 0,
"Max array size in bc(1)");
648SYSCTL_INT(_user, USER_BC_SCALE_MAX, bc_scale_max, CTLFLAG_RD,
649 SYSCTL_NULL_INT_PTR, 0,
"Max scale value in bc(1)");
650SYSCTL_INT(_user, USER_BC_STRING_MAX, bc_string_max, CTLFLAG_RD,
651 SYSCTL_NULL_INT_PTR, 0,
"Max string length in bc(1)");
652SYSCTL_INT(_user, USER_COLL_WEIGHTS_MAX, coll_weights_max, CTLFLAG_RD,
653 SYSCTL_NULL_INT_PTR, 0,
"Maximum number of weights assigned to an LC_COLLATE locale entry");
654SYSCTL_INT(_user, USER_EXPR_NEST_MAX, expr_nest_max, CTLFLAG_RD,
655 SYSCTL_NULL_INT_PTR, 0,
"");
657 SYSCTL_NULL_INT_PTR, 0,
"Max length (bytes) of a text-processing utility's input line");
659 SYSCTL_NULL_INT_PTR, 0,
"Maximum number of repeats of a regexp permitted");
660SYSCTL_INT(_user, USER_POSIX2_VERSION, posix2_version, CTLFLAG_RD,
661 SYSCTL_NULL_INT_PTR, 0,
662 "The version of POSIX 1003.2 with which the system attempts to comply");
663SYSCTL_INT(_user, USER_POSIX2_C_BIND, posix2_c_bind, CTLFLAG_RD,
664 SYSCTL_NULL_INT_PTR, 0,
"Whether C development supports the C bindings option");
665SYSCTL_INT(_user, USER_POSIX2_C_DEV, posix2_c_dev, CTLFLAG_RD,
666 SYSCTL_NULL_INT_PTR, 0,
"Whether system supports the C development utilities option");
667SYSCTL_INT(_user, USER_POSIX2_CHAR_TERM, posix2_char_term, CTLFLAG_RD,
668 SYSCTL_NULL_INT_PTR, 0,
"");
669SYSCTL_INT(_user, USER_POSIX2_FORT_DEV, posix2_fort_dev, CTLFLAG_RD,
670 SYSCTL_NULL_INT_PTR, 0,
"Whether system supports FORTRAN development utilities");
671SYSCTL_INT(_user, USER_POSIX2_FORT_RUN, posix2_fort_run, CTLFLAG_RD,
672 SYSCTL_NULL_INT_PTR, 0,
"Whether system supports FORTRAN runtime utilities");
673SYSCTL_INT(_user, USER_POSIX2_LOCALEDEF, posix2_localedef, CTLFLAG_RD,
674 SYSCTL_NULL_INT_PTR, 0,
"Whether system supports creation of locales");
675SYSCTL_INT(_user, USER_POSIX2_SW_DEV, posix2_sw_dev, CTLFLAG_RD,
676 SYSCTL_NULL_INT_PTR, 0,
"Whether system supports software development utilities");
678 SYSCTL_NULL_INT_PTR, 0,
"Whether system supports the user portability utilities");
680 SYSCTL_NULL_INT_PTR, 0,
"Min Maximum number of streams a process may have open at one time");
682 SYSCTL_NULL_INT_PTR, 0,
"Min Maximum number of types supported for timezone names");
689#include <sys/vnode.h>
691 SYSCTL_NULL_INT_PTR,
sizeof(
struct vnode),
"sizeof(struct vnode)");
694 SYSCTL_NULL_INT_PTR,
sizeof(
struct proc),
"sizeof(struct proc)");
703 if (error || !req->newptr)
712 if (pm < 300 || pm > PID_MAX)
721 CTLFLAG_RWTUN | CTLFLAG_NOFETCH | CTLFLAG_MPSAFE,
727 SYSCTL_NULL_INT_PTR,
sizeof(
struct bio),
"sizeof(struct bio)");
729 SYSCTL_NULL_INT_PTR,
sizeof(
struct buf),
"sizeof(struct buf)");
733 SYSCTL_NULL_INT_PTR,
sizeof(
struct kinfo_proc),
"sizeof(struct kinfo_proc)");
738 SYSCTL_NULL_INT_PTR,
sizeof(
struct pcb),
"sizeof(struct pcb)");
741#include <sys/imgact.h>
742#include <sys/imgact_elf.h>
744 &
__elfN(fallback_brand),
sizeof(
__elfN(fallback_brand)),
745 "compatibility for kern.fallback_elf_brand");
const struct cf_level * level
static int __elfN(aslr_enabled)
FEATURE(kdtrace_hooks, "Kernel DTrace hooks which are required to load DTrace kernel modules")
#define BUILD_ID_HEADER_LEN
static int sysctl_hostid(SYSCTL_HANDLER_ARGS)
static char localbase[MAXPATHLEN]
SYSCTL_INT(_kern, KERN_OSREV, osrevision, CTLFLAG_RD|CTLFLAG_CAPRD, SYSCTL_NULL_INT_PTR, BSD, "Operating system revision")
static const char * proc_machine_arch(struct proc *p)
static int sysctl_hw_physmem(SYSCTL_HANDLER_ARGS)
char kernelname[MAXPATHLEN]
MTX_SYSINIT(bootid_lock, &bootid_lk, "bootid generator lock", MTX_DEF)
SYSCTL_ROOT_NODE(0, sysctl, CTLFLAG_RW|CTLFLAG_MPSAFE, 0, "Sysctl internal magic")
SYSCTL_NODE(_debug, OID_AUTO, sizeof, CTLFLAG_RW|CTLFLAG_MPSAFE, 0, "Sizeof various things")
#define BUILD_ID_HASH_MAXLEN
static int sysctl_kern_arnd(SYSCTL_HANDLER_ARGS)
static int sysctl_osreldate(SYSCTL_HANDLER_ARGS)
static int sysctl_bootid(SYSCTL_HANDLER_ARGS)
static int sysctl_hw_machine_arch(SYSCTL_HANDLER_ARGS)
SYSCTL_STRING(_kern, OID_AUTO, ident, CTLFLAG_RD|CTLFLAG_MPSAFE, kern_ident, 0, "Kernel identifier")
SYSCTL_PROC(_kern, KERN_ARND, arandom, CTLTYPE_OPAQUE|CTLFLAG_RD|CTLFLAG_MPSAFE|CTLFLAG_CAPRD, NULL, 0, sysctl_kern_arnd, "", "arc4rand")
static int sysctl_hostname(SYSCTL_HANDLER_ARGS)
SYSCTL_ULONG(_kern, KERN_MAXPHYS, maxphys, CTLFLAG_RDTUN|CTLFLAG_NOFETCH|CTLFLAG_CAPRD, &maxphys, 0, "Maximum block I/O access size")
int adaptive_machine_arch
static int sysctl_build_id(SYSCTL_HANDLER_ARGS)
static int sysctl_hw_pagesizes(SYSCTL_HANDLER_ARGS)
static int sysctl_kern_pid_max(SYSCTL_HANDLER_ARGS)
static int sysctl_hw_realmem(SYSCTL_HANDLER_ARGS)
static int regression_securelevel_nonmonotonic
static int sysctl_hw_usermem(SYSCTL_HANDLER_ARGS)
static int sysctl_kern_securelvl(SYSCTL_HANDLER_ARGS)
u_long pagesizes[MAXPAGESIZES]
static int sysctl_osrelease(SYSCTL_HANDLER_ARGS)
static struct mtx bootid_lk
SYSCTL_LONG(_hw, OID_AUTO, availpages, CTLFLAG_RD, &physmem, 0, "Amount of physical memory (in pages)")
static struct pollrec pr[POLL_LIST_LEN]
struct sx __exclusive_cache_line proctree_lock
struct sx __exclusive_cache_line allproc_lock
int sysctl_handle_long(SYSCTL_HANDLER_ARGS)
int sysctl_handle_int(SYSCTL_HANDLER_ARGS)
int sysctl_handle_string(SYSCTL_HANDLER_ARGS)
int snprintf(char *str, size_t size, const char *format,...)