xref: /freebsd/share/man/man7/sdoc.7 (revision 655f01f6df97f016604c9f9c57636d10ea75db86)
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.\"
311fc841e3SChris Costello.Dd October 12, 2001
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.
673092f2e6SChris CostelloAs described in
681fc841e3SChris Costellothe FreeBSD Security Architecture (FSA),
691fc841e3SChris Costellothere are four classes of security requirements:
701fc841e3SChris Costello.Bl -hang -offset indent
711fc841e3SChris Costello.It Em integrity
721fc841e3SChris Costello(example: non-administrators should not modify system binaries),
731fc841e3SChris Costello.It Em confidentiality
741fc841e3SChris Costello(example: non-administrators should not view the shadow password file),
751fc841e3SChris Costello.It Em availability
761fc841e3SChris Costello(example: the web server should respond to client requests in a timely
771fc841e3SChris Costellofashion), and
781fc841e3SChris Costello.It Em correctness
791fc841e3SChris Costello(example: the ps program should provide exactly the process table
801fc841e3SChris Costelloinformation listing functionality described in its documentation - no more,
811fc841e3SChris Costellono less.)
821fc841e3SChris Costello.El
831fc841e3SChris Costello.Pp
841fc841e3SChris CostelloThe FSA
853092f2e6SChris Costellocontains a list of integrity, confidentiality, availability,
863092f2e6SChris Costelloand correctness requirements for the base
871fc841e3SChris Costello.Fx
883092f2e6SChris Costellosystem.
893092f2e6SChris CostelloMany commands, tools, and utilities
903092f2e6SChris Costellodocumented in sections 1, 6, and 8 of the manual
913092f2e6SChris Costelloare partly responsible for meeting these base system requirements.
923092f2e6SChris CostelloConsequently, borrowing entries from the list in
931fc841e3SChris Costellothe FSA
941fc841e3SChris Costellois a good way to begin the list of requirements for these commands,
951fc841e3SChris Costellotools, and utilities.
961fc841e3SChris Costello.Pp
971fc841e3SChris CostelloComplex servers and subsystems may have their own integrity,
983092f2e6SChris Costelloconfidentiality, availability and correctness requirements
993092f2e6SChris Costelloin addition to the system-wide ones listed in
1001fc841e3SChris Costellothe FSA.
1013092f2e6SChris CostelloListing these additional requirements will require
1023092f2e6SChris Costellosome thought and analysis.
1033092f2e6SChris CostelloCorrectness requirements will most often
1043092f2e6SChris Costellodeal with configuration issues,
1053092f2e6SChris Costelloespecially in cases of programs that can load modules
1063092f2e6SChris Costellocontaining arbitrary functionality during run-time.
1071fc841e3SChris Costello.Pp
1083092f2e6SChris CostelloFor low-level features, such as the individual functions
1093092f2e6SChris Costellodocumented in sections 2, 3, and 9 of the manual,
1103092f2e6SChris Costelloit is generally sufficient to proceed with
1113092f2e6SChris Costelloonly a single correctness requirement:
1123092f2e6SChris Costellosimply that the function behaves as advertised.
1131fc841e3SChris Costello.Pp
1143092f2e6SChris CostelloA good security considerations section
1153092f2e6SChris Costelloshould explain how the feature can be misused
1163092f2e6SChris Costelloto violate each general security requirement in the list.
1173092f2e6SChris CostelloEach explanation should be accompanied by instructions
1183092f2e6SChris Costellothe reader should follow in order to avoid a violation.
1193092f2e6SChris CostelloFor the sake of brevity, assume the reader is familiar with
1203092f2e6SChris Costelloall of the concepts in
1211fc841e3SChris Costellothe FSA.
1223092f2e6SChris CostelloWhen referencing potential vulnerabilities
123655f01f6SHiten Pandyadescribed in the Secure Programming Practices manual page,
1241fc841e3SChris Costello.Xr sprog 7 ,
1253092f2e6SChris Costellolikewise cross-reference that document
1263092f2e6SChris Costellorather than replicating information.
1273092f2e6SChris CostelloWhenever possible, refer to this document
1283092f2e6SChris Costellorather than reproducing the material it contains.
129ad25c55eSChris Costello.Ss Where to Stop
1303092f2e6SChris CostelloSecurity problems are often interrelated;
1313092f2e6SChris Costelloindividual problems often have far-reaching implications.
1323092f2e6SChris CostelloFor example, the correctness of virtually any dynamically-linked program
1333092f2e6SChris Costellois dependent on the correct implementation and configuration
1343092f2e6SChris Costelloof the run-time linker.
1353092f2e6SChris CostelloThe correctness of this program, in turn,
1363092f2e6SChris Costellodepends on the correctness of its libraries,
1373092f2e6SChris Costellothe compiler used to build it,
1383092f2e6SChris Costellothe correctness of the preceding compiler that was used to build that compiler,
1393092f2e6SChris Costelloand so on,
1403092f2e6SChris Costelloas described by Thompson (see
1413092f2e6SChris Costello.Sx SEE ALSO ,
1423092f2e6SChris Costellobelow).
1431fc841e3SChris Costello.Pp
1443092f2e6SChris CostelloDue to the need for brevity, security consideration sections
1453092f2e6SChris Costelloshould describe only those issues directly related to the feature
1463092f2e6SChris Costellothat is the subject of the manual page.
1473092f2e6SChris CostelloRefer to other manual pages
1483092f2e6SChris Costellorather than duplicating the material found there.
1493092f2e6SChris CostelloRefer to generalized descriptions of problems in
1501fc841e3SChris Costellothe FSA
1513092f2e6SChris Costellorather than referring to specific instances of those problems
1523092f2e6SChris Costelloin other manual pages.
1533092f2e6SChris CostelloIdeally, each specific security-relevant issue
1543092f2e6SChris Costelloshould be described in exactly one manual page,
1553092f2e6SChris Costellopreferably as a specific instance of a general problem
1563092f2e6SChris Costellodescribed in
1571fc841e3SChris Costellothe FSA.
1581fc841e3SChris Costello.Sh EXAMPLES
1591fc841e3SChris CostelloSecurity considerations sections for most individual functions can follow
1601fc841e3SChris Costellothis simple formula:
1611fc841e3SChris Costello.Pp
1621fc841e3SChris Costello.Bl -enum -offset indent -compact
1631fc841e3SChris Costello.It
1641fc841e3SChris CostelloProvide one or two sentences describing each potential security
1651fc841e3SChris Costelloproblem, referencing
1661fc841e3SChris Costellothe FSA
1671fc841e3SChris Costelloto provide details whenever possible.
1681fc841e3SChris Costello.It
1691fc841e3SChris CostelloProvide one or two sentences describing how to avoid each potential
1701fc841e3SChris Costellosecurity problem.
1711fc841e3SChris Costello.It
1721fc841e3SChris CostelloProvide a short example in code.
1731fc841e3SChris Costello.El
1741fc841e3SChris Costello.Pp
1751fc841e3SChris CostelloThis is an example security considerations section for the
1761fc841e3SChris Costello.Xr strcpy 3
1771fc841e3SChris Costellomanual page:
1781fc841e3SChris Costello.Pp
1791fc841e3SChris CostelloThe
1801fc841e3SChris Costello.Fn strcpy
1811fc841e3SChris Costellofunction is easily misused in a manner which enables malicious users
1823092f2e6SChris Costelloto arbitrarily change a running program's functionality
1833092f2e6SChris Costellothrough a buffer overflow attack.
1843092f2e6SChris Costello(See
1851fc841e3SChris Costellothe FSA.)
1861fc841e3SChris Costello.Pp
1871fc841e3SChris CostelloAvoid using
1881fc841e3SChris Costello.Fn strcpy .
1891fc841e3SChris CostelloInstead, use
1901fc841e3SChris Costello.Fn strncpy
1911fc841e3SChris Costelloand ensure that no more characters are copied to the destination buffer
1921fc841e3SChris Costellothan it can hold.
193e4407b54SChris CostelloDo not forget to NUL-terminate the destination buffer,
1941fc841e3SChris Costelloas
1951fc841e3SChris Costello.Fn strncpy
1961fc841e3SChris Costellowill not terminate the destination string if it is truncated.
1971fc841e3SChris Costello.Pp
1981fc841e3SChris CostelloNote that
1991fc841e3SChris Costello.Fn strncpy
2003092f2e6SChris Costellocan also be problematic.
2013092f2e6SChris CostelloIt may be a security concern for a string to be truncated at all.
2023092f2e6SChris CostelloSince the truncated string will not be as long as the original,
2033092f2e6SChris Costelloit may refer to a completely different resource
2043092f2e6SChris Costelloand usage of the truncated resource
2053092f2e6SChris Costellocould result in very incorrect behavior.
2061fc841e3SChris CostelloExample:
2071fc841e3SChris Costello.Pp
2081fc841e3SChris Costello.Bd -literal
2091fc841e3SChris Costellovoid
2101fc841e3SChris Costellofoo(const char *arbitrary_string)
2111fc841e3SChris Costello{
2121fc841e3SChris Costello	char onstack[8];
2131fc841e3SChris Costello
2141fc841e3SChris Costello#if defined(BAD)
2151fc841e3SChris Costello	/*
216e4407b54SChris Costello	 * This first strcpy is bad behavior.  Do not use strcpy()!
2171fc841e3SChris Costello	 */
2181fc841e3SChris Costello	(void)strcpy(onstack, arbitrary_string);     /* BAD! */
2191fc841e3SChris Costello#elif defined(BETTER)
2201fc841e3SChris Costello	/*
2211fc841e3SChris Costello	 * The following two lines demonstrate better use of
2221fc841e3SChris Costello	 * strncpy().
2231fc841e3SChris Costello	 */
2241fc841e3SChris Costello	(void)strncpy(onstack, arbitrary_string, sizeof(onstack) - 1);
2251fc841e3SChris Costello	onstack[sizeof(onstack - 1)] = '\\0';
2261fc841e3SChris Costello#elif defined(BEST)
2271fc841e3SChris Costello	/*
2281fc841e3SChris Costello	 * These lines are even more robust due to testing for
2291fc841e3SChris Costello	 * truncation.
2301fc841e3SChris Costello	 */
2311fc841e3SChris Costello	if (strlen(arbitrary_string) + 1 > sizeof(onstack))
2321fc841e3SChris Costello		err(1, "onstack would be truncated");
2331fc841e3SChris Costello	(void)strncpy(onstack, arbitrary_string, sizeof(onstack));
2341fc841e3SChris Costello#endif
2351fc841e3SChris Costello}
2361fc841e3SChris Costello.Ed
2371fc841e3SChris Costello.Pp
2383092f2e6SChris CostelloSecurity considerations sections for tools and commands
2393092f2e6SChris Costelloare apt to be less formulaic.
2403092f2e6SChris CostelloLet your list of potentially-violated security requirements
2413092f2e6SChris Costellobe your guide;
2423092f2e6SChris Costelloexplain each one and list a solution in as concise a manner as possible.
2431fc841e3SChris Costello.Pp
2441fc841e3SChris CostelloThis is an example security considerations section for the
2451fc841e3SChris Costello.Xr rtld 1
2461fc841e3SChris Costellomanual page:
2471fc841e3SChris Costello.Pp
2481fc841e3SChris CostelloUsing the LD_LIBRARY_PATH and LD_PRELOAD environment variables,
2493092f2e6SChris Costellomalicious users can cause the dynamic linker
2503092f2e6SChris Costelloto link shared libraries of their own devising
2513092f2e6SChris Costellointo the address space of processes running non-set-user-ID/group-ID programs.
2523092f2e6SChris CostelloThese shared libraries can arbitrarily change the functionality
2533092f2e6SChris Costelloof the program by replacing calls to standard library functions
2543092f2e6SChris Costellowith calls to their own.
2553092f2e6SChris CostelloAlthough this feature is disabled for set-user-ID and set-group-ID programs,
2563092f2e6SChris Costelloit can still be used to create Trojan horses in other programs.
2573092f2e6SChris Costello(See
2581fc841e3SChris Costellothe FSA.)
2591fc841e3SChris Costello.Pp
2601fc841e3SChris CostelloAll users should be aware that the correct operation of non
2611fc841e3SChris Costelloset-user-ID/group-ID dynamically-linked programs depends on the proper
2623092f2e6SChris Costelloconfiguration of these environment variables,
2633092f2e6SChris Costelloand take care to avoid actions that might set them to values
2643092f2e6SChris Costellowhich would cause the run-time linker
2653092f2e6SChris Costelloto link in shared libraries of unknown pedigree.
2661fc841e3SChris Costello.Sh SEE ALSO
2671fc841e3SChris Costello.Xr groff_mdoc 7 ,
2681fc841e3SChris Costello.Xr security 7 ,
2691fc841e3SChris Costello.Xr sprog 7
2701fc841e3SChris Costello.Rs
2711fc841e3SChris Costello.%T "The FreeBSD Security Architecture"
2721fc841e3SChris Costello.%J file:///usr/share/doc/{to be determined}
2731fc841e3SChris Costello.Re
2741fc841e3SChris Costello.Rs
2751fc841e3SChris Costello.%A "Edward Amoroso, AT&T Bell Laboratories"
2761fc841e3SChris Costello.%B "Fundamentals of Computer Security Technology"
2771fc841e3SChris Costello.%I "P T R Prentice Hall"
2781fc841e3SChris Costello.%D "1994"
2791fc841e3SChris Costello.Re
2801fc841e3SChris Costello.Rs
2811fc841e3SChris Costello.%A "Ken Thompson"
2821fc841e3SChris Costello.%T "Reflections on Trusting Trust"
2831fc841e3SChris Costello.%J "Communications of the ACM"
2841fc841e3SChris Costello.%I "Association for Computing Machinery, Inc."
2851fc841e3SChris Costello.%P "761-763"
2861fc841e3SChris Costello.%N "Vol. 27, No. 8"
2871fc841e3SChris Costello.%D "August, 1984"
2881fc841e3SChris Costello.Re
2891fc841e3SChris Costello.Sh HISTORY
2901fc841e3SChris CostelloThe
2911fc841e3SChris Costello.Nm
2921fc841e3SChris Costellomanual page first appeared in
2931fc841e3SChris Costello.Fx 5.0 .
2941fc841e3SChris Costello.Sh AUTHORS
2951fc841e3SChris Costello.An "Tim Fraser, NAI Labs CBOSS project." Aq tfraser@tislabs.com
2961fc841e3SChris Costello.An "Brian Feldman, NAI Labs CBOSS project." Aq bfeldman@tislabs.com
297