[PATCH] Harden tcache double-free check
Siddhesh Poyarekar
siddhesh@sourceware.org
Wed Jul 7 17:58:54 GMT 2021
On 7/7/21 11:05 PM, Adhemerval Zanella via Libc-alpha wrote:
>
>
> On 06/07/2021 22:29, Siddhesh Poyarekar via Libc-alpha wrote:
>
>> +/* Process-wide key to try and catch a double-free in the same thread. */
>> +static uintptr_t tcache_key;
>> +
>> +/* The value of tcache_key does not really have to be a cryptographically
>> + secure random number. It only needs to be arbitrary enough so that it does
>> + not collide with values present in applications, which would be quite rare,
>> + about 1 in 2^wordsize. */
>> +static void
>> +tcache_key_initialize (void)
>> +{
>> + if (__getrandom (&tcache_key, sizeof(tcache_key), GRND_NONBLOCK)
>> + != sizeof (tcache_key))
>> + {
>> + tcache_key = random_bits ();
>> +#if __WORDSIZE == 64
>> + tcache_key = (tcache_key << 32) | random_bits ();
>> +#endif
>
> The other usage for ramdom_bits at sysdeps/posix/tempname.c already uses
tempname.c seems to have its own random_bits function (i.e. it just
happens to have the same name); it doesn't use the one in random_bits.h
AFAICT. All other users of random_bits() use 32-bit. Entropy isn't
really a concern in the above use case, it's just a key to avoid collisions.
Siddhesh
More information about the Libc-alpha
mailing list