spacemeshos / gpu-post

Spacemesh proof of space time gpu optimized setup
GNU General Public License v3.0
29 stars 9 forks source link

Race condition in global `g_spacemesh_api_abort_flag` #79

Open fasmat opened 1 year ago

fasmat commented 1 year ago

g_spacemesh_api_abort_flag (defined here https://github.com/spacemeshos/gpu-post/blob/develop/src/api_internal.cpp#L15) is used as a termination condition to stop calculation of hashes early (e.g. here https://github.com/spacemeshos/gpu-post/blob/develop/src/cuda/driver-cuda.cpp#L220).

This global variable isn't protected from concurrent access, so stopping a running process is inherently unsafe at the moment. This should be fixed by protecting g_spacemesh_api_abort_flag with mutexes.