-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix #78516: password_hash(): Memory cost is outside of allowed memory… #4695
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Unless there are objections, I'll merge this PR on next Monday (so that it makes it into PHP 7.4.0RC2). |
ext/sodium/sodium_pwhash.c
Outdated
} | ||
|
||
static int php_sodium_argon2_get_info(zval *return_value, const zend_string *hash) { | ||
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Applied as 145ffd9. Thanks! |
… 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