RFR: 8330611: AES-CTR vector intrinsic may read out of bounds (x86_64, AVX-512)

Sandhya Viswanathan sviswanathan at openjdk.org
Fri Apr 19 20:21:33 UTC 2024


On Fri, 19 Apr 2024 00:04:41 GMT, Martin Balao <mbalao at openjdk.org> wrote:

> We would like to propose a fix for 8330611.
> 
> To avoid an out of bounds memory read when the input's size is not multiple of the block size, we read the plaintext/ciphertext tail in 8, 4, 2 and 1 byte batches depending on what it is guaranteed to be available by 'len_reg'. This behavior replaces the read of 16 bytes of input upfront and later discard of spurious data.
> 
> While we add 3 extra instructions + 3 extra memory reads in the worst case —to the same cache line probably—, the performance impact of this fix should be low because it only occurs at the end of the input and when its length is not multiple of the block size.
> 
> A reliable test case for this bug is hard to develop because we would need accurate heap allocation. The fact that spuriously read data is silently discarded most of the time makes this bug harder to observe. No regressions have been observed in the compiler/codegen/aes jtreg category. Additionally, we verified the fix manually with the debugger.
> 
> This work is in collaboration with @franferrax .

src/hotspot/cpu/x86/stubGenerator_x86_64_aes.cpp line 2618:

> 2616:   __ movdqu(Address(saved_encCounter_start, 0), xmm0);
> 2617:   // XOR encryted block cipher in xmm0 with PT to produce CT
> 2618:   __ evpxorq(xmm0, xmm0, Address(src_addr, pos, Address::times_1, 0), Assembler::AVX_128bit);

This could be fixed alternatively by using mask register with evpxorq. That will have lower impact on performance. @smita-kamath can share the changes needed.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/18849#discussion_r1572908603


More information about the hotspot-compiler-dev mailing list