Using arc4random() in the library (was Re: [PATCH] malloc: Use __getrandom_nocancel during tcache initiailization)

Yann Droneaud ydroneaud@opteya.com
Tue Aug 2 09:04:25 GMT 2022


Hi,

Le 01/08/2022 à 12:35, Florian Weimer via Libc-alpha a écrit :
> Cancellation currently cannot happen at this point because dlopen
> as used by the unwind link always performs additional allocations
> for libgcc_s.so.1, even if it has been loaded already as a dependency
> of the main executable.  But it seems prudent not to rely on this
> quirk.
>
> ---
>   malloc/malloc.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/malloc/malloc.c b/malloc/malloc.c
> index bd3c76ed31..430d204156 100644
> --- a/malloc/malloc.c
> +++ b/malloc/malloc.c
> @@ -254,6 +254,7 @@
>   /* For tcache double-free check.  */
>   #include <random-bits.h>
>   #include <sys/random.h>
> +#include <not-cancel.h>
>   
>   /*
>     Debugging:
> @@ -3153,7 +3154,7 @@ static uintptr_t tcache_key;
>   static void
>   tcache_key_initialize (void)
>   {
> -  if (__getrandom (&tcache_key, sizeof(tcache_key), GRND_NONBLOCK)
> +  if (__getrandom_nocancel (&tcache_key, sizeof(tcache_key), GRND_NONBLOCK)


Is this a place where arc4random() could be used in the future ?

aka. is there a policy on using arc4random() instead of getrandom() in 
the library ?


-- 

Yann Droneaud

OPTEYA




More information about the Libc-alpha mailing list