bzero, explicit_bzero(3) | zero a byte string |
bstring, bcmp, bcopy, bzero, memccpy, memchr, memcmp, memcpy, memfrob, memmem, memmove, memset(3) | byte string operations |
bzero(3) | Library Functions Manual | bzero(3) |
bzero, explicit_bzero - zero a byte string
Standard C library (libc, -lc)
#include <strings.h>
void bzero(void s[.n], size_t n);
#include <string.h>
void explicit_bzero(void s[.n], size_t n);
The bzero() function erases the data in the n bytes of the memory starting at the location pointed to by s, by writing zeros (bytes containing '\0') to that area.
The explicit_bzero() function performs the same task as bzero(). It differs from bzero() in that it guarantees that compiler optimizations will not remove the erase operation if the compiler deduces that the operation is "unnecessary".
None.
For an explanation of the terms used in this section, see attributes(7).
Interface | Attribute | Value |
bzero (), explicit_bzero () | Thread safety | MT-Safe |
None.
The explicit_bzero() function addresses a problem that security-conscious applications may run into when using bzero(): if the compiler can deduce that the location to be zeroed will never again be touched by a correct program, then it may remove the bzero() call altogether. This is a problem if the intent of the bzero() call was to erase sensitive data (e.g., passwords) to prevent the possibility that the data was leaked by an incorrect or compromised program. Calls to explicit_bzero() are never optimized away by the compiler.
The explicit_bzero() function does not solve all problems associated with erasing sensitive data:
Note that declaring the sensitive variable with the volatile qualifier does not eliminate the above problems. Indeed, it will make them worse, since, for example, it may force a variable that would otherwise have been optimized into a register to instead be maintained in (more vulnerable) RAM for its entire lifetime.
Notwithstanding the above details, for security-conscious applications, using explicit_bzero() is generally preferable to not using it. The developers of explicit_bzero() anticipate that future compilers will recognize calls to explicit_bzero() and take steps to ensure that all copies of the sensitive data are erased, including copies in registers or in "scratch" stack areas.
bstring(3), memset(3), swab(3)
2023-07-20 | Linux man-pages 6.05.01 |