Fix #78516: password_hash(): Memory cost is outside of allowed memory…#4695
Closed
cmb69 wants to merge 5 commits intophp:PHP-7.4from
Closed
Fix #78516: password_hash(): Memory cost is outside of allowed memory…#4695cmb69 wants to merge 5 commits intophp:PHP-7.4from
cmb69 wants to merge 5 commits intophp:PHP-7.4from
Conversation
… range libsodium measures the memory cost in bytes, while password_hash() and friends expect kibibyte values. We have to properly map between these scales not only when calling libsodium functions, but also when checking for allowed values.
Girgias
reviewed
Sep 10, 2019
Member
Author
|
Unless there are objections, I'll merge this PR on next Monday (so that it makes it into PHP 7.4.0RC2). |
nikic
reviewed
Sep 11, 2019
nikic
reviewed
Sep 14, 2019
nikic
reviewed
Sep 14, 2019
ext/sodium/sodium_pwhash.c
Outdated
| const char* p = NULL; | ||
| zend_long v = 0, threads = 1; | ||
| zend_long memory_cost = PHP_SODIUM_PWHASH_MEMLIMIT; | ||
| zend_long memory_cost = PHP_SODIUM_PWHASH_MEMLIMIT << 10; |
Member
There was a problem hiding this comment.
I don't think this one is right. It shouldn't really happen anyway (that means that the sscanf failed and the hash is essentially corrupt), but if in this context memory_cost shouldn't by multiplied by 1k, I think
Member
Author
There was a problem hiding this comment.
Oh, you're right.
It seems to me that we should catch failing sscanf() here. Otherwise password_needs_rehash() may return true, although password_get_info() returns values which wouldn't indicate that.
Member
Author
|
Applied as 145ffd9. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
… range
libsodium measures the memory cost in bytes, while password_hash() and
friends expect kibibyte values. We have to properly map between these
scales not only when calling libsodium functions, but also when
checking for allowed values.
cc @sgolemon