[PATCH] malloc: Make sure tcache_key is not 0
Wilco Dijkstra
Wilco.Dijkstra@arm.com
Fri Aug 1 11:21:26 GMT 2025
Hi Samuel,
>> Basically the assumption for the "key" is that it is not a commonly occurring value
>> in memory. So we should exclude small positive/negative values and anything
>> that doesn't appear random enough to be used (eg. check popcount is between
>> 24 and 40).
>
> So looping around __getrandom_nocancel_nostatus_direct() and
> random_bits(), or only the latter?
I'd suggest only the latter. I don't believe __getrandom is useful at all for this purpose.
It has very limited random data (it always fails when you loop), so using it for
non-essential purposes is a bad idea. It is likely more expensive than random_bits().
My suggestion above would have a reject rate of 7%, so at worst you'll loop a few times.
Cheers,
Wilco
More information about the Libc-alpha
mailing list