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

Code fixes from audit #105

Merged
merged 3 commits into from
Nov 26, 2019
Merged

Code fixes from audit #105

merged 3 commits into from
Nov 26, 2019

Conversation

matthewbauer
Copy link
Collaborator

Assortment of changes based on audit:

  • Use sizeof(level_t) instead of sizeof(int) in apdu_reset
  • Use explicit_bzero in place of memset
  • Guard against buffer underflow in b58enc

int can be different sizes on different platforms (although 32-bit is
most common). To ensure portability we can use the ‘level_t’ type
which is defined as a uint32_t value. This should have no difference
in function.

Co-authored-by: Jean-Baptiste Bédrune
This is a safer version of memset where memory is completely cleared.
This is useful for sensitive data like private keys.

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

Co-authored-by: Jean-Baptiste Bédrune
Detected by ASAN, buffer underflow occurs when code is capable of
unbounded writing to before the buffer begins (compare to buffer
overflow). This change ensures that the index is always greater than
0.

Co-authored-by: Jean-Baptiste Bédrune
@@ -35,7 +35,7 @@ static inline void generate_key_pair(
check_null(out);
key_pair_t *const result = generate_key_pair_return_global(derivation_type, bip32_path);
memcpy(out, result, sizeof(*out));
memset(result, 0, sizeof(*result));
explicit_bzero(result, sizeof(*result));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a lot of other places that we use memset(..., 0, ...). Should we replace all of them?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might not hurt to do that! Here I am just rewriting the ones that have some private key behind it. If the data's not sensitive, it's probably cheaper to just use memset, but maybe not something we should worry about.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've merged this as-is; I'll get a ticket in the backlog to investigate whether to replace the other uses of memset(..., 0, ...) with explicit_bzero.

@jonored jonored merged commit 8fca217 into develop Nov 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants