1.\" $NetBSD: secmodel_securelevel.9,v 1.12 2012/01/17 10:47:27 cegger Exp $ 2.\" 3.\" Copyright (c) 2006 Elad Efrat <elad@NetBSD.org> 4.\" Copyright (c) 2000 Hugh Graham 5.\" All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 3. The name of the author may not be used to endorse or promote products 16.\" derived from this software without specific prior written permission. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28.\" 29.Dd January 16, 2012 30.Dt SECMODEL_SECURELEVEL 9 31.Os 32.Sh NAME 33.Nm secmodel_securelevel 34.Nd securelevel security model 35.Sh DESCRIPTION 36The securelevel mechanism is intended to allow protecting the persistence 37of code and data on the system, or a subset thereof, from modification, even 38by the 39.Em super-user 40by providing convenient means of 41.Dq locking down 42a system to a degree suited to its environment. 43.Pp 44The 45.Em super-user 46can raise the 47.Em securelevel 48using 49.Xr sysctl 8 , 50but only 51.Xr init 8 52can lower it. 53.Pp 54Four security levels are provided. 55.Bl -tag -width flag 56.It \&-1 Em Permanently insecure mode 57.Bl -bullet 58.It 59Do not raise the 60.Em securelevel 61on boot 62.El 63.It \ 0 Em Insecure mode 64.Bl -bullet 65.It 66The init process (PID 1) may not be traced or accessed by 67.Xr ptrace 2 68or procfs. 69.It 70Immutable and append-only file flags may be changed by 71.Xr chflags 1 72or by other means. 73.It 74All devices may be read or written subject to their permissions. 75.It 76All 77.Xr gpio 4 78pins can be set and device drivers can be attached to them. 79.It 80On architectures that support 81.Xr module 4 , 82kernel modules can be loaded and unloaded. 83.El 84.It \ 1 Em Secure mode 85.Bl -bullet 86.It 87All effects of 88.Em securelevel 890. 90.It 91The 92.Xr kmem 4 93memory files 94.Pa /dev/mem 95and 96.Pa /dev/kmem 97may not be written to. 98.It 99Raw disk devices of mounted file systems are read-only. 100.It 101Immutable and append-only file flags may not be removed. 102.It 103Kernel modules may not be loaded or unloaded. 104.It 105Neither the 106.Va net.inet.ip.sourceroute 107nor the 108.Va vm.user_va0_disable 109.Xr sysctl 8 110variables may be changed. 111.It 112Adding or removing 113.Xr sysctl 9 114nodes is denied. 115.It 116The RTC offset may not be changed. 117.It 118Set-id coredump settings may not be altered. 119.It 120Attaching the IP-based kernel debugger, 121.Xr ipkdb 4 , 122is not allowed. 123.It 124Device 125.Dq pass-thru 126requests that may be used to perform raw disk and/or memory access are denied. 127.It 128The 129.Em iopl 130and 131.Em ioperm 132calls are denied. 133.It 134Access to unmanaged memory is denied. 135.It 136Only GPIO pins that have been set at 137.Em securelevel 1380 can be accessed. 139.El 140.It \ 2 Em Highly secure mode 141.Bl -bullet 142.It 143All effects of 144.Em securelevel 1451. 146.It 147Raw disk devices are always read-only whether mounted or not. 148.It 149New disks may not be mounted, and existing mounts may only be downgraded 150from read-write to read-only. 151.It 152The system clock may not be set backwards or close to overflow. 153.It 154Per-process coredump name may not be changed. 155.It 156Packet filtering and NAT rules may not be altered. 157.It 158CPU ucode loading is denied on platforms that support it. 159.El 160.El 161.Pp 162Highly secure mode may seem Draconian, but is intended as a last line of 163defence should the 164.Em super-user 165account be compromised. 166Its effects preclude 167circumvention of file flags by direct modification of a raw disk device, 168or erasure of a file system by means of 169.Xr newfs 8 . 170Further, it can limit the potential damage of a compromised 171.Dq firewall 172by prohibiting the modification of packet filter rules. 173Preventing 174the system clock from being set backwards aids in post-mortem analysis 175and helps ensure the integrity of logs. 176Precision timekeeping is not 177affected because the clock may still be slowed. 178.Pp 179Normally, the system runs in 180.Em securelevel 1810 while single-user and in 182.Em securelevel 1831 while multi-user. 184If a higher 185.Em securelevel 186is desired while running multi-user, 187it can be set using the 188.Sy securelevel 189keyword in the startup script 190.Pa /etc/rc.conf , 191see 192.Xr rc.conf 5 193for details. 194Lower securelevels require the kernel to be compiled with 195.Sy options INSECURE , 196causing it to always default to 197.Em securelevel 198\-1. 199.Pp 200In order for this protection to be effective, the administrator 201must ensure that no program that is run while the security level 202is 0 or lower, nor any data or configuration file used by any such 203program, can be modified while the security level is greater than 2040. 205This may be achieved through the careful use of the 206.Dq immutable 207file flag to define and protect a Trusted Computing Base (TCB) 208consisting of all such programs and data, or by ensuring that all 209such programs and data are on filesystems that are mounted read-only 210and running at security level 2 or higher. 211.Em Particular care must be taken to ensure, if relying upon 212.Em security level 1 and the use of file flags, that the integrity of the 213.Em TCB cannot be compromised through the use of modifications to the 214.Em disklabel or access to overlapping disk partitions, including the 215.Em raw partition . 216.Pp 217Do not overlook the fact that shell scripts (or anything else fed to an 218interpreter, through any mechanism) and the kernel itself are "programs 219that run while the security level is 0" and must be considered part of 220the TCB. 221.Pp 222The following 223.Xr sysctl 3 224variables are exported: 225.Bl -tag -width compact 226.It security.models.securelevel.securelevel 227The system security level. 228This level may be raised by processes with appropriate privilege. 229It may only be lowered by process 1 (init). 230.El 231.Sh FUNCTIONS 232.Nm 233exposes a 234.Xr secmodel_eval 9 235evaluation routine 236to test whether the current 237.Em securelevel 238is above a certain threshold level or not. 239.Pp 240The parameters to 241.Xr secmodel_eval 9 242are: 243.Bl -tag -compact -width xxxxx 244.It id 245the unique identifier of 246.Nm : 247.Qo Dv org.netbsd.secmodel.securelevel Qc . 248.It what 249a string, 250.Qo Dv is-securelevel-above Qc 251.It arg 252a reference to an 253.Dv int 254representing the threshold level. 255.It ret 256a boolean, set by 257.Nm 258to 259.Dv true 260when the 261.Em securelevel 262is strictly above 263the threshold level, 264.Dv false 265otherwise. 266.El 267.Sh RETURN TYPES 268If successful, the evaluation returns 0 with the 269.Fa ret 270argument being either 271.Dv true 272or 273.Dv false . 274.Sh SEE ALSO 275.Xr kauth 9 , 276.Xr secmodel 9 , 277.Xr secmodel_bsd44 9 , 278.Xr secmodel_eval 9 279.Sh AUTHORS 280.An Elad Efrat Aq elad@NetBSD.org 281.Sh BUGS 282Systems without 283.Xr sysctl 8 284behave as though they have security level \-1. 285.Pp 286The security level 2 restrictions relating to TCB integrity protection 287should be enforced at security level 1. 288Restrictions dependent upon security level but not relating to TCB 289integrity protection should be selected by 290.Xr sysctl 8 291settings available only at security level 0 or lower. 292