BLAKE3-team / BLAKE3

the official Rust and C implementations of the BLAKE3 cryptographic hash function
Apache License 2.0
4.71k stars 315 forks source link

AVX512 test failure #392

Closed lulcat closed 1 month ago

lulcat commented 2 months ago

Hi. on a Ryzen 7*** series, if relevant, I got during make -f Makefile.testing test in the c sub-directory:

Testing 0x00000060 AddressSanitizer:DEADLYSIGNAL

==37697==ERROR: AddressSanitizer: SEGV on unknown address (pc 0x64ae1f0fefa4 bp 0x7fff4ee2f970 sp 0x7fff4ee2d200 T0) ==37697==The signal is caused by a READ memory access. ==37697==Hint: this fault was caused by a dereference of a high value address (see register values below). Disassemble the provided pc to learn which register was used.

0 0x64ae1f0fefa4 in blake3_hash16_avx512 (/BLAKE3/c/blake3+0x131fa4) (BuildId: 437efdf9a18d03604553d6113dbee7c8a062baaa)

#1 0x64ae1f12e67f in blake3_hash_many_avx512 (/BLAKE3/c/blake3+0x16167f) (BuildId: 437efdf9a18d03604553d6113dbee7c8a062baaa)
#2 0x64ae1f02e6af in blake3_compress_subtree_wide (/BLAKE3/c/blake3+0x616af) (BuildId: 437efdf9a18d03604553d6113dbee7c8a062baaa)
#3 0x64ae1f036199 in blake3_hasher_update.part.0 (/BLAKE3/c/blake3+0x69199) (BuildId: 437efdf9a18d03604553d6113dbee7c8a062baaa)
#4 0x64ae1f02d3d7 in main (/BLAKE3/c/blake3+0x603d7) (BuildId: 437efdf9a18d03604553d6113dbee7c8a062baaa)
#5 0x730a6d243ccf  (/usr/lib/libc.so.6+0x25ccf) (BuildId: 6542915cee3354fbcf2b3ac5542201faec43b5c9)
#6 0x730a6d243d89 in __libc_start_main (/usr/lib/libc.so.6+0x25d89) (BuildId: 6542915cee3354fbcf2b3ac5542201faec43b5c9)
#7 0x64ae1f02deb4 in _start (/BLAKE3/c/blake3+0x60eb4) (BuildId: 437efdf9a18d03604553d6113dbee7c8a062baaa)

AddressSanitizer can not provide additional info. SUMMARY: AddressSanitizer: SEGV (/BLAKE3/c/blake3+0x131fa4) (BuildId: 437efdf9a18d03604553d6113dbee7c8a062baaa) in blake3_hash16_avx512 ==37697==ABORTING Traceback (most recent call last): File "/BLAKE3/c/./test.py", line 97, in main() File "/BLAKE3/c/./test.py", line 48, in main test_hash = run_blake3([], input) ^^^^^^^^^^^^^^^^^^^^^ File "/BLAKE3/c/./test.py", line 14, in run_blake3 output = subprocess.run([path.join(HERE, "blake3")] + args, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/subprocess.py", line 571, in run raise CalledProcessError(retcode, process.args, subprocess.CalledProcessError: Command '['/BLAKE3/c/./blake3']' returned non-zero exit status 1. make: *** [Makefile.testing:69: test] Error 1

I did not go through any of the .S files, but only one .c file: throwing up the diff in case you want to check/look thorugh, address it. This was first and only attempt at auditing the fix, so upstream needs to verify if the case of exactly 16 left should be in the other condition.

DIFF: (mind you, I don't know how to use web html for formatting is it three backticks for \

 styles?)

diff --git a/c/blake3_avx512.c b/c/blake3_avx512.c
index d6b1ae9..97b19d1 100644
--- a/c/blake3_avx512.c
+++ b/c/blake3_avx512.c
@@ -1177,7 +1177,7 @@ void blake3_hash_many_avx512(const uint8_t *const *inputs, size_t num_inputs,
                              uint64_t counter, bool increment_counter,
                              uint8_t flags, uint8_t flags_start,
                              uint8_t flags_end, uint8_t *out) {
-  while (num_inputs >= 16) {
+  while (num_inputs > 16) {
     blake3_hash16_avx512(inputs, blocks, key, counter, increment_counter, flags,
                          flags_start, flags_end, out);
     if (increment_counter) {
sneves commented 2 months ago

This is caused by this GCC bug.

lulcat commented 2 months ago

Cheers. I usually am on a distant cousin or superset to arch linux although ssp doesn't have to be on/default. Nevertheless, I am on an arch like thing momentarily for a while and it's just so buggy. (endeavour or so). But still, compiler bugs are compiler bugs. I have my fair share of experience of using too experimental versions so I prefer using stable versions now. This fix isn't out yet on this os though but good to know. I'll keep an eye on it. I think I was the first to adopt your blake3 as default into a package manager already just a fortnight after it was released on github. I know, not smart to take something entirely unvetted as a default security wise but blake2 was already held on great regard.

EDIT: this can be closed by the way.