xref: /freebsd/share/man/man7/sdoc.7 (revision b2c76c41be32f904179efed29c0ca04d53f3996c)
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.\"
30d667076bSTim J. Robbins.Dd September 5, 2005
312131a0f6SChris Costello.Dt SDOC 7
321fc841e3SChris Costello.Os
331fc841e3SChris Costello.Sh NAME
342131a0f6SChris Costello.Nm sdoc
351fc841e3SChris Costello.Nd guide to adding security considerations sections to manual pages
361fc841e3SChris Costello.Sh DESCRIPTION
373092f2e6SChris CostelloThis document presents guidelines for
383092f2e6SChris Costelloadding security considerations sections to manual pages.
393092f2e6SChris CostelloIt provides two typical examples.
401fc841e3SChris Costello.Pp
411fc841e3SChris CostelloThe guidelines for writing
421fc841e3SChris Costello.Fx
431fc841e3SChris Costellomanual pages in
441fc841e3SChris Costello.Xr groff_mdoc 7
451fc841e3SChris Costellomandate that each manual page describing a feature of the
461fc841e3SChris Costello.Fx
473092f2e6SChris Costellosystem should contain a security considerations section
483092f2e6SChris Costellodescribing what security requirements can be broken
493092f2e6SChris Costellothrough the misuse of that feature.
503092f2e6SChris CostelloWhen writing these sections, authors should attempt to
513092f2e6SChris Costelloachieve a happy medium between two conflicting goals:
523092f2e6SChris Costellobrevity and completeness.
533092f2e6SChris CostelloOn one hand, security consideration sections must not be too verbose,
543092f2e6SChris Costelloor busy readers might be dissuaded from reading them.
553092f2e6SChris CostelloOn the other hand, security consideration sections must not be incomplete,
563092f2e6SChris Costelloor they will fail in their purpose of
573092f2e6SChris Costelloinstructing the reader on how to avoid all insecure uses.
583092f2e6SChris CostelloThis document provides guidelines for balancing brevity and completeness
593092f2e6SChris Costelloin the security consideration section for a given feature of the
601fc841e3SChris Costello.Fx
611fc841e3SChris Costellosystem.
62ad25c55eSChris Costello.Ss Where to Start
631fc841e3SChris CostelloBegin by listing
643092f2e6SChris Costellothose general security requirements that can be violated
653092f2e6SChris Costellothrough the misuse of the feature.
66d667076bSTim J. RobbinsThere 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
813092f2e6SChris CostelloA good security considerations section
823092f2e6SChris Costelloshould explain how the feature can be misused
833092f2e6SChris Costelloto violate each general security requirement in the list.
843092f2e6SChris CostelloEach explanation should be accompanied by instructions
853092f2e6SChris Costellothe reader should follow in order to avoid a violation.
863092f2e6SChris CostelloWhen referencing potential vulnerabilities
87655f01f6SHiten Pandyadescribed in the Secure Programming Practices manual page,
881fc841e3SChris Costello.Xr sprog 7 ,
893092f2e6SChris Costellolikewise cross-reference that document
903092f2e6SChris Costellorather than replicating information.
913092f2e6SChris CostelloWhenever possible, refer to this document
923092f2e6SChris Costellorather than reproducing the material it contains.
93ad25c55eSChris Costello.Ss Where to Stop
943092f2e6SChris CostelloSecurity problems are often interrelated;
953092f2e6SChris Costelloindividual problems often have far-reaching implications.
963092f2e6SChris CostelloFor example, the correctness of virtually any dynamically-linked program
973092f2e6SChris Costellois dependent on the correct implementation and configuration
983092f2e6SChris Costelloof the run-time linker.
993092f2e6SChris CostelloThe correctness of this program, in turn,
1003092f2e6SChris Costellodepends on the correctness of its libraries,
1013092f2e6SChris Costellothe compiler used to build it,
1023092f2e6SChris Costellothe correctness of the preceding compiler that was used to build that compiler,
1033092f2e6SChris Costelloand so on,
1043092f2e6SChris Costelloas described by Thompson (see
1053092f2e6SChris Costello.Sx SEE ALSO ,
1063092f2e6SChris Costellobelow).
1071fc841e3SChris Costello.Pp
1083092f2e6SChris CostelloDue to the need for brevity, security consideration sections
1093092f2e6SChris Costelloshould describe only those issues directly related to the feature
1103092f2e6SChris Costellothat is the subject of the manual page.
1113092f2e6SChris CostelloRefer to other manual pages
1123092f2e6SChris Costellorather than duplicating the material found there.
1131fc841e3SChris Costello.Sh EXAMPLES
1141fc841e3SChris CostelloSecurity considerations sections for most individual functions can follow
1151fc841e3SChris Costellothis simple formula:
1161fc841e3SChris Costello.Pp
1171fc841e3SChris Costello.Bl -enum -offset indent -compact
1181fc841e3SChris Costello.It
1191fc841e3SChris CostelloProvide one or two sentences describing each potential security
120d667076bSTim J. Robbinsproblem.
1211fc841e3SChris Costello.It
1221fc841e3SChris CostelloProvide one or two sentences describing how to avoid each potential
1231fc841e3SChris Costellosecurity problem.
1241fc841e3SChris Costello.It
1251fc841e3SChris CostelloProvide a short example in code.
1261fc841e3SChris Costello.El
1271fc841e3SChris Costello.Pp
1281fc841e3SChris CostelloThis is an example security considerations section for the
1291fc841e3SChris Costello.Xr strcpy 3
1301fc841e3SChris Costellomanual page:
1311fc841e3SChris Costello.Pp
1321fc841e3SChris CostelloThe
1331fc841e3SChris Costello.Fn strcpy
1341fc841e3SChris Costellofunction is easily misused in a manner which enables malicious users
1353092f2e6SChris Costelloto arbitrarily change a running program's functionality
1363092f2e6SChris Costellothrough a buffer overflow attack.
1371fc841e3SChris Costello.Pp
1381fc841e3SChris CostelloAvoid using
1391fc841e3SChris Costello.Fn strcpy .
1401fc841e3SChris CostelloInstead, use
1411fc841e3SChris Costello.Fn strncpy
1421fc841e3SChris Costelloand ensure that no more characters are copied to the destination buffer
1431fc841e3SChris Costellothan it can hold.
144e4407b54SChris CostelloDo not forget to NUL-terminate the destination buffer,
1451fc841e3SChris Costelloas
1461fc841e3SChris Costello.Fn strncpy
1471fc841e3SChris Costellowill not terminate the destination string if it is truncated.
1481fc841e3SChris Costello.Pp
1491fc841e3SChris CostelloNote that
1501fc841e3SChris Costello.Fn strncpy
1513092f2e6SChris Costellocan also be problematic.
1523092f2e6SChris CostelloIt may be a security concern for a string to be truncated at all.
1533092f2e6SChris CostelloSince the truncated string will not be as long as the original,
1543092f2e6SChris Costelloit may refer to a completely different resource
1553092f2e6SChris Costelloand usage of the truncated resource
1563092f2e6SChris Costellocould result in very incorrect behavior.
1571fc841e3SChris CostelloExample:
1581fc841e3SChris Costello.Bd -literal
1591fc841e3SChris Costellovoid
1601fc841e3SChris Costellofoo(const char *arbitrary_string)
1611fc841e3SChris Costello{
1621fc841e3SChris Costello	char onstack[8];
1631fc841e3SChris Costello
1641fc841e3SChris Costello#if defined(BAD)
1651fc841e3SChris Costello	/*
166e4407b54SChris Costello	 * This first strcpy is bad behavior.  Do not use strcpy()!
1671fc841e3SChris Costello	 */
1681fc841e3SChris Costello	(void)strcpy(onstack, arbitrary_string);     /* BAD! */
1691fc841e3SChris Costello#elif defined(BETTER)
1701fc841e3SChris Costello	/*
1711fc841e3SChris Costello	 * The following two lines demonstrate better use of
1721fc841e3SChris Costello	 * strncpy().
1731fc841e3SChris Costello	 */
1741fc841e3SChris Costello	(void)strncpy(onstack, arbitrary_string, sizeof(onstack) - 1);
1751fc841e3SChris Costello	onstack[sizeof(onstack - 1)] = '\\0';
1761fc841e3SChris Costello#elif defined(BEST)
1771fc841e3SChris Costello	/*
1781fc841e3SChris Costello	 * These lines are even more robust due to testing for
1791fc841e3SChris Costello	 * truncation.
1801fc841e3SChris Costello	 */
1811fc841e3SChris Costello	if (strlen(arbitrary_string) + 1 > sizeof(onstack))
1821fc841e3SChris Costello		err(1, "onstack would be truncated");
1831fc841e3SChris Costello	(void)strncpy(onstack, arbitrary_string, sizeof(onstack));
1841fc841e3SChris Costello#endif
1851fc841e3SChris Costello}
1861fc841e3SChris Costello.Ed
1871fc841e3SChris Costello.Pp
1883092f2e6SChris CostelloSecurity considerations sections for tools and commands
1893092f2e6SChris Costelloare apt to be less formulaic.
1903092f2e6SChris CostelloLet your list of potentially-violated security requirements
1913092f2e6SChris Costellobe your guide;
1923092f2e6SChris Costelloexplain each one and list a solution in as concise a manner as possible.
1931fc841e3SChris Costello.Pp
1941fc841e3SChris CostelloThis is an example security considerations section for the
1951fc841e3SChris Costello.Xr rtld 1
1961fc841e3SChris Costellomanual page:
1971fc841e3SChris Costello.Pp
1981fc841e3SChris CostelloUsing the LD_LIBRARY_PATH and LD_PRELOAD environment variables,
1993092f2e6SChris Costellomalicious users can cause the dynamic linker
2003092f2e6SChris Costelloto link shared libraries of their own devising
2013092f2e6SChris Costellointo the address space of processes running non-set-user-ID/group-ID programs.
2023092f2e6SChris CostelloThese shared libraries can arbitrarily change the functionality
2033092f2e6SChris Costelloof the program by replacing calls to standard library functions
2043092f2e6SChris Costellowith calls to their own.
2053092f2e6SChris CostelloAlthough this feature is disabled for set-user-ID and set-group-ID programs,
2063092f2e6SChris Costelloit can still be used to create Trojan horses in other programs.
2071fc841e3SChris Costello.Pp
2081fc841e3SChris CostelloAll users should be aware that the correct operation of non
2091fc841e3SChris Costelloset-user-ID/group-ID dynamically-linked programs depends on the proper
2103092f2e6SChris Costelloconfiguration of these environment variables,
2113092f2e6SChris Costelloand take care to avoid actions that might set them to values
2123092f2e6SChris Costellowhich would cause the run-time linker
2133092f2e6SChris Costelloto link in shared libraries of unknown pedigree.
2141fc841e3SChris Costello.Sh SEE ALSO
2151fc841e3SChris Costello.Xr groff_mdoc 7 ,
2161fc841e3SChris Costello.Xr security 7 ,
2171fc841e3SChris Costello.Xr sprog 7
2181fc841e3SChris Costello.Rs
2191fc841e3SChris Costello.%A "Edward Amoroso, AT&T Bell Laboratories"
2201fc841e3SChris Costello.%B "Fundamentals of Computer Security Technology"
2211fc841e3SChris Costello.%I "P T R Prentice Hall"
2221fc841e3SChris Costello.%D "1994"
2231fc841e3SChris Costello.Re
2241fc841e3SChris Costello.Rs
2251fc841e3SChris Costello.%A "Ken Thompson"
2261fc841e3SChris Costello.%T "Reflections on Trusting Trust"
2271fc841e3SChris Costello.%J "Communications of the ACM"
2281fc841e3SChris Costello.%I "Association for Computing Machinery, Inc."
2291fc841e3SChris Costello.%P "761-763"
2301fc841e3SChris Costello.%N "Vol. 27, No. 8"
2311fc841e3SChris Costello.%D "August, 1984"
2321fc841e3SChris Costello.Re
2331fc841e3SChris Costello.Sh HISTORY
2341fc841e3SChris CostelloThe
2351fc841e3SChris Costello.Nm
2361fc841e3SChris Costellomanual page first appeared in
2371fc841e3SChris Costello.Fx 5.0 .
2381fc841e3SChris Costello.Sh AUTHORS
239*a63d6c94SBaptiste Daroussin.An Tim Fraser Aq Mt tfraser@tislabs.com ,
240*a63d6c94SBaptiste DaroussinNAI Labs CBOSS project
241*a63d6c94SBaptiste Daroussin.An Brian Feldman Aq Mt bfeldman@tislabs.com ,
242*a63d6c94SBaptiste DaroussinNAI Labs CBOSS project
243