Skip to content

Conversation

@nebeid
Copy link
Contributor

@nebeid nebeid commented Feb 28, 2025

Original PR: #2227
Cherry-pick eb0c0c0

  • Fix instruction that caused out-of-bound read in the input reading of the 16x loop (which processes a batch of 16 blocks of AES, 1 block = 16 bytes). This was triggered on lengths that are in the range [16k * (16 bytes), (16k +3)* (16 bytes)-1], k = 1, 2, ... The instruction was reading up to 3*16 bytes beyond the input length bound.

  • The fix was inspired by the 8x loop in

    vmovdqu8 0x70($input),%xmm5

  • The existing unit tests cover those cases but there were no explicit memory protections and ASAN doesn't instrument assembly code to check for out-of-bound reads even when the subsequent memory is explicitly poisoned.

Call-outs:

N/A

Testing:

On c6i, without the fix, the unit test segfaults

./crypto/crypto_test "--gtest_filter=XTSTest.*"
Note: Google Test filter = XTSTest.*
[==========] Running 4 tests from 1 test suite.
[----------] Global test environment set-up.
[----------] 4 tests from XTSTest
[ RUN      ] XTSTest.TestVectors
Segmentation fault (core dumped)

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.

…mentation (aws#2227)

- Fix instruction that caused out-of-bound read in the input reading of
the 16x loop (which processes a batch of 16 blocks of AES, 1 block = 16
bytes). This was triggered on lengths that are in the range 
[16*k * (16 bytes), (16*k +3)* (16 bytes)-1], k = 1, 2, ... 
The instruction was reading up to 3*16 bytes beyond the input length bound.

- The fix was inspired by the 8x loop in
https://github.com/aws/aws-lc/blob/becf5785c131012bb5a64f3da6cdb117ddc0f431/crypto/fipsmodule/aes/asm/aesni-xts-avx512.pl#L2544

- The existing unit tests cover those cases but there were no explicit
memory protections and ASAN doesn't instrument assembly code to check
for out-of-bound reads even when the subsequent memory is explicitly
poisoned.
 
### Call-outs:
N/A

### Testing:
On c6i, without the fix, the unit test segfaults
```
./crypto/crypto_test "--gtest_filter=XTSTest.*"
Note: Google Test filter = XTSTest.*
[==========] Running 4 tests from 1 test suite.
[----------] Global test environment set-up.
[----------] 4 tests from XTSTest
[ RUN      ] XTSTest.TestVectors
Segmentation fault (core dumped)
```
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 nebeid requested a review from a team as a code owner February 28, 2025 21:13
@nebeid nebeid requested a review from torben-hansen February 28, 2025 22:48
@nebeid nebeid merged commit 7d3a0cc into aws:fips-2024-09-27 Feb 28, 2025
87 of 110 checks passed
@nebeid nebeid deleted the aes-xts-avx512-fips20240927 branch February 28, 2025 22:55
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants