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

Fixed md5 buffer in LLMD5::finalize not being correctly zero-initialized #2507

Merged

Conversation

Hecklezz
Copy link
Contributor

@Hecklezz Hecklezz commented Sep 5, 2024

Fixes the error mentioned in my issue posted here-
#2500

Unless I am mistaken and it is intentional, the md5 buffer in the LLMD5::finalize function is being incorrectly zeroized and instead only the first byte is being zeroized.

Also went ahead and refactored the code so it more closely matches the styling of the rest of the codebase.

Copy link
Contributor

@marchcat marchcat left a comment

Choose a reason for hiding this comment

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

Nice! Thank you!

@marchcat marchcat added this to the Develop milestone Sep 5, 2024
@marchcat
Copy link
Contributor

marchcat commented Sep 5, 2024

Mac build fails with

/Users/runner/work/viewer/viewer/indra/llcommon/llmd5.cpp:219:10: error: array type 'uint8_t[64]' is not assignable
  buffer = {};
  ~~~~~~ ^
1 error generated.

so the buffer should be either initialized as

std::array<uint8_t, 64> buffer = {};

or, alternatively, we can use std::fill:

std::fill(std::begin(buffer), std::end(buffer), 0);

@Hecklezz
Copy link
Contributor Author

Hecklezz commented Sep 5, 2024

Whoops my bad, I really should have tested compiling first before blindly making that change and trusting intellisense that it said nothing was wrong and not remembering that C arrays are not assignable like that after they have already been defined.

Should we stick with memset since a large portion of the rest of the codebase is still using memset, or should the code be changed to be more in line with modern C++ standards?

@Nicky-D
Copy link
Contributor

Nicky-D commented Sep 5, 2024

While at it, can we maybe change the finalized member to a bool?

Regarding memset. If this is down deemed security related and the buffer must be cleared, then memset_s or something like SecureZeroMemory needs to be employed.
Otherwise the compiler can happily optimize that call to memset away (dunno if it would do here, probably not?)

@Hecklezz Hecklezz force-pushed the fix/incorrect-zero-initialize-1 branch from 64d67aa to c3e4056 Compare September 5, 2024 12:53
@Hecklezz
Copy link
Contributor Author

Hecklezz commented Sep 5, 2024

I went back to using regular memset. Doing some googling, supposedly MSVC does not even have memset_s implemented even if you set the define it wants, and SecureZeroMemory is windows specific so that isn't helpful either.

I also went ahead and did a bit of a tidy-up of the llmd5 files so they weren't so outdated interms of code styling.

@Hecklezz Hecklezz force-pushed the fix/incorrect-zero-initialize-1 branch from c3e4056 to 208e4c4 Compare September 5, 2024 13:00
Copy link
Contributor

@marchcat marchcat left a comment

Choose a reason for hiding this comment

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

It looks much better now.

Thank you for your efforts!

@marchcat marchcat removed this from the Develop milestone Sep 5, 2024
@marchcat marchcat merged commit bacf9cf into secondlife:develop Sep 5, 2024
11 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Sep 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Possible error in llmd5 finalize function leaving sensitive information not zeroized?
3 participants