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