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

Fixes for Issue #204. #205

Merged
merged 3 commits into from
Jan 16, 2025
Merged

Fixes for Issue #204. #205

merged 3 commits into from
Jan 16, 2025

Conversation

besser82
Copy link
Owner

@besser82 besser82 commented Jan 15, 2025

  • crypt: Zeroize initialized and reserved data members after computation.
  • crypt: Zeroize and initialize (re)allocated memory in crypt_ra.
  • test/short-outbuf: Add two more cases for crypt_ra.

@besser82 besser82 requested a review from solardiz January 15, 2025 11:25
@besser82 besser82 self-assigned this Jan 15, 2025
Copy link

codecov bot commented Jan 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.15%. Comparing base (0cada50) to head (ac873d4).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #205      +/-   ##
===========================================
+ Coverage    90.12%   90.15%   +0.02%     
===========================================
  Files           32       32              
  Lines         3627     3626       -1     
  Branches       690      689       -1     
===========================================
  Hits          3269     3269              
+ Misses         227      226       -1     
  Partials       131      131              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@solardiz
Copy link
Collaborator

BTW, realloc gives us no way to zeroize the previous data if it happens to relocate it to a new address. This could be worth a source code comment maybe, if we started to care about these things here.

@besser82 besser82 force-pushed the topic/besser82/issue_204 branch from 36618ad to 043f5df Compare January 16, 2025 12:23
@besser82 besser82 force-pushed the topic/besser82/issue_204 branch 2 times, most recently from ac873d4 to 5a0547b Compare January 16, 2025 14:37
@besser82
Copy link
Owner Author

besser82 commented Jan 16, 2025

BTW, realloc gives us no way to zeroize the previous data if it happens to relocate it to a new address. This could be worth a source code comment maybe, if we started to care about these things here.

I've taken that into account in the rebased commits.

@solardiz
Copy link
Collaborator

The code on its own looks good to me now, although I suggest to use a simple memset after the realloc because in that place it's pure initialization and not zeroization of sensitive data.

While at it, I once again notice that we have some unfortunate (in my opinion) recommendations in the man page: "Applications are encouraged, but not required, to use the phrase and setting fields to store the strings that they will pass as phrase and setting to crypt_r." I think it's very wrong that we don't just keep this struct opaque to the callers (except maybe for the initialized field). We may want to fix that separately.

Also unify the codepaths for (re)allocation.
 * outbuf != NULL with negative size parameter, and
 * outbuf == NULL with valid size parameter.
@besser82 besser82 force-pushed the topic/besser82/issue_204 branch from 5a0547b to fe5b8b8 Compare January 16, 2025 18:35
@besser82 besser82 merged commit fe5b8b8 into develop Jan 16, 2025
94 checks passed
@besser82 besser82 deleted the topic/besser82/issue_204 branch January 16, 2025 18:49
@besser82
Copy link
Owner Author

The code on its own looks good to me now, although I suggest to use a simple memset after the realloc because in that place it's pure initialization and not zeroization of sensitive data.

Fixed in merged commits.

While at it, I once again notice that we have some unfortunate (in my opinion) recommendations in the man page: "Applications are encouraged, but not required, to use the phrase and setting fields to store the strings that they will pass as phrase and setting to crypt_r." I think it's very wrong that we don't just keep this struct opaque to the callers (except maybe for the initialized field). We may want to fix that separately.

Let's do this in a seperate PR.

@@ -181,6 +181,8 @@ do_crypt (const char *phrase, const char *setting, struct crypt_data *data)
cint->alg_specific, sizeof cint->alg_specific);

explicit_bzero (data->internal, sizeof data->internal);
explicit_bzero (data->reserved, sizeof data->reserved);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I suggest we don't zeroize reserved. This serves no purpose with current libxcrypt, and it could unnecessarily limit how we're able to use the reserved space in future/mixed versions.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, I didn't realize you merged this already. Nevermind, then.

Copy link
Owner Author

Choose a reason for hiding this comment

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

I suggest we don't zeroize reserved. This serves no purpose with current libxcrypt, and it could unnecessarily limit how we're able to use the reserved space in future/mixed versions.

I think we can drop it, if we decide to use that field to store a state or sth. in later versions.

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.

2 participants