Commit Graph

39177 Commits

Author SHA1 Message Date
Szabolcs Nagy
d63bc8be87 cheri: elf: elfptr_t fixes for preinit/init/fini array
According to the ELF spec:

 "Each element of this array is a pointer to a function to be executed
  by the dynamic linker."

 "Note that the address of a function need not be the same as a pointer
  to a function as defined by the processor supplement."

so these should be accessed via uintptr_t type instead of ElfW(Addr).
2022-08-05 19:45:19 +01:00
Szabolcs Nagy
d257d001c3 TODO(l_addr): cheri: in static exe initialize l_addr to a zero capability
The base should be 0, but also a valid capability. Initialize to a zero
capability instead of relying on AT_BASE.

TODO: this is a hack. we will need stricter bounds and possibly separate
l_addr and bounds info.
2022-08-05 19:45:19 +01:00
Szabolcs Nagy
8536404f41 cheri: elf: use elfptr_t for auxv parsing 2022-08-05 19:45:19 +01:00
Szabolcs Nagy
8022e6934e cheri: elf: Adjust Elf64_auxv_t for capabilities
The Elf64_auxv_t needs to be adjusted for the new capability size.
2022-08-05 19:45:19 +01:00
Szabolcs Nagy
a4f02d3f68 cheri: elf: make l_addr a capability
l_addr should be a capability on Morello. This is synchronized with the
same variable in gdb.

Use elfptr_t when ElfW(Addr) represents a runtime pointer that may be
dereferenced.
2022-08-05 19:45:19 +01:00
Carlos Eduardo Seo
091bcf0e1c cheri: elf: Add new a_type entries
The Morello Pure Capability kernel uABI defines new a_type entries:

https://git.morello-project.org/morello/kernel/linux/-/wikis/Morello-pure-capability-kernel-user-Linux-ABI-specification#auxiliary-vector-auxv
2022-08-05 19:45:19 +01:00
Szabolcs Nagy
823a9cb203 elf: add EF_AARCH64_CHERI_PURECAP 2022-08-05 19:45:19 +01:00
Carlos Eduardo Seo
bb5bc76947 elf: add Arm Morello relocations to elf.h 2022-08-05 19:45:19 +01:00
Szabolcs Nagy
110733491a cheri: fix __minimal_malloc
The linker created _end symbol does not have the right bounds, so
don't try to reuse leftover memory at the end of the .data section.
2022-08-05 19:45:19 +01:00
Carlos Eduardo Seo
4275aff6b8 cheri: fix static linking TLS setup
Use l_addr provenance for TLS initimage.
2022-08-05 19:45:19 +01:00
Szabolcs Nagy
cb79f5073a cheri: fix static linking early allocation
Store mmap result to intptr_t instead of long.
2022-08-05 19:45:19 +01:00
Szabolcs Nagy
887a33c6bb 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
2022-08-05 19:45:19 +01:00
Szabolcs Nagy
ff2cd89ebb cheri: don't use dl_random for pointer mangling
Pointer mangling cannot be supported on capability architectures.
And there is not enough bytes in dl_random for 128 bit pointers.

Stack guard is still loaded from dl_random: stack protection is
unlikely to be useful on a capability architecture, but it works.
2022-08-05 19:45:19 +01:00
Szabolcs Nagy
347f7e2ac1 TODO(relro): cheri: make __attribute_relro a nop
relro does not work in the libc, because capabilities are readonly
even before the page protection is applied.
2022-08-05 19:45:19 +01:00
Carlos Eduardo Seo
d77736297a TODO(ddc): aarch64: morello: purecap support in the CSU
Purecap ABI versions of start.S, crti.S and crtn.S.

TODO: must not use ddc but caps from auxv
TODO: start.S: dynamic linked case is now detected by x0 != 0 (ld.so passes
__rtld_fini there), but the value of c0 on entry is not abi, just that
it has to be passed back to the libc start code in c5, so ideally the
linker should be fixed to reliably emit __rela_dyn_start when a static
exe must self relocate.
2022-08-05 19:45:19 +01:00
Carlos Eduardo Seo
2d0278e6d7 cheri: aarch64: Add header for CHERI permissions
New file containing the capability permission bits.

The capability permission bits are defined in the Arm Architecture
Reference Manual Suplement- Morello for A-Profile Architecture:

https://developer.arm.com/documentation/ddi0606/latest
2022-08-05 19:45:19 +01:00
Szabolcs Nagy
822571c5b1 TODO(uapi): aarch64: morello: use non-ifunc gettimeofday
TODO: Remove this once morello has vdso gettimeofday.
2022-08-05 19:45:19 +01:00
Szabolcs Nagy
9f92fe592b TODO(uapi): aarch64: morello: make brk always fail
TODO: drop this once linux brk always fails.
2022-08-05 19:45:19 +01:00
Szabolcs Nagy
fb41a562bf TODO(uapi): cheri: fix clone_args
Current clone_args does not support 128 bit pointers.

TODO: the fix is incomplete (missing clone3 abi checks) and has to be
aligned with purecap clone3 struct layout.
2022-08-05 19:45:19 +01:00
Szabolcs Nagy
ed90470cc0 aarch64: morello: fix missing variadic argument in fcntl
In fcntl va_arg is currently used even if the caller did not pass
any variadic arguments. This is undefined behaviour and does not
work with the Morello purecap ABI, so use a helper macro.

When the argument is missing, the result of the helper macro is
arbitrary as it will be ignored by the kernel, we just have to
ensure it does not cause a runtime crash.
2022-08-05 19:45:19 +01:00
Szabolcs Nagy
d23dfc0324 aarch64: morello: fix vfork
No need to set the child stack to sp, 0 means the parent stack is used.
This avoids purecap specific ifdefs in vfork.
2022-08-05 19:45:19 +01:00
Carlos Eduardo Seo
ff371935db aarch64: morello: add purecap syscall support
Support the Morello Linux purecap syscall ABI.  The macro definitions
are moved to a morello specific sysdep.h to avoid cluttering the
aarch64 one.
2022-08-05 19:45:19 +01:00
Szabolcs Nagy
9ef71c0be0 aarch64: fix VDSO setup to only apply to known ABIs
New syscall ABI requires different VDSO support code.
2022-08-05 19:45:19 +01:00
Szabolcs Nagy
2d17978865 TODO(api): cheri: fix syscall return type
TODO: this affects API (syscall return type is long)
so breaks portability and requires doc updates.
2022-08-05 19:45:19 +01:00
Szabolcs Nagy
fbdd679dfe aarch64: morello: string: memcpy
from arm optimized-routines morello branch.
2022-08-05 19:45:19 +01:00
Szabolcs Nagy
dd44f97920 aarch64: morello: string: memset
memset from arm optimized-routines morello branch.
2022-08-05 19:45:19 +01:00
Szabolcs Nagy
30d6fef4c7 aarch64: morello: string: dummy c memcmp 2022-08-05 19:45:19 +01:00
Szabolcs Nagy
05c7fd2959 aarch64: morello: string: dummy c memchr 2022-08-05 19:45:19 +01:00
Szabolcs Nagy
df91141390 aarch64: morello: string: dummy c memrchr 2022-08-05 19:45:19 +01:00
Carlos Eduardo Seo
2e1fc3bdee aarch64: morello: purecap rawmemchr
Modified rawmemchr to support Arm Morello Capabilities.
2022-08-05 19:45:19 +01:00
Szabolcs Nagy
0ae704caef aarch64: morello: string: dummy c strchrnul 2022-08-05 19:45:19 +01:00
Szabolcs Nagy
538a80eaf4 aarch64: morello: string: dummy c strlen 2022-08-05 19:45:19 +01:00
Szabolcs Nagy
42ab155048 aarch64: morello: string: dummy c strnlen 2022-08-05 19:45:19 +01:00
Szabolcs Nagy
424b0ffa6f aarch64: morello: string: dummy c strcpy and stpcpy 2022-08-05 19:45:19 +01:00
Szabolcs Nagy
bec24b66e8 aarch64: morello: string: dummy c strcmp 2022-08-05 19:45:19 +01:00
Szabolcs Nagy
d496a3dd55 aarch64: morello: string: dummy c strncmp 2022-08-05 19:45:19 +01:00
Szabolcs Nagy
750a8bb78b aarch64: morello: string: dummy c strchr 2022-08-05 19:45:19 +01:00
Szabolcs Nagy
3a0ce7aeb0 aarch64: morello: string: dummy c strrchr 2022-08-05 19:45:19 +01:00
Szabolcs Nagy
eca95865e3 aarch64: morello: string: dummy c strspn
avoids out of bound access of the generic implementation.
2022-08-05 19:45:19 +01:00
Szabolcs Nagy
e8728f756a aarch64: morello: string: dummy c strcspn
avoids out of bounds access of the generic implementation.
2022-08-05 19:45:19 +01:00
Carlos Eduardo Seo
db037e48fb aarch64: morello: update sysdep.h for purecap ABI
Add macro definitions for purecap ABI in sysdep.h.
2022-08-05 19:45:19 +01:00
Carlos Eduardo Seo
434271f132 TODO(spec): cheri: __LP64__ is not defined for purecap ABI
TODO: there is no good ABI macro to check, for now we assume
__CHERI_PURE_CAPABILITY__ implies 64 bit long, 64 bit address and
128 bit pointer.
2022-08-05 19:45:19 +01:00
Szabolcs Nagy
93c5545300 cheri: headers: Define {u}intptr_t and {u}intcap_t for CHERI
The CHERI pure capability programming model for C requires special
definition of {u}intptr_t.

Only the pure capability model is supported for hosted compilation,
but for freestanding compilation there is limited support for other
(hybrid capability) programming models too, which require new
{u}intcap_t type definitions.
2022-08-05 19:45:19 +01:00
Szabolcs Nagy
77777d453d aarch64: morello: use separate c++-types.data
The c++ mangling ABI for intptr_t and pthread_t are different on
morello.
2022-08-05 19:45:19 +01:00
Szabolcs Nagy
78cc285037 aarch64: morello: use separate localplt data for morello
There is no longer PLT reference to matherr in libm.
2022-08-05 19:45:19 +01:00
Szabolcs Nagy
ccec84f408 aarch64: morello: Add separate lp64 and morello linux abilists
The base symbol version is 2.36.
2022-08-05 19:45:19 +01:00
Szabolcs Nagy
9e6811dafb aarch64: morello: Add purecap abi-variants on linux 2022-08-05 19:45:19 +01:00
Szabolcs Nagy
18fb025070 aarch64: morello: configure change for purecap abi
Detect default-abi and add aarch64-purecap make variable.

Purecap abi sets HIDDEN_VAR_NEEDS_DYNAMIC_RELOC and unsets
SUPPORT_STATIC_PIE.
2022-08-05 19:45:19 +01:00
Szabolcs Nagy
4fc4072240 aarch64: morello: Use separate lp64 and morello sysdep directories
Provide separate directories for lp64 and purecap abi related sysdep
functionality.

purecap may be better name than morello, but we started with morello
and that is more future compatible with alternative cheri-like
extensions on top of aarch64.
2022-08-05 19:45:19 +01:00
Szabolcs Nagy
570f6858b7 aarch64: morello: add purecap support to build-many-glibcs.py
aarch64-linux-gnu compiler is a lp64,purecap multilib gcc and
supported glibc variants:

  aarch64-linux-gnu
  aarch64-linux-gnu-purecap
  aarch64-linux-gnu-purecap-nopie

aarch64-linux-gnu_purecap compiler is a default purecap gcc, with
supported glibc variants:

  aarch64-linux-gnu_purecap
  aarch64-linux-gnu_purecap-nopie

purecap libgomp and libitm builds fail so disabled for now.
2022-08-05 19:45:19 +01:00