xref: /netbsd-src/lib/libc/ssp/ssp.3 (revision 8b0f9554ff8762542c4defc4f70e1eb76fb508fa)
1.\"	$NetBSD: ssp.3,v 1.2 2007/08/20 16:07:05 perry Exp $
2.\"
3.\" Copyright (c) 2007 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Christos Zoulas.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\" 3. All advertising materials mentioning features or use of this software
18.\"    must display the following acknowledgement:
19.\"        This product includes software developed by the NetBSD
20.\"        Foundation, Inc. and its contributors.
21.\" 4. Neither the name of The NetBSD Foundation nor the names of its
22.\"    contributors may be used to endorse or promote products derived
23.\"    from this software without specific prior written permission.
24.\"
25.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35.\" POSSIBILITY OF SUCH DAMAGE.
36.\"
37.\"
38.Dd May 23, 2007
39.Dt SSP 3
40.Os
41.Sh NAME
42.Nm ssp
43.Nd bounds checked libc functions
44.Sh LIBRARY
45.Lb libssp
46.Sh SYNOPSIS
47.In ssp/stdio.h
48.Ft int
49.Fn sprintf "char *str" "const char *fmt" "..."
50.Ft int
51.Fn vsprintf "char *str" "const char *fmt" "va_list ap"
52.Ft int
53.Fn snprintf "char *str" "size_t len" "const char *fmt" "..."
54.Ft int
55.Fn vsnprintf "char *str" "size_t len" "const char *fmt" "va_list ap"
56.Ft char *
57.Fn gets "char *str"
58.Ft char *
59.Fn fgets "char *str" "int len" "FILE *fp"
60.In ssp/string.h
61.Ft void *
62.Fn memcpy "void *str" "const void *ptr" "size_t len"
63.Ft void *
64.Fn memmove "void *str" "const void *ptr" "size_t len"
65.Ft void *
66.Fn memset "void *str" "int val" "size_t len"
67.Ft char *
68.Fn strcpy "char *str" "const char *ptr" "size_t len"
69.Ft char *
70.Fn strcat "char *str" "const char *ptr" "size_t len"
71.Ft char *
72.Fn strncpy "char *str" "const char *ptr" "size_t len"
73.Ft char *
74.Fn strncat "char *str" "const char *ptr" "size_t len"
75.In ssp/strings.h
76.Ft void *
77.Fn bcopy "const void *ptr" "void *str" "size_t len"
78.Ft void *
79.Fn bzero "void *str" "size_t len"
80.In ssp/unistd.h
81.Ft ssize_t
82.Fn read "int fd" "void *str" "size_t len"
83.Ft int
84.Fn readlink "const char * restrict path" "char * restrict str" "size_t len"
85.Ft int
86.Fn getcwd "char *str" "size_t len"
87.Sh DESCRIPTION
88When
89.Dv _FORTIFY_SOURCE
90bounds checking is enabled as described below, the above functions get
91overwriten to use the
92.Xr gcc 1
93.Xr __builtin_object_size 3
94function to compute the size of
95.Fa str
96if known at compile time and perform bounds check on it in order
97to avoid data buffer or stack buffer overflows.
98If an overflow is detected the routines will call
99.Xr abort 3 .
100.Pp
101To enable these function overrides the following should be added to the
102.Xr gcc 1
103command line:
104.Dq \-I/usr/include/ssp
105to override the standard include files and
106.Dq \-D_FORTIFY_SOURCE=1
107or
108.Dq \-D_FORTIFY_SOURCE=2 .
109.Pp
110If
111.Dv _FORTIFY_SOURCE is set to
112.Dv 1
113the code will compute the maximum possible buffer size for
114.Fa str ,
115and if set to
116.Dv 2
117it will compute the minimum buffer size.
118.Sh SEE ALSO
119.Xr gcc 1 ,
120.Xr read 2 ,
121.Xr readlink 2 ,
122.Xr getcwd 3 ,
123.Xr stdio 3 ,
124.Xr string 3 ,
125.Xr abort 3 ,
126.Xr __builtin_object_size 3
127.Sh HISTORY
128The
129.Nm ssp
130library appeared
131.Nx 4.0 .
132