Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use explicit_bzero() if available #148

Closed
wants to merge 4 commits into from

Conversation

michaelortmann
Copy link

Use explicit_bzero() if available

The 'volatile' solution may not work as expected

Quote from https://www.gnu.org/software/libc/manual/html_node/Erasing-Sensitive-Data.html:

Declaring sensitive variables as volatile will make both the above problems worse; a volatile variable will be stored in memory for its entire lifetime, and the compiler will make more copies of it than it would otherwise have. Attempting to erase a normal variable “by hand” through a volatile-qualified pointer doesn’t work at all—because the variable itself is not volatile, some compilers will ignore the qualification on the pointer and remove the erasure anyway.

comm.c Outdated Show resolved Hide resolved
meson.build Outdated Show resolved Hide resolved
meson.build Outdated Show resolved Hide resolved
@emersion
Copy link
Member

The 'volatile' solution may not work as expected

This isn't much of an issue: volatile isn't used for the sensitive data, instead it's used for the zeroes.

@emersion
Copy link
Member

Yeah, this requires _GNU_SOURCE as I thought.

I'm not sure it's worth it to maintain this extra complexity for unclear benefits.

@emersion
Copy link
Member

Sorry, I'm going to close this, we prefer to avoid non-POSIX functions.

@emersion emersion closed this Aug 14, 2021
@nmeum
Copy link

nmeum commented Mar 30, 2024

Sorry, I'm going to close this, we prefer to avoid non-POSIX functions.

You cannot reliably zero memory without avoiding non-POSIX functions. explicit_bzero is nowadays implemented by OpenBSD, musl libc, and glibc (i.e. it is widely available). If you rely on the volatile keyword, chances are that the zero'ing is optimized out by the compiler. For more background information refer to https://media.ccc.de/v/35c3-9788-memsad

@nmeum
Copy link

nmeum commented Mar 30, 2024

Since this issue has been closed for a couple of years now, I have opened #353 with a somewhat simpler implementation in the hopes of resuming the discussion there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants