tzfile.5, tzselect.8: sync from tzdb upstream
[man-pages.git] / man3 / bzero.3
blob0d7171bf8ade6e3aa7e485f44edff246ff7b3e04
1 '\" t
2 .\" Copyright (C) 2017 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\"
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\"
6 .TH bzero 3 (date) "Linux man-pages (unreleased)"
7 .SH NAME
8 bzero, explicit_bzero \- zero a byte string
9 .SH LIBRARY
10 Standard C library
11 .RI ( libc ", " \-lc )
12 .SH SYNOPSIS
13 .nf
14 .B #include <strings.h>
15 .PP
16 .BI "void bzero(void " s [. n "], size_t " n );
17 .PP
18 .B #include <string.h>
19 .PP
20 .BI "void explicit_bzero(void " s [. n "], size_t " n );
21 .fi
22 .SH DESCRIPTION
23 The
24 .BR bzero ()
25 function erases the data in the
26 .I n
27 bytes of the memory starting at the location pointed to by
28 .IR s ,
29 by writing zeros (bytes containing \[aq]\e0\[aq]) to that area.
30 .PP
31 The
32 .BR explicit_bzero ()
33 function performs the same task as
34 .BR bzero ().
35 It differs from
36 .BR bzero ()
37 in that it guarantees that compiler optimizations will not remove the
38 erase operation if the compiler deduces that the operation is "unnecessary".
39 .SH RETURN VALUE
40 None.
41 .SH VERSIONS
42 .BR explicit_bzero ()
43 first appeared in glibc 2.25.
44 .SH ATTRIBUTES
45 For an explanation of the terms used in this section, see
46 .BR attributes (7).
47 .ad l
48 .nh
49 .TS
50 allbox;
51 lbx lb lb
52 l l l.
53 Interface       Attribute       Value
55 .BR bzero (),
56 .BR explicit_bzero ()
57 T}      Thread safety   MT-Safe
58 .TE
59 .hy
60 .ad
61 .sp 1
62 .SH STANDARDS
63 The
64 .BR bzero ()
65 function is deprecated (marked as LEGACY in POSIX.1-2001); use
66 .BR memset (3)
67 in new programs.
68 POSIX.1-2008 removes the specification of
69 .BR bzero ().
70 The
71 .BR bzero ()
72 function first appeared in 4.3BSD.
73 .PP
74 The
75 .BR explicit_bzero ()
76 function is a nonstandard extension that is also present on some of the BSDs.
77 Some other implementations have a similar function, such as
78 .BR memset_explicit ()
80 .BR memset_s ().
81 .SH NOTES
82 The
83 .BR explicit_bzero ()
84 function addresses a problem that security-conscious applications
85 may run into when using
86 .BR bzero ():
87 if the compiler can deduce that the location to be zeroed will
88 never again be touched by a
89 .I correct
90 program, then it may remove the
91 .BR bzero ()
92 call altogether.
93 This is a problem if the intent of the
94 .BR bzero ()
95 call was to erase sensitive data (e.g., passwords)
96 to prevent the possibility that the data was leaked
97 by an incorrect or compromised program.
98 Calls to
99 .BR explicit_bzero ()
100 are never optimized away by the compiler.
103 .BR explicit_bzero ()
104 function does not solve all problems associated with erasing sensitive data:
105 .IP \[bu] 3
107 .BR explicit_bzero ()
108 function does
109 .I not
110 guarantee that sensitive data is completely erased from memory.
111 (The same is true of
112 .BR bzero ().)
113 For example, there may be copies of the sensitive data in
114 a register and in "scratch" stack areas.
116 .BR explicit_bzero ()
117 function is not aware of these copies, and can't erase them.
118 .IP \[bu]
119 In some circumstances,
120 .BR explicit_bzero ()
122 .I decrease
123 security.
124 If the compiler determined that the variable containing the
125 sensitive data could be optimized to be stored in a register
126 (because it is small enough to fit in a register,
127 and no operation other than the
128 .BR explicit_bzero ()
129 call would need to take the address of the variable), then the
130 .BR explicit_bzero ()
131 call will force the data to be copied from the register
132 to a location in RAM that is then immediately erased
133 (while the copy in the register remains unaffected).
134 The problem here is that data in RAM is more likely to be exposed
135 by a bug than data in a register, and thus the
136 .BR explicit_bzero ()
137 call creates a brief time window where the sensitive data is more
138 vulnerable than it would otherwise have been
139 if no attempt had been made to erase the data.
141 Note that declaring the sensitive variable with the
142 .B volatile
143 qualifier does
144 .I not
145 eliminate the above problems.
146 Indeed, it will make them worse, since, for example,
147 it may force a variable that would otherwise have been optimized
148 into a register to instead be maintained in (more vulnerable)
149 RAM for its entire lifetime.
151 Notwithstanding the above details, for security-conscious applications, using
152 .BR explicit_bzero ()
153 is generally preferable to not using it.
154 The developers of
155 .BR explicit_bzero ()
156 anticipate that future compilers will recognize calls to
157 .BR explicit_bzero ()
158 and take steps to ensure that all copies of the sensitive data are erased,
159 including copies in registers or in "scratch" stack areas.
160 .SH SEE ALSO
161 .BR bstring (3),
162 .BR memset (3),
163 .BR swab (3)