aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2022-10-27malloc: Don't use __libc_free for tcache cleanupSzabolcs Nagy
__libc_free must only be used for memory given out by __libc_malloc and similar public apis, but tcache stores a cache of already freed pointers and itself is allocated using internal malloc apis. Strong double free detection in __libc_free breaks tcache_thread_shutdown, so use a cut down version of free to reset tcache entries.
2022-10-27cheri: use getauxptr in iconv/tst-gconv-init-failure testSzabolcs Nagy
On CHERI targets getauxval cannot return a valid pointer.
2022-10-27cheri: elf: Fix tst-auxv for MorelloCarlos Eduardo Seo
2022-10-27cheri: Update libc.abilist for getauxptrCarlos Eduardo Seo
Updates libc.abilist files for getauxptr to version 2.37.
2022-10-27TODO(api): cheri: misc: Implement new function getauxptr for CHERI capabilitiesCarlos Eduardo Seo
New function to return values from the auxiliary vector as capabilities. This is the same as implemented by other C libraries. TODO: agree about exact semantics across libcs
2022-10-27support: Fix TEST_COMPARE for uintptr_t.Carlos Eduardo Seo
TEST_COMPARE should allow comparison between two capability values.
2022-10-27cheri: stdio-common: Add test for %#p printf modifierCarlos Eduardo Seo
Testcase for printing capabilities.
2022-10-27cheri: stdio-common: add support for printing CHERI capabilitiesCarlos Eduardo Seo
This adds a new modifier %#p for printing capability information according to the CHERI C Programming guide: https://github.com/CTSRD-CHERI/cheri-c-programming/wiki/Displaying-Capabilities A %#p option in printf will display: <address> [<permissions>,<base>-<top>] (<attr>) * address: Virtual address of capability displayed as a hexadecimal value with a 0x prefix. * permissions: Zero or more of the following characters: r: LOAD permission w: STORE permission x: EXECUTE permission R: LOAD_CAP permission W: STORE_CAP permission E: EXECUTIVE permission (Morello only) * base: Lower bound of capability displayed as a hexadecimal value with a 0x prefix. * top: Upper bound of capability plus 1 displayed as a hexadecimal value with a 0x prefix. * attr: Zero or more of the following comma-separated attributes. If none of the attributes are present, this field is omitted (along with the enclosing parentheses/brackets). invalid: Capability's tag is clear. sentry: Capability is a sealed entry. sealed: Capability is sealed with a type other than the sealed entry object type. A %p option in printf will display the capability value (address) normally.
2022-10-27cheri: nptl: Check user provided stack for PCS constraintsCarlos Eduardo Seo
In pthread_attr_setstack fail with EINVAL if the input stack does not meet the PCS constraints.
2022-10-27cheri: Fix sigevent ABISzabolcs Nagy
Adjust padding to accommodate pointer size and alignment increase.
2022-10-27cheri: fix posix timersSzabolcs Nagy
We need to distinguish timerids that are small integers returned by the kernel and timerids that are pointers to struct timer. The existing pointer tagging does not work for CHERI because of the pointer shift. Simply use the top bit without shift to tag pointers. This still relies on the top byte ignore of aarch64 (the top byte does not affect the capability representation) and that pointers are not tagged for other reasons (like HWASAN). Note: this is morello specific and does not work for generic cheri.
2022-10-27cheri: elf: make sure dlpi_phdr covers the load segmentsSzabolcs Nagy
In dl_iterate_phdr phdr is the only capability passed to the callback that may be used to derive pointers of the elf module, so ensure it has wide bounds.
2022-10-27TODO(api): cheri: fix dl_iterate_phdr dlpi_addrSzabolcs Nagy
The dlpi_addr field is a capability that has value l_addr, but we can only do this for libraries (ET_DYN) where l_addr == l_map_start, otherwise we return l_addr which is normally 0 then (ET_EXEC) so the caller can detect and special case it. For now l_addr != 0 and l_addr != l_map_start case is not supported. Note: this api may be used by the unwinder to find and read .eh_frame data. TODO: dlpi_addr could be address only, but requires unwinder update and agreement about the abi.
2022-10-27TODO(api): cheri: elfptr_t in public api for unwinderSzabolcs Nagy
TODO: needs agreement across cheri libcs
2022-10-27TODO(uapi): cheri: start: restrict auxv capability permissionsSzabolcs Nagy
TODO: not needed with full pcuabi
2022-10-27cheri: Update the static tls requirement of the libcSzabolcs Nagy
Larger requirement because pointers are bigger.
2022-10-27aarch64: morello: fix DL_SYMBOL_ADDRESSSzabolcs Nagy
It has to return a pointer that can be dereferenced, so it must be derived correctly from RX and RW capabilities. Try to have tight object bounds and seal function symbols.
2022-10-27aarch64: morello: add D_PTR_RWSzabolcs Nagy
Writable version of D_PTR, required for updating GOT[1] and GOT[2].
2022-10-27aarch64: morello: Return bounded pointer in __tls_get_addrSzabolcs Nagy
There is no traditional TLS support in morello that would explicitly call __tls_get_addr, but the libc uses it internally and the returned pointer escapes to user code. So bound the pointers according to the tls symbol size instead of doing so in each caller. (Affects dlsym and dynamic TLSDESC.)
2022-10-27aarch64: morello: dynamic linking supportSzabolcs Nagy
Add morello specific dl-machine.h. Add morello dynamic relocation processing support for purecap ABI. Only support R_AARCH64_NONE, R_AARCH64_ABS64 and R_AARCH64_RELATIVE dynamic relocs from the lp64 ABI. RELATIVE and IRELATIVE relocs use a helper function from cheri-rel.h to construct a capability. Also fixed the IRELATIVE handling for static linking. Use new machine routines on morello for load address computation so it is a valid capability: void *elf_machine_runtime_dynamic (void) void elf_machine_rtld_base_setup (struct link_map *map, void *args) The ld.so load address and RX, RW capabilities are derived from auxv and the RW ranges are set up based on the ld.so program headers early. __tls_get_addr should return a bounded pointer instead of fixing it in _dl_make_tlsdesc_dynamic, this is done in a separate patch.
2022-10-27aarch64: morello: add lazy binding entry codeSzabolcs Nagy
2022-10-27cheri: elf: fix SYMBOL_ADDRESS to return RX derived pointerSzabolcs Nagy
All symbol addresses can be derived from the RX capability of the module (l_map_start). For RW object symbols pointer will have to be rederived from l_rw_start.
2022-10-27cheri: elf: Use RW permissions for l_ld when neededSzabolcs Nagy
The dynamic section of an executable needs to be written to set the DT_DEBUG entry for debuggers (unless the target has some other place to store r_debug). For this reason we make l_ld writable whenever the dynamic section is writable. The ld.so l_ld is kept RX, since it does not have DT_DEBUG. (Note: relocating the dynamic section is not allowed on cheri and that's the only other reason glibc would write to it.)
2022-10-27cheri: elf: Use elfptr_t for function symbol fixupSzabolcs Nagy
Propagate capabilities during lazy binding and IFUNC fixup in dlsym.
2022-10-27cheri: elf: Prepare support for dynamic relocation processingSzabolcs Nagy
Type of relocation addresses must be changed from ElfW(Addr) to elfptr_t to cover both traditional and CHERI ABIs. And relative relocation processing must have access to the link_map to derive pointers from the right per module capability.
2022-10-27TODO(sprof): cheri: disable profiling shared librariesSzabolcs Nagy
This is needed now to avoid referencing abort in ld.so. TODO: Fixing shared library profiling for capabilities requires type fixes so capabilities are not stored into shared memory (maybe purecap layout can match the lp64 one and then no file format and external tooling change is required.) TODO: Proper fix also depends on _dl_runtime_profile plt entry
2022-10-27TODO(pldd): cheri: elf: fix pldd to compile for purecap abiCarlos Eduardo Seo
Adjust types in the E(*) structs to support capabilities. TODO: purecap pldd should refuse to deal with lp64 and ELF32 processes. the code for the 32bit case should be disabled. TODO: a correct fix requires support for all abis that can run on the same system (purecap, lp64 and ELF32 too).
2022-10-27aarch64: morello: add dl-r_debug.hSzabolcs Nagy
Used internally for r_debug tests, but with the assumption that the return value can be dereferenced, so change the prototype and return a valid capability. Also used in pldd, where we only support purecap abi processes.
2022-10-27aarch64: elf: avoid loading incompatible binariesSzabolcs Nagy
Prevent lp64 ld.so loading purecap binaries.
2022-10-27cheri: elf: use RX, RW capabilities to derive pointersSzabolcs Nagy
Instead of map->l_addr + offset use dl_rx_ptr (map, offset) dl_rw_ptr (map, offset) depending on RX or RW permission requirement.
2022-10-27cheri: elf: Fix segment mapping permissionsSzabolcs Nagy
Ensure mmap returns pointers with RWX permission covering all segments. These pointers later get restricted to RX and RW permission.
2022-10-27cheri: elf: Setup per module RX and RW capabilitiesSzabolcs Nagy
_dl_map_segments must use capabilities, this required changes beyond the obvious elfptr_t changes: - Ensure map_end is derived from map_start, - Use strict mmap bounds with MAP_FIXED: c->mapend is aligned up to pagesize which may be out of bounds of l_map_start (covering the load segments, but bounds are not aligned up), so use c->dataend instead. Propagate l_map_start and l_rw_start capabilities of ld.so and exe that come from auxv, and ensure they are not recomputed incorrectly by ld.so. The l_rw_range should exclude the relro region, but in libc.so and ld.so this does not work: symbols are accessed before relro is applied and then the permission should be writable.
2022-10-27cheri: elf: change l_entry to be elfptr_tSzabolcs Nagy
It is simpler and more consistent to make l_entry a capability throughout instead of leaving it as an address and converting before use: The AT_ENTRY auxv entry is specified to be a capability and a number if internal l_entry usage is simpler if it is elfptr_t. Functions returning a pointer to the user entry are also changed to use elfptr_t.
2022-10-27aarch64: morello: add purecap ld.so _start codeSzabolcs Nagy
The purecap version of aarch64 dl-start.S. Note: self relocation of ld.so is handled by the rtld bootstrap code. The ldso internal _dl_start still expects continuous argc, argv, envp, auxv, so that's emulated (since the purecap ELF entry passes them in separate registers).
2022-10-27aarch64: morello: rtld: define DL_RO_DYN_SECTIONSzabolcs Nagy
The dynamic section cannot be relocated to hold pointers in place.
2022-10-27aarch64: morello: fix ldconfig for purecap abiSzabolcs Nagy
Add purecap ld cache flag. Add the purecap ld.so name to known names. Handle lib64c system library paths. And set the purecap abi flag on cache entries.
2022-10-27aarch64: morello: disable the vpcs testSzabolcs Nagy
The asm code of the test is for lp64 ABI only.
2022-10-27aarch64: morello: add purecap ucontext supportCarlos Eduardo Seo
Adjust ucontext layout for purecap ABI and add make/get/set/swapcontext implementations accordingly. Note: mcontext layout follows the linux sigcontext struct, in userspace *context functions rely on the c registers stored in the extension area and ignore the mcontext fields for x registers.
2022-10-27aarch64: morello: add purecap setjmp/longjmpCarlos Eduardo Seo
Similar to lp64 setjmp/longjmp, but handles capability registers. Save q regs instead of d regs to simplify the offset computation.
2022-10-27cheri: malloc: Ensure the mappings have RW permissionSzabolcs Nagy
The arena allocator incrementally applies RW mprotect to a PROT_NONE mapping. Use PROT_MAX to ensure the pointers derived from the original mapping have RW capability permission.
2022-10-27cheri: malloc: avoid switch over uintptr_tSzabolcs Nagy
We should use a type that guarantees to represent all address bits. In CHERI C this would be ptraddr_t, but we use unsigned long for now not to cause regressions on other targets where this type is missing.
2022-10-27cheri: malloc: align up without breaking capability in memalignSzabolcs Nagy
2022-10-27cheri: malloc: Disable pointer protectionSzabolcs Nagy
Such arithmetic invalidates capabilities so this security measure does not work for CHERI. Note: the architecture makes it hard to corrupt pointers in malloc metadata, but not impossible: current allocation bounds include the metadata and capabilities are not revoked after free. These issues can be fixed by a capability aware malloc.
2022-10-27cheri: fix invalid pointer use after realloc in localealiasSzabolcs Nagy
This code updates pointers to a reallocated buffer to point to the new buffer. It is not conforming (does arithmetics with freed pointers), but it also creates invalid capabilities because the provenance is derived from the original freed pointers instead of the new buffer. Change the arithmetics so provenance is derived from the new buffer. The conformance issue is not fixed.
2022-10-27cheri: fix pointer tagging in tsearchSzabolcs Nagy
USE_MALLOC_LOW_BIT should work for capabilities too, but we need to ensure that pointer provenance is right: the red/black flag is computed as uintptr_t, but with uintptr_t | uintptr_t it's not clear which side provides the provenance. So use unsigned int type for the flag (which is the type used in case of !USE_MALLOC_LOW_BIT anyway), then unsigned int | uintptr_t works. The type of RED is corrected too to match unsigned int.
2022-10-27cheri: fix qsort for capabilitiesSzabolcs Nagy
On capability targets avoid copying pointers via unsigned long.
2022-10-27cheri: wctype: turn wctype_t into a pointerSzabolcs Nagy
Make wctype_t a pointer so dereferencing it works. wctrans_t is already a pointer and used the same way. Existing targets are not affected, only capability targets where this is necessary.
2022-10-27cheri: rseq: remove const to avoid readonly permissionSzabolcs Nagy
Using const on the definition does not work for a pure capability ABI: the capability permissions when accessing the object will be read only. Use a hack to hide the public declaration in the TU where the const objects are initialized. (This should work on non-capability targets too, but to err on the safe side only enable the hack on capability targets.)
2022-10-27cheri: Fix capability permissions of PROT_NONE maps in test codeSzabolcs Nagy
2022-10-27cheri: Fix capability permissions of PROT_NONE map in locarchiveSzabolcs Nagy