]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
TODO(gcc): cheri: work around a gcc bug in _dl_setup_stack_chk_guard
authorSzabolcs Nagy <szabolcs.nagy@arm.com>
Fri, 15 Jul 2022 18:33:23 +0000 (19:33 +0100)
committerSzabolcs Nagy <szabolcs.nagy@arm.com>
Thu, 27 Oct 2022 13:46:49 +0000 (14:46 +0100)
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

index 7888915f12ed44f52fad5829966f790a981bab34..49d8f973c81213307a668e4d3cb9b55f8f2bc984 100644 (file)
@@ -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