DynamoRIO / dynamorio

Dynamic Instrumentation Tool Platform
Other
2.61k stars 554 forks source link

os_tls_calloc does not handle alignment parameter correctly #6608

Open egrimley-arm opened 7 months ago

egrimley-arm commented 7 months ago

The function is here: https://github.com/DynamoRIO/dynamorio/blob/95fd0237a5b9c9ca1add88574f9bddca002a82e9/core/unix/os.c#L2507-L2538

If you ask for num_slots > 1 then the implementation wants every slot to be aligned, which fails if the alignment is greater than the size of a slot and succeeds trivially otherwise, so the parameter is useless, I think.

You can fix this, I think, by adding start != -1 || to the start of the condition on the line https://github.com/DynamoRIO/dynamorio/blob/95fd0237a5b9c9ca1add88574f9bddca002a82e9/core/unix/os.c#L2519 so the condition reads: (!client_tls_allocated[i] && (start != -1 || alignment == 0 || ALIGNED(...)))