generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 152
Adding detection of out-of-bound pre-bound memory read to AES-XTS tests. #2286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2286 +/- ##
==========================================
+ Coverage 79.02% 79.04% +0.01%
==========================================
Files 614 614
Lines 106934 106953 +19
Branches 15145 15146 +1
==========================================
+ Hits 84504 84537 +33
+ Misses 21777 21762 -15
- Partials 653 654 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
skmcgrail
approved these changes
Mar 27, 2025
justsmth
approved these changes
Mar 28, 2025
Merged
skmcgrail
added a commit
that referenced
this pull request
Mar 28, 2025
## What's Changed * Revert "Allow constructed strings in BER parsing (#2015)" by @samuel40791765 in #2278 * Add the rehash utility to the openssl CLI tool by @smittals2 in #2258 * Documentation on service indicator by @justsmth in #2281 * Update patches in Ruby CI by @samuel40791765 in #2233 * Reject DSA trailing garbage in EVP layer, add test cases by @skmcgrail in #2289 * Add support for verifying PKCS7 signed attributes by @samuel40791765 in #2264 * Add support for more SSL BIO functions by @samuel40791765 in #2273 * Wire-up rust-openssl into GitHub CI (for the time being) by @skmcgrail in #2291 * Adding detection of out-of-bound pre-bound memory read to AES-XTS tests. by @nebeid in #2286 * AES: Add function pointer trampoline to avoid delocator issue by @hanno-becker in #2294 * Bump mysql CI to 9.2.0 by @samuel40791765 in #2161 * Cherrypick hardening DSA param checks from BoringSSL by @smittals2 in #2293 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
added a commit
to nebeid/aws-lc
that referenced
this pull request
Apr 8, 2025
…ts. (aws#2286) This change hardens the tests introduced in aws#2227 Fix out-of-bound (OOB) input read in AES-XTS Decrypt in AVX-512 implementation. It adds a memory page preceding the input and output buffer that is protected against read and write in order to detect any under-read, in which case a segfault occurs. The suspected code that can potentially cause a "pre-bound" OOB is the cipher-stealing section in Encrypt [crypto/fipsmodule/aes/asm/aesni-xts-avx512.pl#L1809-L1810](https://github.com/aws/aws-lc/blob/v1.48.5/crypto/fipsmodule/aes/asm/aesni-xts-avx512.pl#L1809-L1810) and decrypt [crypto/fipsmodule/aes/asm/aesni-xts-avx512.pl#2572-L2573](https://github.com/aws/aws-lc/blob/v1.48.5/crypto/fipsmodule/aes/asm/aesni-xts-avx512.pl#L2572-L2573). The efficacy of the added test was shown by changing the decrypt cipher-stealing code for example to: ```diff --- a/crypto/fipsmodule/aes/asm/aesni-xts-avx512.pl +++ b/crypto/fipsmodule/aes/asm/aesni-xts-avx512.pl @@ -2569,7 +2569,7 @@ ___ vpshufb %xmm10,%xmm8,%xmm8 - vmovdqu -0x10($input,$length,1),%xmm3 + vmovdqu -0x12($input,$length,1),%xmm3 vmovdqu %xmm8,-0x10($output,$length,1) ``` With this change, a segmentation fault occurs in the test vector of input length 17 bytes (1 AES block + 1 byte); which is the smallest test vector that requires cipher stealing. At the changed line: - `$input` points at byte 16, i.e. past the first block - `$length` = 1, after [l.2429](https://github.com/aws/aws-lc/blob/v1.48.5/crypto/fipsmodule/aes/asm/aesni-xts-avx512.pl#L2429) - the read index with the diff change is `$input + $length - 18` = `$input -17`, which points at byte "-1", i.e. the byte right before byte 0 of the input, i.e. an underread, this causes a segfault at this vector. - Other larger changes, e.g. -0x20, will have the same result. Another test changes the location of the written output ```@@ -2607,7 +2607,7 @@ ___ .L_done_${rndsuffix}: # store last ciphertext value - vmovdqu %xmm8,-0x10($output) + vmovdqu %xmm8,-0x11($output) ___ } ``` - This test caused a segfault with the smallest input of 1 block = 16 bytes Similar tests in the encrypt path gave the same result of segfaulting when trying to read before the input beginning. 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
added a commit
to nebeid/aws-lc
that referenced
this pull request
Apr 8, 2025
…ts. (aws#2286) This change hardens the tests introduced in aws#2227 Fix out-of-bound (OOB) input read in AES-XTS Decrypt in AVX-512 implementation. It adds a memory page preceding the input and output buffer that is protected against read and write in order to detect any under-read, in which case a segfault occurs. The suspected code that can potentially cause a "pre-bound" OOB is the cipher-stealing section in Encrypt [crypto/fipsmodule/aes/asm/aesni-xts-avx512.pl#L1809-L1810](https://github.com/aws/aws-lc/blob/v1.48.5/crypto/fipsmodule/aes/asm/aesni-xts-avx512.pl#L1809-L1810) and decrypt [crypto/fipsmodule/aes/asm/aesni-xts-avx512.pl#2572-L2573](https://github.com/aws/aws-lc/blob/v1.48.5/crypto/fipsmodule/aes/asm/aesni-xts-avx512.pl#L2572-L2573). The efficacy of the added test was shown by changing the decrypt cipher-stealing code for example to: ```diff --- a/crypto/fipsmodule/aes/asm/aesni-xts-avx512.pl +++ b/crypto/fipsmodule/aes/asm/aesni-xts-avx512.pl @@ -2569,7 +2569,7 @@ ___ vpshufb %xmm10,%xmm8,%xmm8 - vmovdqu -0x10($input,$length,1),%xmm3 + vmovdqu -0x12($input,$length,1),%xmm3 vmovdqu %xmm8,-0x10($output,$length,1) ``` With this change, a segmentation fault occurs in the test vector of input length 17 bytes (1 AES block + 1 byte); which is the smallest test vector that requires cipher stealing. At the changed line: - `$input` points at byte 16, i.e. past the first block - `$length` = 1, after [l.2429](https://github.com/aws/aws-lc/blob/v1.48.5/crypto/fipsmodule/aes/asm/aesni-xts-avx512.pl#L2429) - the read index with the diff change is `$input + $length - 18` = `$input -17`, which points at byte "-1", i.e. the byte right before byte 0 of the input, i.e. an underread, this causes a segfault at this vector. - Other larger changes, e.g. -0x20, will have the same result. Another test changes the location of the written output ```@@ -2607,7 +2607,7 @@ ___ .L_done_${rndsuffix}: # store last ciphertext value - vmovdqu %xmm8,-0x10($output) + vmovdqu %xmm8,-0x11($output) ___ } ``` - This test caused a segfault with the smallest input of 1 block = 16 bytes Similar tests in the encrypt path gave the same result of segfaulting when trying to read before the input beginning. 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. (cherry picked from commit a39439b)
nebeid
added a commit
that referenced
this pull request
Apr 22, 2025
…lace SSE instructions that degraded performance for certain input lengths (#2319) Original commits: a39439b and 37c2b5e This is a follow-up to #2228 where an out-of-bound (OOB) read was fixed in the AVX512 implementation of AES-XTS and more tests were added. This cherry-picks: - further hardening tests on checking pre-bound reads #2286 - a fix to a performance glitch on a code path that had an SSE instruction instead of an AVX512 one which was triggered by certain input lengths. #2140 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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issues:
Addresses #V1681992550
Description of changes:
This change hardens the tests introduced in #2227 Fix out-of-bound (OOB) input read in AES-XTS Decrypt in AVX-512 implementation.
It adds a memory page preceding the input and output buffer that is protected against read and write in order to detect any under-read, in which case a segfault occurs.
The suspected code that can potentially cause a "pre-bound" OOB is the cipher-stealing section in Encrypt
crypto/fipsmodule/aes/asm/aesni-xts-avx512.pl#L1809-L1810
and decrypt
crypto/fipsmodule/aes/asm/aesni-xts-avx512.pl#2572-L2573.
Testing:
The efficacy of the added test was shown by changing the decrypt cipher-stealing code for example to:
With this change, a segmentation fault occurs in the test vector of input length 17 bytes (1 AES block + 1 byte); which is the smallest test vector that requires cipher stealing. At the changed line:
$inputpoints at byte 16, i.e. past the first block$length= 1, after l.2429$input + $length - 18=$input -17, which points at byte "-1", i.e. the byte right before byte 0 of the input, i.e. an underread, this causes a segfault at this vector.Another test changes the location of the written output
Similar tests in the encrypt path gave the same result of segfaulting when trying to read before the input beginning.
Call-outs:
N/A
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.