1aa5ff764SRobert Watson.\" Copyright (c) 2001, 2002 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. 12aa5ff764SRobert Watson.\" 3. The names of the authors may not be used to endorse or promote 13aa5ff764SRobert Watson.\" products derived from this software without specific prior written 14aa5ff764SRobert Watson.\" permission. 151fc841e3SChris Costello.\" 161fc841e3SChris Costello.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 171fc841e3SChris Costello.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 181fc841e3SChris Costello.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 191fc841e3SChris Costello.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 201fc841e3SChris Costello.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 211fc841e3SChris Costello.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 221fc841e3SChris Costello.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 231fc841e3SChris Costello.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 241fc841e3SChris Costello.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 251fc841e3SChris Costello.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 261fc841e3SChris Costello.\" SUCH DAMAGE. 271fc841e3SChris Costello.\" 2843b95addSChris Costello.\" $Id: sec-doc.7,v 1.7 2001/12/22 00:14:12 rwatson Exp$ 291fc841e3SChris Costello.\" $FreeBSD$ 301fc841e3SChris Costello.\" 31d667076bSTim J. Robbins.Dd September 5, 2005 322131a0f6SChris Costello.Dt SDOC 7 331fc841e3SChris Costello.Os 341fc841e3SChris Costello.Sh NAME 352131a0f6SChris Costello.Nm sdoc 361fc841e3SChris Costello.Nd guide to adding security considerations sections to manual pages 371fc841e3SChris Costello.Sh DESCRIPTION 383092f2e6SChris CostelloThis document presents guidelines for 393092f2e6SChris Costelloadding security considerations sections to manual pages. 403092f2e6SChris CostelloIt provides two typical examples. 411fc841e3SChris Costello.Pp 421fc841e3SChris CostelloThe guidelines for writing 431fc841e3SChris Costello.Fx 441fc841e3SChris Costellomanual pages in 451fc841e3SChris Costello.Xr groff_mdoc 7 461fc841e3SChris Costellomandate that each manual page describing a feature of the 471fc841e3SChris Costello.Fx 483092f2e6SChris Costellosystem should contain a security considerations section 493092f2e6SChris Costellodescribing what security requirements can be broken 503092f2e6SChris Costellothrough the misuse of that feature. 513092f2e6SChris CostelloWhen writing these sections, authors should attempt to 523092f2e6SChris Costelloachieve a happy medium between two conflicting goals: 533092f2e6SChris Costellobrevity and completeness. 543092f2e6SChris CostelloOn one hand, security consideration sections must not be too verbose, 553092f2e6SChris Costelloor busy readers might be dissuaded from reading them. 563092f2e6SChris CostelloOn the other hand, security consideration sections must not be incomplete, 573092f2e6SChris Costelloor they will fail in their purpose of 583092f2e6SChris Costelloinstructing the reader on how to avoid all insecure uses. 593092f2e6SChris CostelloThis document provides guidelines for balancing brevity and completeness 603092f2e6SChris Costelloin the security consideration section for a given feature of the 611fc841e3SChris Costello.Fx 621fc841e3SChris Costellosystem. 63ad25c55eSChris Costello.Ss Where to Start 641fc841e3SChris CostelloBegin by listing 653092f2e6SChris Costellothose general security requirements that can be violated 663092f2e6SChris Costellothrough the misuse of the feature. 67d667076bSTim J. RobbinsThere are four classes of security requirements: 681fc841e3SChris Costello.Bl -hang -offset indent 691fc841e3SChris Costello.It Em integrity 701fc841e3SChris Costello(example: non-administrators should not modify system binaries), 711fc841e3SChris Costello.It Em confidentiality 721fc841e3SChris Costello(example: non-administrators should not view the shadow password file), 731fc841e3SChris Costello.It Em availability 741fc841e3SChris Costello(example: the web server should respond to client requests in a timely 751fc841e3SChris Costellofashion), and 761fc841e3SChris Costello.It Em correctness 771fc841e3SChris Costello(example: the ps program should provide exactly the process table 781fc841e3SChris Costelloinformation listing functionality described in its documentation - no more, 791fc841e3SChris Costellono less.) 801fc841e3SChris Costello.El 811fc841e3SChris Costello.Pp 823092f2e6SChris CostelloA good security considerations section 833092f2e6SChris Costelloshould explain how the feature can be misused 843092f2e6SChris Costelloto violate each general security requirement in the list. 853092f2e6SChris CostelloEach explanation should be accompanied by instructions 863092f2e6SChris Costellothe reader should follow in order to avoid a violation. 873092f2e6SChris CostelloWhen referencing potential vulnerabilities 88655f01f6SHiten Pandyadescribed in the Secure Programming Practices manual page, 891fc841e3SChris Costello.Xr sprog 7 , 903092f2e6SChris Costellolikewise cross-reference that document 913092f2e6SChris Costellorather than replicating information. 923092f2e6SChris CostelloWhenever possible, refer to this document 933092f2e6SChris Costellorather than reproducing the material it contains. 94ad25c55eSChris Costello.Ss Where to Stop 953092f2e6SChris CostelloSecurity problems are often interrelated; 963092f2e6SChris Costelloindividual problems often have far-reaching implications. 973092f2e6SChris CostelloFor example, the correctness of virtually any dynamically-linked program 983092f2e6SChris Costellois dependent on the correct implementation and configuration 993092f2e6SChris Costelloof the run-time linker. 1003092f2e6SChris CostelloThe correctness of this program, in turn, 1013092f2e6SChris Costellodepends on the correctness of its libraries, 1023092f2e6SChris Costellothe compiler used to build it, 1033092f2e6SChris Costellothe correctness of the preceding compiler that was used to build that compiler, 1043092f2e6SChris Costelloand so on, 1053092f2e6SChris Costelloas described by Thompson (see 1063092f2e6SChris Costello.Sx SEE ALSO , 1073092f2e6SChris Costellobelow). 1081fc841e3SChris Costello.Pp 1093092f2e6SChris CostelloDue to the need for brevity, security consideration sections 1103092f2e6SChris Costelloshould describe only those issues directly related to the feature 1113092f2e6SChris Costellothat is the subject of the manual page. 1123092f2e6SChris CostelloRefer to other manual pages 1133092f2e6SChris Costellorather than duplicating the material found there. 1141fc841e3SChris Costello.Sh EXAMPLES 1151fc841e3SChris CostelloSecurity considerations sections for most individual functions can follow 1161fc841e3SChris Costellothis simple formula: 1171fc841e3SChris Costello.Pp 1181fc841e3SChris Costello.Bl -enum -offset indent -compact 1191fc841e3SChris Costello.It 1201fc841e3SChris CostelloProvide one or two sentences describing each potential security 121d667076bSTim J. Robbinsproblem. 1221fc841e3SChris Costello.It 1231fc841e3SChris CostelloProvide one or two sentences describing how to avoid each potential 1241fc841e3SChris Costellosecurity problem. 1251fc841e3SChris Costello.It 1261fc841e3SChris CostelloProvide a short example in code. 1271fc841e3SChris Costello.El 1281fc841e3SChris Costello.Pp 1291fc841e3SChris CostelloThis is an example security considerations section for the 1301fc841e3SChris Costello.Xr strcpy 3 1311fc841e3SChris Costellomanual page: 1321fc841e3SChris Costello.Pp 1331fc841e3SChris CostelloThe 1341fc841e3SChris Costello.Fn strcpy 1351fc841e3SChris Costellofunction is easily misused in a manner which enables malicious users 1363092f2e6SChris Costelloto arbitrarily change a running program's functionality 1373092f2e6SChris Costellothrough a buffer overflow attack. 1381fc841e3SChris Costello.Pp 1391fc841e3SChris CostelloAvoid using 1401fc841e3SChris Costello.Fn strcpy . 1411fc841e3SChris CostelloInstead, use 1421fc841e3SChris Costello.Fn strncpy 1431fc841e3SChris Costelloand ensure that no more characters are copied to the destination buffer 1441fc841e3SChris Costellothan it can hold. 145e4407b54SChris CostelloDo not forget to NUL-terminate the destination buffer, 1461fc841e3SChris Costelloas 1471fc841e3SChris Costello.Fn strncpy 1481fc841e3SChris Costellowill not terminate the destination string if it is truncated. 1491fc841e3SChris Costello.Pp 1501fc841e3SChris CostelloNote that 1511fc841e3SChris Costello.Fn strncpy 1523092f2e6SChris Costellocan also be problematic. 1533092f2e6SChris CostelloIt may be a security concern for a string to be truncated at all. 1543092f2e6SChris CostelloSince the truncated string will not be as long as the original, 1553092f2e6SChris Costelloit may refer to a completely different resource 1563092f2e6SChris Costelloand usage of the truncated resource 1573092f2e6SChris Costellocould result in very incorrect behavior. 1581fc841e3SChris CostelloExample: 1591fc841e3SChris Costello.Pp 1601fc841e3SChris Costello.Bd -literal 1611fc841e3SChris Costellovoid 1621fc841e3SChris Costellofoo(const char *arbitrary_string) 1631fc841e3SChris Costello{ 1641fc841e3SChris Costello char onstack[8]; 1651fc841e3SChris Costello 1661fc841e3SChris Costello#if defined(BAD) 1671fc841e3SChris Costello /* 168e4407b54SChris Costello * This first strcpy is bad behavior. Do not use strcpy()! 1691fc841e3SChris Costello */ 1701fc841e3SChris Costello (void)strcpy(onstack, arbitrary_string); /* BAD! */ 1711fc841e3SChris Costello#elif defined(BETTER) 1721fc841e3SChris Costello /* 1731fc841e3SChris Costello * The following two lines demonstrate better use of 1741fc841e3SChris Costello * strncpy(). 1751fc841e3SChris Costello */ 1761fc841e3SChris Costello (void)strncpy(onstack, arbitrary_string, sizeof(onstack) - 1); 1771fc841e3SChris Costello onstack[sizeof(onstack - 1)] = '\\0'; 1781fc841e3SChris Costello#elif defined(BEST) 1791fc841e3SChris Costello /* 1801fc841e3SChris Costello * These lines are even more robust due to testing for 1811fc841e3SChris Costello * truncation. 1821fc841e3SChris Costello */ 1831fc841e3SChris Costello if (strlen(arbitrary_string) + 1 > sizeof(onstack)) 1841fc841e3SChris Costello err(1, "onstack would be truncated"); 1851fc841e3SChris Costello (void)strncpy(onstack, arbitrary_string, sizeof(onstack)); 1861fc841e3SChris Costello#endif 1871fc841e3SChris Costello} 1881fc841e3SChris Costello.Ed 1891fc841e3SChris Costello.Pp 1903092f2e6SChris CostelloSecurity considerations sections for tools and commands 1913092f2e6SChris Costelloare apt to be less formulaic. 1923092f2e6SChris CostelloLet your list of potentially-violated security requirements 1933092f2e6SChris Costellobe your guide; 1943092f2e6SChris Costelloexplain each one and list a solution in as concise a manner as possible. 1951fc841e3SChris Costello.Pp 1961fc841e3SChris CostelloThis is an example security considerations section for the 1971fc841e3SChris Costello.Xr rtld 1 1981fc841e3SChris Costellomanual page: 1991fc841e3SChris Costello.Pp 2001fc841e3SChris CostelloUsing the LD_LIBRARY_PATH and LD_PRELOAD environment variables, 2013092f2e6SChris Costellomalicious users can cause the dynamic linker 2023092f2e6SChris Costelloto link shared libraries of their own devising 2033092f2e6SChris Costellointo the address space of processes running non-set-user-ID/group-ID programs. 2043092f2e6SChris CostelloThese shared libraries can arbitrarily change the functionality 2053092f2e6SChris Costelloof the program by replacing calls to standard library functions 2063092f2e6SChris Costellowith calls to their own. 2073092f2e6SChris CostelloAlthough this feature is disabled for set-user-ID and set-group-ID programs, 2083092f2e6SChris Costelloit can still be used to create Trojan horses in other programs. 2091fc841e3SChris Costello.Pp 2101fc841e3SChris CostelloAll users should be aware that the correct operation of non 2111fc841e3SChris Costelloset-user-ID/group-ID dynamically-linked programs depends on the proper 2123092f2e6SChris Costelloconfiguration of these environment variables, 2133092f2e6SChris Costelloand take care to avoid actions that might set them to values 2143092f2e6SChris Costellowhich would cause the run-time linker 2153092f2e6SChris Costelloto link in shared libraries of unknown pedigree. 2161fc841e3SChris Costello.Sh SEE ALSO 2171fc841e3SChris Costello.Xr groff_mdoc 7 , 2181fc841e3SChris Costello.Xr security 7 , 2191fc841e3SChris Costello.Xr sprog 7 2201fc841e3SChris Costello.Rs 2211fc841e3SChris Costello.%A "Edward Amoroso, AT&T Bell Laboratories" 2221fc841e3SChris Costello.%B "Fundamentals of Computer Security Technology" 2231fc841e3SChris Costello.%I "P T R Prentice Hall" 2241fc841e3SChris Costello.%D "1994" 2251fc841e3SChris Costello.Re 2261fc841e3SChris Costello.Rs 2271fc841e3SChris Costello.%A "Ken Thompson" 2281fc841e3SChris Costello.%T "Reflections on Trusting Trust" 2291fc841e3SChris Costello.%J "Communications of the ACM" 2301fc841e3SChris Costello.%I "Association for Computing Machinery, Inc." 2311fc841e3SChris Costello.%P "761-763" 2321fc841e3SChris Costello.%N "Vol. 27, No. 8" 2331fc841e3SChris Costello.%D "August, 1984" 2341fc841e3SChris Costello.Re 2351fc841e3SChris Costello.Sh HISTORY 2361fc841e3SChris CostelloThe 2371fc841e3SChris Costello.Nm 2381fc841e3SChris Costellomanual page first appeared in 2391fc841e3SChris Costello.Fx 5.0 . 2401fc841e3SChris Costello.Sh AUTHORS 2411fc841e3SChris Costello.An "Tim Fraser, NAI Labs CBOSS project." Aq tfraser@tislabs.com 2421fc841e3SChris Costello.An "Brian Feldman, NAI Labs CBOSS project." Aq bfeldman@tislabs.com 243