1.\" $NetBSD: secmodel_securelevel.9,v 1.19 2019/05/18 10:21:03 alnsn 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 May 18, 2019 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 7 , 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 x86/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 120Device 121.Dq pass-thru 122requests that may be used to perform raw disk and/or memory access are denied. 123.It 124The 125.Em iopl 126and 127.Em ioperm 128calls are denied. 129.It 130Access to unmanaged memory is denied. 131.It 132Only GPIO pins that have been set at 133.Em securelevel 1340 can be accessed. 135.El 136.It \ 2 Em Highly secure mode 137.Bl -bullet 138.It 139All effects of 140.Em securelevel 1411. 142.It 143Raw disk devices are always read-only whether mounted or not. 144.It 145New disks may not be mounted, and existing mounts may only be downgraded 146from read-write to read-only. 147.It 148The system clock may not be set backwards or close to overflow. 149.It 150Per-process coredump name may not be changed. 151.It 152Packet filtering and NAT rules may not be altered. 153.It 154CPU ucode loading is denied on platforms that support it. 155.El 156.El 157.Pp 158Highly secure mode may seem Draconian, but is intended as a last line of 159defence should the 160.Em super-user 161account be compromised. 162Its effects preclude 163circumvention of file flags by direct modification of a raw disk device, 164or erasure of a file system by means of 165.Xr newfs 8 . 166Further, it can limit the potential damage of a compromised 167.Dq firewall 168by prohibiting the modification of packet filter rules. 169Preventing 170the system clock from being set backwards aids in post-mortem analysis 171and helps ensure the integrity of logs. 172Precision timekeeping is not 173affected because the clock may still be slowed. 174.Pp 175Normally, the system runs in 176.Em securelevel 1770 while single-user and in 178.Em securelevel 1791 while multi-user. 180If a higher 181.Em securelevel 182is desired while running multi-user, 183it can be set using the 184.Sy securelevel 185keyword in the startup script 186.Pa /etc/rc.conf , 187see 188.Xr rc.conf 5 189for details. 190Lower securelevels require the kernel to be compiled with 191.Sy options INSECURE , 192causing it to always default to 193.Em securelevel 194\-1. 195.Pp 196In order for this protection to be effective, the administrator 197must ensure that no program that is run while the security level 198is 0 or lower, nor any data or configuration file used by any such 199program, can be modified while the security level is greater than 2000. 201This may be achieved through the careful use of the 202.Dq immutable 203file flag to define and protect a Trusted Computing Base (TCB) 204consisting of all such programs and data, or by ensuring that all 205such programs and data are on filesystems that are mounted read-only 206and running at security level 2 or higher. 207.Em Particular care must be taken to ensure, if relying upon 208.Em security level 1 and the use of file flags, that the integrity of the 209.Em TCB cannot be compromised through the use of modifications to the 210.Em disklabel or access to overlapping disk partitions, including the 211.Em raw partition . 212.Pp 213Do not overlook the fact that shell scripts (or anything else fed to an 214interpreter, through any mechanism) and the kernel itself are "programs 215that run while the security level is 0" and must be considered part of 216the TCB. 217.Pp 218The following 219.Xr sysctl 3 220variables are exported: 221.Bl -tag -width compact 222.It security.models.securelevel.securelevel 223The system security level. 224This level may be raised by processes with appropriate privilege. 225It may only be lowered by process 1 (init). 226.El 227.Sh FUNCTIONS 228.Nm 229exposes a 230.Xr secmodel_eval 9 231evaluation routine 232to test whether the current 233.Em securelevel 234is above a certain threshold level or not. 235.Pp 236The parameters to 237.Xr secmodel_eval 9 238are: 239.Bl -tag -compact -width xxxxx 240.It id 241the unique identifier of 242.Nm : 243.Qo Dv org.netbsd.secmodel.securelevel Qc . 244.It what 245a string, 246.Qo Dv is-securelevel-above Qc . 247.It arg 248a reference to an 249.Dv int 250representing the threshold level. 251.It ret 252a boolean, set by 253.Nm 254to 255.Dv true 256when the 257.Em securelevel 258is strictly above 259the threshold level, 260.Dv false 261otherwise. 262.El 263.Sh RETURN TYPES 264If successful, the evaluation returns 0 with the 265.Fa ret 266argument being either 267.Dv true 268or 269.Dv false . 270.Sh SEE ALSO 271.Xr kauth 9 , 272.Xr secmodel 9 , 273.Xr secmodel_bsd44 9 , 274.Xr secmodel_eval 9 275.Sh AUTHORS 276.An Elad Efrat Aq Mt elad@NetBSD.org 277.Sh BUGS 278Systems without 279.Xr sysctl 8 280behave as though they have security level \-1. 281.Pp 282The security level 2 restrictions relating to TCB integrity protection 283should be enforced at security level 1. 284Restrictions dependent upon security level but not relating to TCB 285integrity protection should be selected by 286.Xr sysctl 8 287settings available only at security level 0 or lower. 288