1.\" Copyright (c) 2001 Networks Associates Technology, Inc. 2.\" All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23.\" SUCH DAMAGE. 24.\" 25.\" $Id: sec-doc.7,v 1.7 2001/12/22 00:14:12 rwatson Exp$ 26.\" $FreeBSD$ 27.\" 28.Dd October 12, 2001 29.Dt SEC-DOC 7 30.Os 31.Sh NAME 32.Nm sec-doc 33.Nd guide to adding security considerations sections to manual pages 34.Sh DESCRIPTION 35This document presents guidelines for 36adding security considerations sections to manual pages. 37It provides two typical examples. 38.Pp 39The guidelines for writing 40.Fx 41manual pages in 42.Xr groff_mdoc 7 43mandate that each manual page describing a feature of the 44.Fx 45system should contain a security considerations section 46describing what security requirements can be broken 47through the misuse of that feature. 48When writing these sections, authors should attempt to 49achieve a happy medium between two conflicting goals: 50brevity and completeness. 51On one hand, security consideration sections must not be too verbose, 52or busy readers might be dissuaded from reading them. 53On the other hand, security consideration sections must not be incomplete, 54or they will fail in their purpose of 55instructing the reader on how to avoid all insecure uses. 56This document provides guidelines for balancing brevity and completeness 57in the security consideration section for a given feature of the 58.Fx 59system. 60.Ss Where to Start 61Begin by listing 62those general security requirements that can be violated 63through the misuse of the feature. 64As described in 65the FreeBSD Security Architecture (FSA), 66there are four classes of security requirements: 67.Bl -hang -offset indent 68.It Em integrity 69(example: non-administrators should not modify system binaries), 70.It Em confidentiality 71(example: non-administrators should not view the shadow password file), 72.It Em availability 73(example: the web server should respond to client requests in a timely 74fashion), and 75.It Em correctness 76(example: the ps program should provide exactly the process table 77information listing functionality described in its documentation - no more, 78no less.) 79.El 80.Pp 81The FSA 82contains a list of integrity, confidentiality, availability, 83and correctness requirements for the base 84.Fx 85system. 86Many commands, tools, and utilities 87documented in sections 1, 6, and 8 of the manual 88are partly responsible for meeting these base system requirements. 89Consequently, borrowing entries from the list in 90the FSA 91is a good way to begin the list of requirements for these commands, 92tools, and utilities. 93.Pp 94Complex servers and subsystems may have their own integrity, 95confidentiality, availability and correctness requirements 96in addition to the system-wide ones listed in 97the FSA. 98Listing these additional requirements will require 99some thought and analysis. 100Correctness requirements will most often 101deal with configuration issues, 102especially in cases of programs that can load modules 103containing arbitrary functionality during run-time. 104.Pp 105For low-level features, such as the individual functions 106documented in sections 2, 3, and 9 of the manual, 107it is generally sufficient to proceed with 108only a single correctness requirement: 109simply that the function behaves as advertised. 110.Pp 111A good security considerations section 112should explain how the feature can be misused 113to violate each general security requirement in the list. 114Each explanation should be accompanied by instructions 115the reader should follow in order to avoid a violation. 116For the sake of brevity, assume the reader is familiar with 117all of the concepts in 118the FSA. 119When referencing potential vulnerabilities 120described in the Secure Programming Practices man page, 121.Xr sprog 7 , 122likewise cross-reference that document 123rather than replicating information. 124Whenever possible, refer to this document 125rather than reproducing the material it contains. 126.Ss Where to Stop 127Security problems are often interrelated; 128individual problems often have far-reaching implications. 129For example, the correctness of virtually any dynamically-linked program 130is dependent on the correct implementation and configuration 131of the run-time linker. 132The correctness of this program, in turn, 133depends on the correctness of its libraries, 134the compiler used to build it, 135the correctness of the preceding compiler that was used to build that compiler, 136and so on, 137as described by Thompson (see 138.Sx SEE ALSO , 139below). 140.Pp 141Due to the need for brevity, security consideration sections 142should describe only those issues directly related to the feature 143that is the subject of the manual page. 144Refer to other manual pages 145rather than duplicating the material found there. 146Refer to generalized descriptions of problems in 147the FSA 148rather than referring to specific instances of those problems 149in other manual pages. 150Ideally, each specific security-relevant issue 151should be described in exactly one manual page, 152preferably as a specific instance of a general problem 153described in 154the FSA. 155.Sh EXAMPLES 156Security considerations sections for most individual functions can follow 157this simple formula: 158.Pp 159.Bl -enum -offset indent -compact 160.It 161Provide one or two sentences describing each potential security 162problem, referencing 163the FSA 164to provide details whenever possible. 165.It 166Provide one or two sentences describing how to avoid each potential 167security problem. 168.It 169Provide a short example in code. 170.El 171.Pp 172This is an example security considerations section for the 173.Xr strcpy 3 174manual page: 175.Pp 176The 177.Fn strcpy 178function is easily misused in a manner which enables malicious users 179to arbitrarily change a running program's functionality 180through a buffer overflow attack. 181(See 182the FSA.) 183.Pp 184Avoid using 185.Fn strcpy . 186Instead, use 187.Fn strncpy 188and ensure that no more characters are copied to the destination buffer 189than it can hold. 190Do not forget to NUL-terminate the destination buffer, 191as 192.Fn strncpy 193will not terminate the destination string if it is truncated. 194.Pp 195Note that 196.Fn strncpy 197can also be problematic. 198It may be a security concern for a string to be truncated at all. 199Since the truncated string will not be as long as the original, 200it may refer to a completely different resource 201and usage of the truncated resource 202could result in very incorrect behavior. 203Example: 204.Pp 205.Bd -literal 206void 207foo(const char *arbitrary_string) 208{ 209 char onstack[8]; 210 211#if defined(BAD) 212 /* 213 * This first strcpy is bad behavior. Do not use strcpy()! 214 */ 215 (void)strcpy(onstack, arbitrary_string); /* BAD! */ 216#elif defined(BETTER) 217 /* 218 * The following two lines demonstrate better use of 219 * strncpy(). 220 */ 221 (void)strncpy(onstack, arbitrary_string, sizeof(onstack) - 1); 222 onstack[sizeof(onstack - 1)] = '\\0'; 223#elif defined(BEST) 224 /* 225 * These lines are even more robust due to testing for 226 * truncation. 227 */ 228 if (strlen(arbitrary_string) + 1 > sizeof(onstack)) 229 err(1, "onstack would be truncated"); 230 (void)strncpy(onstack, arbitrary_string, sizeof(onstack)); 231#endif 232} 233.Ed 234.Pp 235Security considerations sections for tools and commands 236are apt to be less formulaic. 237Let your list of potentially-violated security requirements 238be your guide; 239explain each one and list a solution in as concise a manner as possible. 240.Pp 241This is an example security considerations section for the 242.Xr rtld 1 243manual page: 244.Pp 245Using the LD_LIBRARY_PATH and LD_PRELOAD environment variables, 246malicious users can cause the dynamic linker 247to link shared libraries of their own devising 248into the address space of processes running non-set-user-ID/group-ID programs. 249These shared libraries can arbitrarily change the functionality 250of the program by replacing calls to standard library functions 251with calls to their own. 252Although this feature is disabled for set-user-ID and set-group-ID programs, 253it can still be used to create Trojan horses in other programs. 254(See 255the FSA.) 256.Pp 257All users should be aware that the correct operation of non 258set-user-ID/group-ID dynamically-linked programs depends on the proper 259configuration of these environment variables, 260and take care to avoid actions that might set them to values 261which would cause the run-time linker 262to link in shared libraries of unknown pedigree. 263.Sh SEE ALSO 264.Xr groff_mdoc 7 , 265.Xr security 7 , 266.Xr sprog 7 267.Rs 268.%T "The FreeBSD Security Architecture" 269.%J file:///usr/share/doc/{to be determined} 270.Re 271.Rs 272.%A "Edward Amoroso, AT&T Bell Laboratories" 273.%B "Fundamentals of Computer Security Technology" 274.%I "P T R Prentice Hall" 275.%D "1994" 276.Re 277.Rs 278.%A "Ken Thompson" 279.%T "Reflections on Trusting Trust" 280.%J "Communications of the ACM" 281.%I "Association for Computing Machinery, Inc." 282.%P "761-763" 283.%N "Vol. 27, No. 8" 284.%D "August, 1984" 285.Re 286.Sh HISTORY 287The 288.Nm 289manual page first appeared in 290.Fx 5.0 . 291.Sh AUTHORS 292.An "Tim Fraser, NAI Labs CBOSS project." Aq tfraser@tislabs.com 293.An "Brian Feldman, NAI Labs CBOSS project." Aq bfeldman@tislabs.com 294