[PATCH] aarch64: Fail early if malloc ifunc resolver is called incorrectly
Yury Khrustalev
yury.khrustalev@arm.com
Wed Jul 1 13:16:17 GMT 2026
This patch adds simple check that validates the call to ifunc resolver
for the malloc function. If resolver is called correctly, it must
receive at least 1 argument that is equal to the value of AT_HWCAP
with bit _IFUNC_ARG_HWCAP possibly set as well (see [1]).
If the value of the argument passed to the ifunc resolver is not equal
to the value of AT_HWCAP, we abort with an error message.
[1] https://github.com/ARM-software/abi-aa/blob/main/sysvabi64/sysvabi64.rst
---
Base commit: 84c3993f1f
---
sysdeps/aarch64/multiarch/malloc-ifuncs.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/sysdeps/aarch64/multiarch/malloc-ifuncs.c b/sysdeps/aarch64/multiarch/malloc-ifuncs.c
index 648fb617de..07e05f83cd 100644
--- a/sysdeps/aarch64/multiarch/malloc-ifuncs.c
+++ b/sysdeps/aarch64/multiarch/malloc-ifuncs.c
@@ -22,8 +22,19 @@
#include <malloc-api.h>
#include <shlib-compat.h>
-libc_ifunc_hidden (__libc_malloc, __libc_malloc_redirect,
- __libc_malloc)
+#include <sys/ifunc.h>
+
+static __attribute__ ((noreturn))
+void *(*__bad_ifunc_call (uint64_t arg0)) (size_t)
+{
+ _dl_fatal_printf ("ifunc resolver: incorrect argument: %ld\n", arg0);
+}
+
+__ifunc_hidden (__libc_malloc, __libc_malloc_redirect,
+ ((arg0 & ~_IFUNC_ARG_HWCAP) == GLRO (dl_hwcap))
+ ? __libc_malloc
+ : __bad_ifunc_call (arg0),
+ uint64_t arg0, INIT_ARCH)
strong_alias (__libc_malloc_redirect, malloc)
libc_ifunc_hidden (__libc_calloc, __libc_calloc_redirect,
--
2.47.3
More information about the Libc-alpha
mailing list