[PATCH] malloc: Fix clobbered errno when getrandom failed [BZ #29624]

Yu Chien Peter Lin peterlin@andestech.com
Thu Sep 29 08:33:52 GMT 2022


The patch resets errno when getrandom syscall failed, which will
result in errno clobbered at statically linked program startup. This
scenario is possible if getrandom is called by tcache_key_initialize
when crng is not ready thus EAGAIN is returned.

Fixes bug 29624.

Signed-off-by: Yu Chien Peter Lin <peterlin@andestech.com>
---
 malloc/malloc.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/malloc/malloc.c b/malloc/malloc.c
index 953183e956..21f2bf5431 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -3140,6 +3140,7 @@ tcache_key_initialize (void)
 #if __WORDSIZE == 64
       tcache_key = (tcache_key << 32) | random_bits ();
 #endif
+      __set_errno(0);
     }
 }
 
-- 
2.34.1



More information about the Libc-alpha mailing list