From 887a33c6bbeb52fc71cf486759ec22ecbd47a946 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Fri, 15 Jul 2022 19:33:23 +0100 Subject: [PATCH] TODO(gcc): cheri: work around a gcc bug in _dl_setup_stack_chk_guard morello purecap gcc in some cases inlines 16byte memcpy as a capability load, which is wrong if the source or dest may be unaligned. stack guard only needs random for the address portion since only that part is compared, so 8 byte is enough with 64 bit addresses, but the current code is only right on little endian systems. TODO: drop when gcc is fixed --- sysdeps/unix/sysv/linux/dl-osinfo.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sysdeps/unix/sysv/linux/dl-osinfo.h b/sysdeps/unix/sysv/linux/dl-osinfo.h index b4104e05395..c5d864f5ba9 100644 --- a/sysdeps/unix/sysv/linux/dl-osinfo.h +++ b/sysdeps/unix/sysv/linux/dl-osinfo.h @@ -34,7 +34,11 @@ _dl_setup_stack_chk_guard (void *dl_random) /* We need in the moment only 8 bytes on 32-bit platforms and 16 bytes on 64-bit platforms. Therefore we can use the data directly and not use the kernel-provided data to seed a PRNG. */ +#ifdef __CHERI_PURE_CAPABILITY__ + memcpy (ret.bytes, dl_random, 8); +#else memcpy (ret.bytes, dl_random, sizeof (ret)); +#endif #if BYTE_ORDER == LITTLE_ENDIAN ret.num &= ~(uintptr_t) 0xff; #elif BYTE_ORDER == BIG_ENDIAN -- 2.47.2