Skip to content

Fix PKCS8_decrypt to handle all negative pass_len values#3039

Merged
geedo0 merged 3 commits intoaws:mainfrom
geedo0:f29
Mar 5, 2026
Merged

Fix PKCS8_decrypt to handle all negative pass_len values#3039
geedo0 merged 3 commits intoaws:mainfrom
geedo0:f29

Conversation

@geedo0
Copy link
Copy Markdown
Contributor

@geedo0 geedo0 commented Feb 24, 2026

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.

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-commenter
Copy link
Copy Markdown

codecov-commenter commented Feb 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.36%. Comparing base (c2548e4) to head (4356427).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@justsmth justsmth requested review from justsmth and nebeid February 25, 2026 14:52
Copy link
Copy Markdown
Contributor

@nebeid nebeid left a comment

Choose a reason for hiding this comment

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

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

@nebeid nebeid self-requested a review February 26, 2026 19:04
@geedo0
Copy link
Copy Markdown
Contributor Author

geedo0 commented Mar 3, 2026

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.

@geedo0 geedo0 merged commit a48830c into aws:main Mar 5, 2026
453 of 455 checks passed
WillChilds-Klein pushed a commit to WillChilds-Klein/aws-lc that referenced this pull request Mar 11, 2026
### 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>
nebeid pushed a commit to nebeid/aws-lc that referenced this pull request Mar 23, 2026
### 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>
@geedo0 geedo0 deleted the f29 branch March 27, 2026 19:28
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.

4 participants