Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EVP: don't call memset for evp_pkey_downgrade
This commit tries to address a locking issue in evp_pkey_reset_unlocked which can occur when it is called from evp_pkey_downgrade. evp_pkey_downgrade will acquire a lock for pk->lock and if successful then call evp_pkey_reset_unlocked. evp_pkey_reset_unlocked will call memset on pk, and then create a new lock and set pk->lock to point to that new lock. I believe there are two problems with this. The first is that after the call to memset, another thread would try to acquire a lock for NULL as that is what the value of pk->lock would be at that point. The second issue is that after the new lock has been assigned to pk->lock, that lock is different from the one currently locked so another thread trying to acquire the lock will succeed which can lead to strange behaviour. More details and a reproducer can be found in the Refs link below. This commit introduces a new function that is only called by evp_pkey_downgrade which does not use memset but instead "manually" sets the EVP_PKEY values to their default values, but does not modify pk->lock. This could perhaps be updated to go back to only having one function that is called for both evp_pkey_downgrade and EVP_PKEY_new and only create a new lock if one does not already exist. Refs: https://github.com/danbev/learning-libcrypto/blob/master/notes/issues.md#openssl-investigationtroubleshooting nodejs/node#29817
- Loading branch information