BLAKE2 / libb2

C library providing BLAKE2b, BLAKE2s, BLAKE2bp, BLAKE2sp
Creative Commons Zero v1.0 Universal
132 stars 47 forks source link

Data Race in x86/x64 pointer to function CPU dispatching #39

Open Nick-Kooij opened 1 year ago

Nick-Kooij commented 1 year ago

There is a data race in blake2-dispatch.c x86/x64 pointer to function CPU dispatching.

Internal calls are made through function pointers to functions that initially point to corresponding dispatch function that detects the CPU features available and updates the corresponding pointer to function.

For example blake2b_init_ptr initially points to blake2b_init_dispatch. The data race is the blake2b_init_ptr pointer update:

int blake2b_init_dispatch( blake2b_state *S, size_t outlen )
{
  /* data race, non-atomic write to blake2b_init_ptr */
  blake2b_init_ptr = blake2b_init_table[get_cpu_features()]; /*
  return blake2b_init_ptr( S, outlen );
}

*All `_dispatch` functions are likewise affected:**