xref: /freebsd/lib/libssp/ssp.3 (revision 8aac90f18aef7c9eea906c3ff9a001ca7b94f375)
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 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 clang 1
98or
99.Xr gcc 1
100command line:
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 clang 1 ,
115.Xr gcc 1 ,
116.Xr __builtin_object_size 3 ,
117.Xr stdio 3 ,
118.Xr string 3 ,
119.Xr security 7
120.Sh HISTORY
121The
122.Nm
123library appeared in
124.Nx 4.0 .
125This version of the
126.Nm
127library replaced the GNU library of the same name in
128.Fx 12.2 .
129