Fix PKCS8_decrypt to handle all negative pass_len values#3039
Fix PKCS8_decrypt to handle all negative pass_len values#3039
Conversation
PKCS8_decrypt only checked for pass_len_in == -1 to trigger strlen(pass), while PKCS8_encrypt checked pass_len_in < 0. Passing other negative values (e.g. -2) caused pass_len to wrap to a huge size_t, resulting in an out-of-bounds read and crash. Change the condition to < 0 to match PKCS8_encrypt and document the negative pass_len behavior in both functions' public headers.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3039 +/- ##
==========================================
+ Coverage 78.34% 78.36% +0.01%
==========================================
Files 689 689
Lines 121025 121025
Branches 16964 16965 +1
==========================================
+ Hits 94822 94840 +18
+ Misses 25306 25288 -18
Partials 897 897 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Would you like to add in crypto/pkcs8/pkcs8_test.cc a test like PKCS8_decrypt(encrypted.get(), password, -2) in addition to https://github.com/geedo0/aws-lc/blob/d44f1374c19d428c56ae7dafa84dadae82bcb815/crypto/pkcs8/pkcs8_test.cc#L204
I don't think that's necessary. Logically, there's no difference between -1 or -2 anymore. I don't think there's a meaningful chance of a regression at this point. |
### Issues: N/A ### Description of changes: PKCS8_decrypt only checked for pass_len_in == -1 to trigger strlen(pass), while PKCS8_encrypt checked pass_len_in < 0. Passing other negative values (e.g. -2) caused pass_len to wrap to a huge size_t, resulting in an out-of-bounds read and crash. Change the condition to < 0 to match PKCS8_encrypt and document the negative pass_len behavior in both functions' public headers. ### Call-outs: N/A ### Testing: How is this change tested (unit tests, fuzz tests, etc.)? Are there any testing steps to be verified by the reviewer? CI By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license. Co-authored-by: Justin W Smith <103147162+justsmth@users.noreply.github.com>
### Issues: N/A ### Description of changes: PKCS8_decrypt only checked for pass_len_in == -1 to trigger strlen(pass), while PKCS8_encrypt checked pass_len_in < 0. Passing other negative values (e.g. -2) caused pass_len to wrap to a huge size_t, resulting in an out-of-bounds read and crash. Change the condition to < 0 to match PKCS8_encrypt and document the negative pass_len behavior in both functions' public headers. ### Call-outs: N/A ### Testing: How is this change tested (unit tests, fuzz tests, etc.)? Are there any testing steps to be verified by the reviewer? CI By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license. Co-authored-by: Justin W Smith <103147162+justsmth@users.noreply.github.com>
Issues:
N/A
Description of changes:
PKCS8_decrypt only checked for pass_len_in == -1 to trigger
strlen(pass), while PKCS8_encrypt checked pass_len_in < 0.
Passing other negative values (e.g. -2) caused pass_len to wrap
to a huge size_t, resulting in an out-of-bounds read and crash.
Change the condition to < 0 to match PKCS8_encrypt and document
the negative pass_len behavior in both functions' public headers.
Call-outs:
N/A
Testing:
How is this change tested (unit tests, fuzz tests, etc.)? Are there any testing steps to be verified by the reviewer?
CI
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.