Merge pull request #10945 from okning/backport/3.6-musl-getrandom

Backport 3.6: Fix getrandom detection with musl libc
This commit is contained in:
Gilles Peskine
2026-09-03 16:41:13 +00:00
committed by GitHub
2 changed files with 17 additions and 4 deletions
+5
View File
@@ -0,0 +1,5 @@
Features
* Use the getrandom() system call for PSA crypto initialization on Linux
when supported by the C library, including musl, uClibc and Android
bionic, avoiding unnecessary reliance on /dev/random on Linux 5.6 and
earlier.
+12 -4
View File
@@ -72,10 +72,16 @@ int mbedtls_platform_entropy_poll(void *data, unsigned char *output, size_t len,
/*
* Test for Linux getrandom() support.
* Since there is no wrapper in the libc yet, use the generic syscall wrapper
* available in GNU libc and compatible libc's (eg uClibc).
* Use the generic syscall wrapper when sys/syscall.h is available.
*/
#if ((defined(__linux__) && defined(__GLIBC__)) || defined(__midipix__))
#if defined(__linux__) && defined(__has_include)
#if __has_include(<sys/syscall.h>)
#define MBEDTLS_PLATFORM_HAS_SYS_SYSCALL_H
#endif
#endif
#if defined(MBEDTLS_PLATFORM_HAS_SYS_SYSCALL_H) || \
(defined(__linux__) && defined(__GLIBC__)) || defined(__midipix__)
#include <unistd.h>
#include <sys/syscall.h>
#if defined(SYS_getrandom)
@@ -93,7 +99,9 @@ static int getrandom_wrapper(void *buf, size_t buflen, unsigned int flags)
return (int) syscall(SYS_getrandom, buf, buflen, flags);
}
#endif /* SYS_getrandom */
#endif /* __linux__ || __midipix__ */
#endif /* sys/syscall.h or a known generic syscall wrapper */
#undef MBEDTLS_PLATFORM_HAS_SYS_SYSCALL_H
#if defined(__FreeBSD__) || defined(__DragonFly__)
#include <sys/param.h>