xref: /minix/lib/libc/ssp/ssp.3 (revision 84d9c625)
1.\"	$NetBSD: ssp.3,v 1.8 2013/11/07 02:01:42 christos 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.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28.\" POSSIBILITY OF SUCH DAMAGE.
29.\"
30.\"
31.Dd November 6, 2013
32.Dt SSP 3
33.Os
34.Sh NAME
35.Nm ssp
36.Nd bounds checked libc functions
37.Sh LIBRARY
38.Lb libssp
39.Sh SYNOPSIS
40.In ssp/stdio.h
41.Ft int
42.Fn sprintf "char *str" "const char *fmt" "..."
43.Ft int
44.Fn vsprintf "char *str" "const char *fmt" "va_list ap"
45.Ft int
46.Fn snprintf "char *str" "size_t len" "const char *fmt" "..."
47.Ft int
48.Fn vsnprintf "char *str" "size_t len" "const char *fmt" "va_list ap"
49.Ft char *
50.Fn gets "char *str"
51.Ft char *
52.Fn fgets "char *str" "int len" "FILE *fp"
53.In ssp/string.h
54.Ft void *
55.Fn memcpy "void *str" "const void *ptr" "size_t len"
56.Ft void *
57.Fn memmove "void *str" "const void *ptr" "size_t len"
58.Ft void *
59.Fn memset "void *str" "int val" "size_t len"
60.Ft char *
61.Fn stpcpy "char *str" "const char *ptr"
62.Ft char *
63.Fn strcpy "char *str" "const char *ptr"
64.Ft char *
65.Fn strcat "char *str" "const char *ptr"
66.Ft char *
67.Fn strncpy "char *str" "const char *ptr" "size_t len"
68.Ft char *
69.Fn strncat "char *str" "const char *ptr" "size_t len"
70.In ssp/strings.h
71.Ft void *
72.Fn bcopy "const void *ptr" "void *str" "size_t len"
73.Ft void *
74.Fn bzero "void *str" "size_t len"
75.In ssp/unistd.h
76.Ft ssize_t
77.Fn read "int fd" "void *str" "size_t len"
78.Ft int
79.Fn readlink "const char * restrict path" "char * restrict str" "size_t len"
80.Ft int
81.Fn getcwd "char *str" "size_t len"
82.Sh DESCRIPTION
83When
84.Dv _FORTIFY_SOURCE
85bounds checking is enabled as described below, the above functions get
86overwritten to use the
87.Xr __builtin_object_size 3
88function to compute the size of
89.Fa str ,
90if known at compile time,
91and perform bounds check on it in order
92to avoid data buffer or stack buffer overflows.
93If an overflow is detected, the routines will call
94.Xr abort 3 .
95.Pp
96To enable these function overrides the following should be added to the
97.Xr gcc 1
98command line:
99.Dq \-I/usr/include/ssp
100to override the standard include files and
101.Dq \-D_FORTIFY_SOURCE=1
102or
103.Dq \-D_FORTIFY_SOURCE=2 .
104.Pp
105If
106.Dv _FORTIFY_SOURCE is set to
107.Dv 1
108the code will compute the maximum possible buffer size for
109.Fa str ,
110and if set to
111.Dv 2
112it will compute the minimum buffer size.
113.Sh SEE ALSO
114.Xr gcc 1 ,
115.Xr __builtin_object_size 3 ,
116.Xr stdio 3 ,
117.Xr string 3 ,
118.Xr security 7
119.Sh HISTORY
120The
121.Nm ssp
122library appeared
123.Nx 4.0 .
124