11fc841e3SChris Costello.\" Copyright (c) 2001 Networks Associates Technology, Inc. 21fc841e3SChris Costello.\" All rights reserved. 31fc841e3SChris Costello.\" 41fc841e3SChris Costello.\" Redistribution and use in source and binary forms, with or without 51fc841e3SChris Costello.\" modification, are permitted provided that the following conditions 61fc841e3SChris Costello.\" are met: 71fc841e3SChris Costello.\" 1. Redistributions of source code must retain the above copyright 81fc841e3SChris Costello.\" notice, this list of conditions and the following disclaimer. 91fc841e3SChris Costello.\" 2. Redistributions in binary form must reproduce the above copyright 101fc841e3SChris Costello.\" notice, this list of conditions and the following disclaimer in the 111fc841e3SChris Costello.\" documentation and/or other materials provided with the distribution. 121fc841e3SChris Costello.\" 131fc841e3SChris Costello.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 141fc841e3SChris Costello.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 151fc841e3SChris Costello.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 161fc841e3SChris Costello.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 171fc841e3SChris Costello.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 181fc841e3SChris Costello.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 191fc841e3SChris Costello.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 201fc841e3SChris Costello.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 211fc841e3SChris Costello.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 221fc841e3SChris Costello.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 231fc841e3SChris Costello.\" SUCH DAMAGE. 241fc841e3SChris Costello.\" 251fc841e3SChris Costello.\" From Id: sec-doc.7,v 1.7 2001/12/22 00:14:12 rwatson Exp 261fc841e3SChris Costello.\" $FreeBSD$ 271fc841e3SChris Costello.\" 281fc841e3SChris Costello.Dd October 12, 2001 291fc841e3SChris Costello.Dt SEC-DOC 7 301fc841e3SChris Costello.Os 311fc841e3SChris Costello.Sh NAME 321fc841e3SChris Costello.Nm sec-doc 331fc841e3SChris Costello.Nd guide to adding security considerations sections to manual pages 341fc841e3SChris Costello.Sh DESCRIPTION 353092f2e6SChris CostelloThis document presents guidelines for 363092f2e6SChris Costelloadding security considerations sections to manual pages. 373092f2e6SChris CostelloIt provides two typical examples. 381fc841e3SChris Costello.Pp 391fc841e3SChris CostelloThe guidelines for writing 401fc841e3SChris Costello.Fx 411fc841e3SChris Costellomanual pages in 421fc841e3SChris Costello.Xr groff_mdoc 7 431fc841e3SChris Costellomandate that each manual page describing a feature of the 441fc841e3SChris Costello.Fx 453092f2e6SChris Costellosystem should contain a security considerations section 463092f2e6SChris Costellodescribing what security requirements can be broken 473092f2e6SChris Costellothrough the misuse of that feature. 483092f2e6SChris CostelloWhen writing these sections, authors should attempt to 493092f2e6SChris Costelloachieve a happy medium between two conflicting goals: 503092f2e6SChris Costellobrevity and completeness. 513092f2e6SChris CostelloOn one hand, security consideration sections must not be too verbose, 523092f2e6SChris Costelloor busy readers might be dissuaded from reading them. 533092f2e6SChris CostelloOn the other hand, security consideration sections must not be incomplete, 543092f2e6SChris Costelloor they will fail in their purpose of 553092f2e6SChris Costelloinstructing the reader on how to avoid all insecure uses. 563092f2e6SChris CostelloThis document provides guidelines for balancing brevity and completeness 573092f2e6SChris Costelloin the security consideration section for a given feature of the 581fc841e3SChris Costello.Fx 591fc841e3SChris Costellosystem. 60ad25c55eSChris Costello.Ss Where to Start 611fc841e3SChris CostelloBegin by listing 623092f2e6SChris Costellothose general security requirements that can be violated 633092f2e6SChris Costellothrough the misuse of the feature. 643092f2e6SChris CostelloAs described in 651fc841e3SChris Costellothe FreeBSD Security Architecture (FSA), 661fc841e3SChris Costellothere are four classes of security requirements: 671fc841e3SChris Costello.Bl -hang -offset indent 681fc841e3SChris Costello.It Em integrity 691fc841e3SChris Costello(example: non-administrators should not modify system binaries), 701fc841e3SChris Costello.It Em confidentiality 711fc841e3SChris Costello(example: non-administrators should not view the shadow password file), 721fc841e3SChris Costello.It Em availability 731fc841e3SChris Costello(example: the web server should respond to client requests in a timely 741fc841e3SChris Costellofashion), and 751fc841e3SChris Costello.It Em correctness 761fc841e3SChris Costello(example: the ps program should provide exactly the process table 771fc841e3SChris Costelloinformation listing functionality described in its documentation - no more, 781fc841e3SChris Costellono less.) 791fc841e3SChris Costello.El 801fc841e3SChris Costello.Pp 811fc841e3SChris CostelloThe FSA 823092f2e6SChris Costellocontains a list of integrity, confidentiality, availability, 833092f2e6SChris Costelloand correctness requirements for the base 841fc841e3SChris Costello.Fx 853092f2e6SChris Costellosystem. 863092f2e6SChris CostelloMany commands, tools, and utilities 873092f2e6SChris Costellodocumented in sections 1, 6, and 8 of the manual 883092f2e6SChris Costelloare partly responsible for meeting these base system requirements. 893092f2e6SChris CostelloConsequently, borrowing entries from the list in 901fc841e3SChris Costellothe FSA 911fc841e3SChris Costellois a good way to begin the list of requirements for these commands, 921fc841e3SChris Costellotools, and utilities. 931fc841e3SChris Costello.Pp 941fc841e3SChris CostelloComplex servers and subsystems may have their own integrity, 953092f2e6SChris Costelloconfidentiality, availability and correctness requirements 963092f2e6SChris Costelloin addition to the system-wide ones listed in 971fc841e3SChris Costellothe FSA. 983092f2e6SChris CostelloListing these additional requirements will require 993092f2e6SChris Costellosome thought and analysis. 1003092f2e6SChris CostelloCorrectness requirements will most often 1013092f2e6SChris Costellodeal with configuration issues, 1023092f2e6SChris Costelloespecially in cases of programs that can load modules 1033092f2e6SChris Costellocontaining arbitrary functionality during run-time. 1041fc841e3SChris Costello.Pp 1053092f2e6SChris CostelloFor low-level features, such as the individual functions 1063092f2e6SChris Costellodocumented in sections 2, 3, and 9 of the manual, 1073092f2e6SChris Costelloit is generally sufficient to proceed with 1083092f2e6SChris Costelloonly a single correctness requirement: 1093092f2e6SChris Costellosimply that the function behaves as advertised. 1101fc841e3SChris Costello.Pp 1113092f2e6SChris CostelloA good security considerations section 1123092f2e6SChris Costelloshould explain how the feature can be misused 1133092f2e6SChris Costelloto violate each general security requirement in the list. 1143092f2e6SChris CostelloEach explanation should be accompanied by instructions 1153092f2e6SChris Costellothe reader should follow in order to avoid a violation. 1163092f2e6SChris CostelloFor the sake of brevity, assume the reader is familiar with 1173092f2e6SChris Costelloall of the concepts in 1181fc841e3SChris Costellothe FSA. 1193092f2e6SChris CostelloWhen referencing potential vulnerabilities 1203092f2e6SChris Costellodescribed in the Secure Programming Practices man page, 1211fc841e3SChris Costello.Xr sprog 7 , 1223092f2e6SChris Costellolikewise cross-reference that document 1233092f2e6SChris Costellorather than replicating information. 1243092f2e6SChris CostelloWhenever possible, refer to this document 1253092f2e6SChris Costellorather than reproducing the material it contains. 126ad25c55eSChris Costello.Ss Where to Stop 1273092f2e6SChris CostelloSecurity problems are often interrelated; 1283092f2e6SChris Costelloindividual problems often have far-reaching implications. 1293092f2e6SChris CostelloFor example, the correctness of virtually any dynamically-linked program 1303092f2e6SChris Costellois dependent on the correct implementation and configuration 1313092f2e6SChris Costelloof the run-time linker. 1323092f2e6SChris CostelloThe correctness of this program, in turn, 1333092f2e6SChris Costellodepends on the correctness of its libraries, 1343092f2e6SChris Costellothe compiler used to build it, 1353092f2e6SChris Costellothe correctness of the preceding compiler that was used to build that compiler, 1363092f2e6SChris Costelloand so on, 1373092f2e6SChris Costelloas described by Thompson (see 1383092f2e6SChris Costello.Sx SEE ALSO , 1393092f2e6SChris Costellobelow). 1401fc841e3SChris Costello.Pp 1413092f2e6SChris CostelloDue to the need for brevity, security consideration sections 1423092f2e6SChris Costelloshould describe only those issues directly related to the feature 1433092f2e6SChris Costellothat is the subject of the manual page. 1443092f2e6SChris CostelloRefer to other manual pages 1453092f2e6SChris Costellorather than duplicating the material found there. 1463092f2e6SChris CostelloRefer to generalized descriptions of problems in 1471fc841e3SChris Costellothe FSA 1483092f2e6SChris Costellorather than referring to specific instances of those problems 1493092f2e6SChris Costelloin other manual pages. 1503092f2e6SChris CostelloIdeally, each specific security-relevant issue 1513092f2e6SChris Costelloshould be described in exactly one manual page, 1523092f2e6SChris Costellopreferably as a specific instance of a general problem 1533092f2e6SChris Costellodescribed in 1541fc841e3SChris Costellothe FSA. 1551fc841e3SChris Costello.Sh EXAMPLES 1561fc841e3SChris CostelloSecurity considerations sections for most individual functions can follow 1571fc841e3SChris Costellothis simple formula: 1581fc841e3SChris Costello.Pp 1591fc841e3SChris Costello.Bl -enum -offset indent -compact 1601fc841e3SChris Costello.It 1611fc841e3SChris CostelloProvide one or two sentences describing each potential security 1621fc841e3SChris Costelloproblem, referencing 1631fc841e3SChris Costellothe FSA 1641fc841e3SChris Costelloto provide details whenever possible. 1651fc841e3SChris Costello.It 1661fc841e3SChris CostelloProvide one or two sentences describing how to avoid each potential 1671fc841e3SChris Costellosecurity problem. 1681fc841e3SChris Costello.It 1691fc841e3SChris CostelloProvide a short example in code. 1701fc841e3SChris Costello.El 1711fc841e3SChris Costello.Pp 1721fc841e3SChris CostelloThis is an example security considerations section for the 1731fc841e3SChris Costello.Xr strcpy 3 1741fc841e3SChris Costellomanual page: 1751fc841e3SChris Costello.Pp 1761fc841e3SChris CostelloThe 1771fc841e3SChris Costello.Fn strcpy 1781fc841e3SChris Costellofunction is easily misused in a manner which enables malicious users 1793092f2e6SChris Costelloto arbitrarily change a running program's functionality 1803092f2e6SChris Costellothrough a buffer overflow attack. 1813092f2e6SChris Costello(See 1821fc841e3SChris Costellothe FSA.) 1831fc841e3SChris Costello.Pp 1841fc841e3SChris CostelloAvoid using 1851fc841e3SChris Costello.Fn strcpy . 1861fc841e3SChris CostelloInstead, use 1871fc841e3SChris Costello.Fn strncpy 1881fc841e3SChris Costelloand ensure that no more characters are copied to the destination buffer 1891fc841e3SChris Costellothan it can hold. 190e4407b54SChris CostelloDo not forget to NUL-terminate the destination buffer, 1911fc841e3SChris Costelloas 1921fc841e3SChris Costello.Fn strncpy 1931fc841e3SChris Costellowill not terminate the destination string if it is truncated. 1941fc841e3SChris Costello.Pp 1951fc841e3SChris CostelloNote that 1961fc841e3SChris Costello.Fn strncpy 1973092f2e6SChris Costellocan also be problematic. 1983092f2e6SChris CostelloIt may be a security concern for a string to be truncated at all. 1993092f2e6SChris CostelloSince the truncated string will not be as long as the original, 2003092f2e6SChris Costelloit may refer to a completely different resource 2013092f2e6SChris Costelloand usage of the truncated resource 2023092f2e6SChris Costellocould result in very incorrect behavior. 2031fc841e3SChris CostelloExample: 2041fc841e3SChris Costello.Pp 2051fc841e3SChris Costello.Bd -literal 2061fc841e3SChris Costellovoid 2071fc841e3SChris Costellofoo(const char *arbitrary_string) 2081fc841e3SChris Costello{ 2091fc841e3SChris Costello char onstack[8]; 2101fc841e3SChris Costello 2111fc841e3SChris Costello#if defined(BAD) 2121fc841e3SChris Costello /* 213e4407b54SChris Costello * This first strcpy is bad behavior. Do not use strcpy()! 2141fc841e3SChris Costello */ 2151fc841e3SChris Costello (void)strcpy(onstack, arbitrary_string); /* BAD! */ 2161fc841e3SChris Costello#elif defined(BETTER) 2171fc841e3SChris Costello /* 2181fc841e3SChris Costello * The following two lines demonstrate better use of 2191fc841e3SChris Costello * strncpy(). 2201fc841e3SChris Costello */ 2211fc841e3SChris Costello (void)strncpy(onstack, arbitrary_string, sizeof(onstack) - 1); 2221fc841e3SChris Costello onstack[sizeof(onstack - 1)] = '\\0'; 2231fc841e3SChris Costello#elif defined(BEST) 2241fc841e3SChris Costello /* 2251fc841e3SChris Costello * These lines are even more robust due to testing for 2261fc841e3SChris Costello * truncation. 2271fc841e3SChris Costello */ 2281fc841e3SChris Costello if (strlen(arbitrary_string) + 1 > sizeof(onstack)) 2291fc841e3SChris Costello err(1, "onstack would be truncated"); 2301fc841e3SChris Costello (void)strncpy(onstack, arbitrary_string, sizeof(onstack)); 2311fc841e3SChris Costello#endif 2321fc841e3SChris Costello} 2331fc841e3SChris Costello.Ed 2341fc841e3SChris Costello.Pp 2353092f2e6SChris CostelloSecurity considerations sections for tools and commands 2363092f2e6SChris Costelloare apt to be less formulaic. 2373092f2e6SChris CostelloLet your list of potentially-violated security requirements 2383092f2e6SChris Costellobe your guide; 2393092f2e6SChris Costelloexplain each one and list a solution in as concise a manner as possible. 2401fc841e3SChris Costello.Pp 2411fc841e3SChris CostelloThis is an example security considerations section for the 2421fc841e3SChris Costello.Xr rtld 1 2431fc841e3SChris Costellomanual page: 2441fc841e3SChris Costello.Pp 2451fc841e3SChris CostelloUsing the LD_LIBRARY_PATH and LD_PRELOAD environment variables, 2463092f2e6SChris Costellomalicious users can cause the dynamic linker 2473092f2e6SChris Costelloto link shared libraries of their own devising 2483092f2e6SChris Costellointo the address space of processes running non-set-user-ID/group-ID programs. 2493092f2e6SChris CostelloThese shared libraries can arbitrarily change the functionality 2503092f2e6SChris Costelloof the program by replacing calls to standard library functions 2513092f2e6SChris Costellowith calls to their own. 2523092f2e6SChris CostelloAlthough this feature is disabled for set-user-ID and set-group-ID programs, 2533092f2e6SChris Costelloit can still be used to create Trojan horses in other programs. 2543092f2e6SChris Costello(See 2551fc841e3SChris Costellothe FSA.) 2561fc841e3SChris Costello.Pp 2571fc841e3SChris CostelloAll users should be aware that the correct operation of non 2581fc841e3SChris Costelloset-user-ID/group-ID dynamically-linked programs depends on the proper 2593092f2e6SChris Costelloconfiguration of these environment variables, 2603092f2e6SChris Costelloand take care to avoid actions that might set them to values 2613092f2e6SChris Costellowhich would cause the run-time linker 2623092f2e6SChris Costelloto link in shared libraries of unknown pedigree. 2631fc841e3SChris Costello.Sh SEE ALSO 2641fc841e3SChris Costello.Xr groff_mdoc 7 , 2651fc841e3SChris Costello.Xr security 7 , 2661fc841e3SChris Costello.Xr sprog 7 2671fc841e3SChris Costello.Rs 2681fc841e3SChris Costello.%T "The FreeBSD Security Architecture" 2691fc841e3SChris Costello.%J file:///usr/share/doc/{to be determined} 2701fc841e3SChris Costello.Re 2711fc841e3SChris Costello.Rs 2721fc841e3SChris Costello.%A "Edward Amoroso, AT&T Bell Laboratories" 2731fc841e3SChris Costello.%B "Fundamentals of Computer Security Technology" 2741fc841e3SChris Costello.%I "P T R Prentice Hall" 2751fc841e3SChris Costello.%D "1994" 2761fc841e3SChris Costello.Re 2771fc841e3SChris Costello.Rs 2781fc841e3SChris Costello.%A "Ken Thompson" 2791fc841e3SChris Costello.%T "Reflections on Trusting Trust" 2801fc841e3SChris Costello.%J "Communications of the ACM" 2811fc841e3SChris Costello.%I "Association for Computing Machinery, Inc." 2821fc841e3SChris Costello.%P "761-763" 2831fc841e3SChris Costello.%N "Vol. 27, No. 8" 2841fc841e3SChris Costello.%D "August, 1984" 2851fc841e3SChris Costello.Re 2861fc841e3SChris Costello.Sh HISTORY 2871fc841e3SChris CostelloThe 2881fc841e3SChris Costello.Nm 2891fc841e3SChris Costellomanual page first appeared in 2901fc841e3SChris Costello.Fx 5.0 . 2911fc841e3SChris Costello.Sh AUTHORS 2921fc841e3SChris Costello.An "Tim Fraser, NAI Labs CBOSS project." Aq tfraser@tislabs.com 2931fc841e3SChris Costello.An "Brian Feldman, NAI Labs CBOSS project." Aq bfeldman@tislabs.com 294