Skip to content

Fix PKCS12_verify_mac OOB read with invalid password_len#3051

Merged
geedo0 merged 1 commit intoaws:mainfrom
geedo0:f27
Mar 5, 2026
Merged

Fix PKCS12_verify_mac OOB read with invalid password_len#3051
geedo0 merged 1 commit intoaws:mainfrom
geedo0:f27

Conversation

@geedo0
Copy link
Copy Markdown
Contributor

@geedo0 geedo0 commented Feb 27, 2026

Description of changes:

Reject negative password_len values (other than -1) early in
PKCS12_verify_mac before they are used as an array index or cast
to size_t for OPENSSL_memchr. Update the public header comment to
clarify that -1 means the password is a NUL-terminated C string.

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.

Reject negative password_len values (other than -1) early in
PKCS12_verify_mac before they are used as an array index or cast
to size_t for OPENSSL_memchr. Update the public header comment to
clarify that -1 means the password is a NUL-terminated C string.
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 78.35%. Comparing base (c2548e4) to head (96bfef1).

Files with missing lines Patch % Lines
crypto/pkcs8/pkcs8_x509.c 50.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3051   +/-   ##
=======================================
  Coverage   78.34%   78.35%           
=======================================
  Files         689      689           
  Lines      121025   121027    +2     
  Branches    16964    16967    +3     
=======================================
+ Hits        94822    94830    +8     
+ Misses      25306    25302    -4     
+ Partials      897      895    -2     

☔ 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.

@geedo0 geedo0 marked this pull request as ready for review March 4, 2026 13:39
@geedo0 geedo0 requested a review from a team as a code owner March 4, 2026 13:39
// |password[password_len]| must be zero and no other NUL bytes may appear in
// |NULL| and zero, respectively, or else |password_len| may be -1 to indicate
// that |password| is a NUL-terminated C string whose length is determined via
// |strlen|, or else |password_len| must be non-negative,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

note for reviewers, looks like strlen is called a bit further down the callstack in PKCS12_get_key_and_certs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

not your change, but this is such an odd API contract... it enforces that 1/ password must be NULL-terminated and 2/ password_len == -1 indicates that it's NULL-terminated. then eventually calls strlen unconditionally.

@geedo0 geedo0 merged commit fb0c415 into aws:main Mar 5, 2026
546 of 551 checks passed
WillChilds-Klein pushed a commit to WillChilds-Klein/aws-lc that referenced this pull request Mar 11, 2026
### Description of changes: 
Reject negative password_len values (other than -1) early in
PKCS12_verify_mac before they are used as an array index or cast
to size_t for OPENSSL_memchr. Update the public header comment to
clarify that -1 means the password is a NUL-terminated C string.

### 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.
nebeid pushed a commit to nebeid/aws-lc that referenced this pull request Mar 23, 2026
### Description of changes: 
Reject negative password_len values (other than -1) early in
PKCS12_verify_mac before they are used as an array index or cast
to size_t for OPENSSL_memchr. Update the public header comment to
clarify that -1 means the password is a NUL-terminated C string.

### 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.
@geedo0 geedo0 deleted the f27 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