Skip to content

Add INT_MAX bounds check before EVP_CipherUpdate in PKCS8/PKCS12 encryption#3043

Merged
geedo0 merged 2 commits intoaws:mainfrom
geedo0:f36
Mar 5, 2026
Merged

Add INT_MAX bounds check before EVP_CipherUpdate in PKCS8/PKCS12 encryption#3043
geedo0 merged 2 commits intoaws:mainfrom
geedo0:f36

Conversation

@geedo0
Copy link
Copy Markdown
Contributor

@geedo0 geedo0 commented Feb 25, 2026

Issues:

N/A

Description of changes:

EVP_CipherUpdate takes int for in_len, but add_encrypted_data and
PKCS8_marshal_encrypted_private_key pass size_t values. Add a check
that in_len + block_size fits in int to prevent silent truncation on
64-bit systems and size_t wraparound on 32-bit systems. This replaces
the previous size_t-only overflow check with a unified check that
covers both concerns.

Call-outs:

There are a couple overlapping concerns here and we should make sure the logic is sound.

  • On a 64-bit system, size_t will be 64-bits wide and int will be 32-bits wide. This potentially results in a silent truncation due to EVP_CipherUpdate's int input.
  • The Cipher's block-size (128-bits for AES) is added to the input length to determine the output buffer to allocate. This has the potential to overflow the size_t used to allocate that buffer (more of a concern for 32-bit systems).

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.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Feb 25, 2026

Codecov Report

❌ Patch coverage is 80.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.37%. Comparing base (e0cf5f8) to head (e6bf0fa).
⚠️ Report is 36 commits behind head on main.

Files with missing lines Patch % Lines
crypto/pkcs8/pkcs8.c 80.00% 1 Missing ⚠️
crypto/pkcs8/pkcs8_x509.c 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3043      +/-   ##
==========================================
- Coverage   78.38%   78.37%   -0.01%     
==========================================
  Files         689      689              
  Lines      121129   121131       +2     
  Branches    16968    16970       +2     
==========================================
- Hits        94948    94938      -10     
- Misses      25287    25297      +10     
- Partials      894      896       +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.

justsmth
justsmth previously approved these changes Feb 25, 2026
…yption

EVP_CipherUpdate takes int for in_len, but add_encrypted_data and
PKCS8_marshal_encrypted_private_key pass size_t values. Add a check
that in_len + block_size fits in int to prevent silent truncation on
64-bit systems and size_t wraparound on 32-bit systems. This replaces
the previous size_t-only overflow check with a unified check that
covers both concerns.
@geedo0 geedo0 enabled auto-merge (squash) March 5, 2026 15:27
@geedo0 geedo0 merged commit 5039544 into aws:main Mar 5, 2026
546 of 560 checks passed
WillChilds-Klein pushed a commit to WillChilds-Klein/aws-lc that referenced this pull request Mar 11, 2026
…yption (aws#3043)

### Issues:
N/A

### Description of changes: 
EVP_CipherUpdate takes int for in_len, but add_encrypted_data and
PKCS8_marshal_encrypted_private_key pass size_t values. Add a check
that in_len + block_size fits in int to prevent silent truncation on
64-bit systems and size_t wraparound on 32-bit systems. This replaces
the previous size_t-only overflow check with a unified check that
covers both concerns.

### Call-outs:

There are a couple overlapping concerns here and we should make sure the
logic is sound.
- On a 64-bit system, `size_t` will be 64-bits wide and `int` will be
32-bits wide. This potentially results in a silent truncation due to
`EVP_CipherUpdate`'s `int` input.
- The Cipher's block-size (128-bits for AES) is added to the input
length to determine the output buffer to allocate. This has the
potential to overflow the `size_t` used to allocate that buffer (more of
a concern for 32-bit systems).

### 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
…yption (aws#3043)

### Issues:
N/A

### Description of changes: 
EVP_CipherUpdate takes int for in_len, but add_encrypted_data and
PKCS8_marshal_encrypted_private_key pass size_t values. Add a check
that in_len + block_size fits in int to prevent silent truncation on
64-bit systems and size_t wraparound on 32-bit systems. This replaces
the previous size_t-only overflow check with a unified check that
covers both concerns.

### Call-outs:

There are a couple overlapping concerns here and we should make sure the
logic is sound.
- On a 64-bit system, `size_t` will be 64-bits wide and `int` will be
32-bits wide. This potentially results in a silent truncation due to
`EVP_CipherUpdate`'s `int` input.
- The Cipher's block-size (128-bits for AES) is added to the input
length to determine the output buffer to allocate. This has the
potential to overflow the `size_t` used to allocate that buffer (more of
a concern for 32-bit systems).

### 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 f36 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