]> git.ipfire.org Git - thirdparty/glibc.git/log
thirdparty/glibc.git
2 years agomorello README: typo and wording fixes arm/morello/v3
Szabolcs Nagy [Tue, 22 Nov 2022 13:36:29 +0000 (13:36 +0000)] 
morello README: typo and wording fixes

2 years agoaarch64: morello: bump min linux version to 5.18.0
Szabolcs Nagy [Tue, 22 Nov 2022 13:07:16 +0000 (13:07 +0000)] 
aarch64: morello: bump min linux version to 5.18.0

2 years agocheri: Fix pselect signal mask argument
Szabolcs Nagy [Thu, 17 Nov 2022 15:19:10 +0000 (15:19 +0000)] 
cheri: Fix pselect signal mask argument

The signal mask argument is passed as a struct with a pointer and size
in the linux syscall abi, but the types used in glibc were wrong for
CHERI due to an x32 specific hack.

2 years agoRevert "cheri: Fix elf/tst-dlmodcount test"
Szabolcs Nagy [Wed, 16 Nov 2022 14:35:43 +0000 (14:35 +0000)] 
Revert "cheri: Fix elf/tst-dlmodcount test"

This reverts commit 3a69d7f241ab9f738479e039bd6eecf433868375.

2 years agoRevert "cheri: malloc: avoid switch over uintptr_t"
Szabolcs Nagy [Wed, 16 Nov 2022 14:27:41 +0000 (14:27 +0000)] 
Revert "cheri: malloc: avoid switch over uintptr_t"

This reverts commit dc8f9560104f0803e53fa23bfd011aa9878d5a97.

2 years agomorello README update
Szabolcs Nagy [Thu, 3 Nov 2022 15:03:47 +0000 (15:03 +0000)] 
morello README update

2 years agomorello: Provide documentation about the morello port.
Szabolcs Nagy [Wed, 19 Oct 2022 15:08:54 +0000 (16:08 +0100)] 
morello: Provide documentation about the morello port.

2 years agocheri: malloc: disable capability narrowing on some tests
Szabolcs Nagy [Fri, 7 Oct 2022 15:05:29 +0000 (16:05 +0100)] 
cheri: malloc: disable capability narrowing on some tests

malloc/tst-malloc-backtrace tests heap corruption.
malloc/tst-dynarray uses malloc_debug wrappers that access internals.

2 years agocheri: malloc: add tunable to turn narrowing off
Szabolcs Nagy [Thu, 6 Oct 2022 11:00:39 +0000 (12:00 +0100)] 
cheri: malloc: add tunable to turn narrowing off

2 years agocheri: malloc: Capability narrowing using internal lookup table
Szabolcs Nagy [Thu, 29 Sep 2022 16:40:58 +0000 (17:40 +0100)] 
cheri: malloc: Capability narrowing using internal lookup table

Add more cap_ hooks to implement narrowing without depending on a
global capability covering the heap.  Either recording every
narrowed capability in a lookup table or recording every mapping
used for the heap are supported.  The morello implmentation uses
a lookup table for now.

The lookup table adds memory overhead, failure paths and locks.
Recording and removing entries from the lookup table must be done
carefully in realloc so on failure the old pointer is usable and
on success the old pointer is immediately reusable concurrently.
The locks require fork hooks so malloc works in multi-threaded
fork child.

2 years agocheri: malloc: Initial capability narrowing support
Szabolcs Nagy [Wed, 21 Sep 2022 14:32:34 +0000 (15:32 +0100)] 
cheri: malloc: Initial capability narrowing support

Public interfaces return pointers with narrow bounds, this internally
requires bumping the size and alignment requirement of allocations so
the bounds are representible.

When pointers with narrow bounds need to be turned back to have wide
bounds (free, realloc), the pointer is rederived from DDC. (So this
patch relies on DDC to cover all heap memory with RW permission.)

Allocations above the mmap threshold waste memory for alignment and
realloc often falls back to the inefficient alloc, copy, free sequence
instead of mremap or other inplace solution.

2 years agomalloc: Don't use __libc_free for tcache cleanup
Szabolcs Nagy [Mon, 3 Oct 2022 10:58:09 +0000 (11:58 +0100)] 
malloc: Don't use __libc_free for tcache cleanup

__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.

2 years agocheri: use getauxptr in iconv/tst-gconv-init-failure test
Szabolcs Nagy [Tue, 11 Oct 2022 15:24:05 +0000 (16:24 +0100)] 
cheri: use getauxptr in iconv/tst-gconv-init-failure test

On CHERI targets getauxval cannot return a valid pointer.

2 years agocheri: elf: Fix tst-auxv for Morello
Carlos Eduardo Seo [Thu, 23 Jun 2022 18:27:55 +0000 (15:27 -0300)] 
cheri: elf: Fix tst-auxv for Morello

2 years agocheri: Update libc.abilist for getauxptr
Carlos Eduardo Seo [Tue, 12 Jul 2022 20:16:53 +0000 (20:16 +0000)] 
cheri: Update libc.abilist for getauxptr

Updates libc.abilist files for getauxptr to version 2.37.

2 years agoTODO(api): cheri: misc: Implement new function getauxptr for CHERI capabilities
Carlos Eduardo Seo [Wed, 18 May 2022 00:52:09 +0000 (00:52 +0000)] 
TODO(api): cheri: misc: Implement new function getauxptr for CHERI capabilities

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

2 years agosupport: Fix TEST_COMPARE for uintptr_t.
Carlos Eduardo Seo [Mon, 27 Jun 2022 21:27:50 +0000 (21:27 +0000)] 
support: Fix TEST_COMPARE for uintptr_t.

TEST_COMPARE should allow comparison between two capability values.

2 years agocheri: stdio-common: Add test for %#p printf modifier
Carlos Eduardo Seo [Mon, 8 Aug 2022 19:09:37 +0000 (16:09 -0300)] 
cheri: stdio-common: Add test for %#p printf modifier

Testcase for printing capabilities.

2 years agocheri: stdio-common: add support for printing CHERI capabilities
Carlos Eduardo Seo [Thu, 7 Jul 2022 18:46:43 +0000 (18:46 +0000)] 
cheri: stdio-common: add support for printing CHERI capabilities

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.

2 years agocheri: nptl: Check user provided stack for PCS constraints
Carlos Eduardo Seo [Thu, 17 Mar 2022 23:51:32 +0000 (20:51 -0300)] 
cheri: nptl: Check user provided stack for PCS constraints

In pthread_attr_setstack fail with EINVAL if the input stack does not
meet the PCS constraints.

2 years agocheri: Fix sigevent ABI
Szabolcs Nagy [Thu, 16 Jun 2022 14:37:31 +0000 (15:37 +0100)] 
cheri: Fix sigevent ABI

Adjust padding to accommodate pointer size and alignment increase.

2 years agocheri: fix posix timers
Szabolcs Nagy [Tue, 19 Apr 2022 14:18:56 +0000 (15:18 +0100)] 
cheri: fix posix timers

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.

2 years agocheri: elf: make sure dlpi_phdr covers the load segments
Szabolcs Nagy [Wed, 14 Sep 2022 13:04:18 +0000 (14:04 +0100)] 
cheri: elf: make sure dlpi_phdr covers the load segments

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.

2 years agoTODO(api): cheri: fix dl_iterate_phdr dlpi_addr
Szabolcs Nagy [Wed, 7 Sep 2022 16:37:38 +0000 (17:37 +0100)] 
TODO(api): cheri: fix dl_iterate_phdr dlpi_addr

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.

2 years agoTODO(api): cheri: elfptr_t in public api for unwinder
Szabolcs Nagy [Wed, 13 Apr 2022 08:27:08 +0000 (09:27 +0100)] 
TODO(api): cheri: elfptr_t in public api for unwinder

TODO: needs agreement across cheri libcs

2 years agoTODO(uapi): cheri: start: restrict auxv capability permissions
Szabolcs Nagy [Fri, 21 Oct 2022 08:52:47 +0000 (09:52 +0100)] 
TODO(uapi): cheri: start: restrict auxv capability permissions

TODO: not needed with full pcuabi

2 years agocheri: Update the static tls requirement of the libc
Szabolcs Nagy [Tue, 18 Oct 2022 14:10:03 +0000 (15:10 +0100)] 
cheri: Update the static tls requirement of the libc

Larger requirement because pointers are bigger.

2 years agoaarch64: morello: fix DL_SYMBOL_ADDRESS
Szabolcs Nagy [Tue, 6 Sep 2022 13:17:35 +0000 (14:17 +0100)] 
aarch64: morello: fix DL_SYMBOL_ADDRESS

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.

2 years agoaarch64: morello: add D_PTR_RW
Szabolcs Nagy [Thu, 1 Sep 2022 15:43:19 +0000 (16:43 +0100)] 
aarch64: morello: add D_PTR_RW

Writable version of D_PTR, required for updating GOT[1] and GOT[2].

2 years agoaarch64: morello: Return bounded pointer in __tls_get_addr
Szabolcs Nagy [Wed, 7 Sep 2022 13:17:46 +0000 (14:17 +0100)] 
aarch64: morello: Return bounded pointer in __tls_get_addr

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.)

2 years agoaarch64: morello: dynamic linking support
Szabolcs Nagy [Tue, 29 Mar 2022 14:24:38 +0000 (15:24 +0100)] 
aarch64: morello: dynamic linking support

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.

2 years agoaarch64: morello: add lazy binding entry code
Szabolcs Nagy [Fri, 8 Jul 2022 15:35:35 +0000 (16:35 +0100)] 
aarch64: morello: add lazy binding entry code

2 years agocheri: elf: fix SYMBOL_ADDRESS to return RX derived pointer
Szabolcs Nagy [Tue, 6 Sep 2022 08:08:25 +0000 (09:08 +0100)] 
cheri: elf: fix SYMBOL_ADDRESS to return RX derived pointer

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.

2 years agocheri: elf: Use RW permissions for l_ld when needed
Szabolcs Nagy [Fri, 2 Sep 2022 13:07:06 +0000 (14:07 +0100)] 
cheri: elf: Use RW permissions for l_ld when needed

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.)

2 years agocheri: elf: Use elfptr_t for function symbol fixup
Szabolcs Nagy [Thu, 20 Oct 2022 16:27:04 +0000 (17:27 +0100)] 
cheri: elf: Use elfptr_t for function symbol fixup

Propagate capabilities during lazy binding and IFUNC fixup in dlsym.

2 years agocheri: elf: Prepare support for dynamic relocation processing
Szabolcs Nagy [Thu, 20 Oct 2022 16:12:36 +0000 (17:12 +0100)] 
cheri: elf: Prepare support for dynamic relocation processing

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.

2 years agoTODO(sprof): cheri: disable profiling shared libraries
Szabolcs Nagy [Thu, 12 May 2022 08:05:30 +0000 (09:05 +0100)] 
TODO(sprof): cheri: disable profiling shared libraries

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

2 years agoTODO(pldd): cheri: elf: fix pldd to compile for purecap abi
Carlos Eduardo Seo [Tue, 5 Jul 2022 22:09:03 +0000 (22:09 +0000)] 
TODO(pldd): cheri: elf: fix pldd to compile for purecap abi

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).

2 years agoaarch64: morello: add dl-r_debug.h
Szabolcs Nagy [Wed, 14 Sep 2022 10:25:55 +0000 (11:25 +0100)] 
aarch64: morello: add dl-r_debug.h

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.

2 years agoaarch64: elf: avoid loading incompatible binaries
Szabolcs Nagy [Fri, 29 Apr 2022 13:02:17 +0000 (14:02 +0100)] 
aarch64: elf: avoid loading incompatible binaries

Prevent lp64 ld.so loading purecap binaries.

2 years agocheri: elf: use RX, RW capabilities to derive pointers
Szabolcs Nagy [Thu, 7 Apr 2022 16:04:59 +0000 (17:04 +0100)] 
cheri: elf: use RX, RW capabilities to derive pointers

Instead of

  map->l_addr + offset

use

  dl_rx_ptr (map, offset)
  dl_rw_ptr (map, offset)

depending on RX or RW permission requirement.

2 years agocheri: elf: Fix segment mapping permissions
Szabolcs Nagy [Fri, 21 Oct 2022 11:38:26 +0000 (12:38 +0100)] 
cheri: elf: Fix segment mapping permissions

Ensure mmap returns pointers with RWX permission covering all segments.
These pointers later get restricted to RX and RW permission.

2 years agocheri: elf: Setup per module RX and RW capabilities
Szabolcs Nagy [Thu, 7 Apr 2022 07:43:00 +0000 (08:43 +0100)] 
cheri: elf: Setup per module RX and RW capabilities

_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.

2 years agocheri: elf: change l_entry to be elfptr_t
Szabolcs Nagy [Wed, 20 Apr 2022 08:54:31 +0000 (09:54 +0100)] 
cheri: elf: change l_entry to be elfptr_t

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.

2 years agoaarch64: morello: add purecap ld.so _start code
Szabolcs Nagy [Thu, 20 Oct 2022 12:05:19 +0000 (13:05 +0100)] 
aarch64: morello: add purecap ld.so _start code

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).

2 years agoaarch64: morello: rtld: define DL_RO_DYN_SECTION
Szabolcs Nagy [Mon, 4 Apr 2022 16:59:20 +0000 (17:59 +0100)] 
aarch64: morello: rtld: define DL_RO_DYN_SECTION

The dynamic section cannot be relocated to hold pointers in place.

2 years agoaarch64: morello: fix ldconfig for purecap abi
Szabolcs Nagy [Fri, 15 Jul 2022 07:15:02 +0000 (08:15 +0100)] 
aarch64: morello: fix ldconfig for purecap abi

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.

2 years agoaarch64: morello: disable the vpcs test
Szabolcs Nagy [Mon, 1 Mar 2021 11:01:40 +0000 (11:01 +0000)] 
aarch64: morello: disable the vpcs test

The asm code of the test is for lp64 ABI only.

2 years agoaarch64: morello: add purecap ucontext support
Carlos Eduardo Seo [Thu, 27 May 2021 20:49:20 +0000 (17:49 -0300)] 
aarch64: morello: add purecap ucontext support

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.

2 years agoaarch64: morello: add purecap setjmp/longjmp
Carlos Eduardo Seo [Mon, 5 Apr 2021 20:01:09 +0000 (17:01 -0300)] 
aarch64: morello: add purecap setjmp/longjmp

Similar to lp64 setjmp/longjmp, but handles capability registers.
Save q regs instead of d regs to simplify the offset computation.

2 years agocheri: malloc: Ensure the mappings have RW permission
Szabolcs Nagy [Fri, 21 Oct 2022 11:35:33 +0000 (12:35 +0100)] 
cheri: malloc: Ensure the mappings have RW permission

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.

2 years agocheri: malloc: avoid switch over uintptr_t
Szabolcs Nagy [Mon, 28 Mar 2022 12:57:10 +0000 (13:57 +0100)] 
cheri: malloc: avoid switch over uintptr_t

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.

2 years agocheri: malloc: align up without breaking capability in memalign
Szabolcs Nagy [Tue, 15 Mar 2022 09:54:59 +0000 (09:54 +0000)] 
cheri: malloc: align up without breaking capability in memalign

2 years agocheri: malloc: Disable pointer protection
Szabolcs Nagy [Wed, 7 Jul 2021 13:21:40 +0000 (14:21 +0100)] 
cheri: malloc: Disable pointer protection

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.

2 years agocheri: fix invalid pointer use after realloc in localealias
Szabolcs Nagy [Fri, 18 Mar 2022 06:55:31 +0000 (06:55 +0000)] 
cheri: fix invalid pointer use after realloc in localealias

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.

2 years agocheri: fix pointer tagging in tsearch
Szabolcs Nagy [Mon, 12 Jul 2021 10:11:05 +0000 (11:11 +0100)] 
cheri: fix pointer tagging in tsearch

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.

2 years agocheri: fix qsort for capabilities
Szabolcs Nagy [Mon, 12 Jul 2021 12:06:40 +0000 (13:06 +0100)] 
cheri: fix qsort for capabilities

On capability targets avoid copying pointers via unsigned long.

2 years agocheri: wctype: turn wctype_t into a pointer
Szabolcs Nagy [Thu, 17 Mar 2022 12:30:37 +0000 (12:30 +0000)] 
cheri: wctype: turn wctype_t into a pointer

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.

2 years agocheri: rseq: remove const to avoid readonly permission
Szabolcs Nagy [Tue, 1 Mar 2022 09:44:14 +0000 (09:44 +0000)] 
cheri: rseq: remove const to avoid readonly permission

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.)

2 years agocheri: Fix capability permissions of PROT_NONE maps in test code
Szabolcs Nagy [Tue, 25 Oct 2022 08:14:46 +0000 (09:14 +0100)] 
cheri: Fix capability permissions of PROT_NONE maps in test code

2 years agocheri: Fix capability permissions of PROT_NONE map in locarchive
Szabolcs Nagy [Tue, 25 Oct 2022 10:20:48 +0000 (11:20 +0100)] 
cheri: Fix capability permissions of PROT_NONE map in locarchive

2 years agocheri: nptl: Fix thread stack capability permissions
Szabolcs Nagy [Mon, 24 Oct 2022 15:18:42 +0000 (16:18 +0100)] 
cheri: nptl: Fix thread stack capability permissions

2 years agoaarch64: morello: nptl: fix thread pointer setup
Szabolcs Nagy [Wed, 13 Jul 2022 11:15:16 +0000 (12:15 +0100)] 
aarch64: morello: nptl: fix thread pointer setup

2 years agoaarch64: morello: nptl: fix pthread types for 128 bit pointers
Szabolcs Nagy [Wed, 13 Jul 2022 11:22:10 +0000 (12:22 +0100)] 
aarch64: morello: nptl: fix pthread types for 128 bit pointers

2 years agocheri: nptl: fix pthread_attr_t alignment
Szabolcs Nagy [Tue, 12 Jul 2022 12:09:02 +0000 (13:09 +0100)] 
cheri: nptl: fix pthread_attr_t alignment

Alignment of the public definition did not match the internal layout.
Ensure that the type is at least pointer aligned.

2 years agocheri: nptl: fix thread ID types for capabilities
Szabolcs Nagy [Wed, 13 Jul 2022 10:06:49 +0000 (11:06 +0100)] 
cheri: nptl: fix thread ID types for capabilities

2 years agocheri: Implement 128-bit atomics
Szabolcs Nagy [Tue, 8 Jun 2021 11:48:43 +0000 (12:48 +0100)] 
cheri: Implement 128-bit atomics

Arm Morello requires 128-bit atomics.

2 years agocheri: elf: Use elfptr_t in _dl_protect_relro
Szabolcs Nagy [Mon, 21 Jun 2021 09:51:05 +0000 (10:51 +0100)] 
cheri: elf: Use elfptr_t in _dl_protect_relro

Derive the start of the relro area from the RW capability of the dso.

2 years agocheri: fix static linking TLS setup
Carlos Eduardo Seo [Wed, 9 Jun 2021 18:23:23 +0000 (15:23 -0300)] 
cheri: fix static linking TLS setup

Use the per module RW capability to access the TLS initimage.
The bounds are not restricted for now.

2 years agocheri: elf: elfptr_t fixes for preinit/init/fini array
Szabolcs Nagy [Thu, 7 Apr 2022 17:40:25 +0000 (18:40 +0100)] 
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) and
the pointers are derived from the RX pointer of the elf module.

2 years agocheri: Setup RX, RW capabilities for static linking
Szabolcs Nagy [Wed, 7 Sep 2022 09:38:29 +0000 (10:38 +0100)] 
cheri: Setup RX, RW capabilities for static linking

At least tls image access requires RX capability of the main link_map.

2 years agocheri: elf: add dl_{rx,rw}_ptr to derive addresses within a map
Szabolcs Nagy [Mon, 8 Aug 2022 09:56:14 +0000 (10:56 +0100)] 
cheri: elf: add dl_{rx,rw}_ptr to derive addresses within a map

To derive pointers within a module from the per module RX and RW caps.

2 years agocheri: elf: add an RW capability to link_map
Szabolcs Nagy [Mon, 8 Aug 2022 08:22:44 +0000 (09:22 +0100)] 
cheri: elf: add an RW capability to link_map

For each module keep an RX and an RW root capability.  Use the existing
l_map_start for RX (covering all load segments) and add l_rw_start for
RW (covering all writable load segments).

For relocation processing, we also need individual RW ranges to decide
which objects need to be derived from RW and RX capabilities.  In
practice most modules have exactly one RW segment and it's unlikely
that any module needs more than four distinct ranges to tightly cover
the RW mappings.

Only added on CHERI targets so always has to be used behind ifdef.

2 years agocheri: elf: elfptr_t l_map_start in link_map struct
Szabolcs Nagy [Thu, 7 Apr 2022 12:18:48 +0000 (13:18 +0100)] 
cheri: elf: elfptr_t l_map_start in link_map struct

Use a capability for the load segment start that covers all load
segments so pointers can be derived from it.

It should have RX permission and a separate capability used for
writable pointers.

2 years agocheri: Introduce elfptr_t int type that can hold pointers
Szabolcs Nagy [Thu, 20 Oct 2022 11:33:20 +0000 (12:33 +0100)] 
cheri: Introduce elfptr_t int type that can hold pointers

Use elfptr_t when ElfW(Addr) represents a runtime pointer (may be
dereferenced or pointers may be derived from it).

2 years agocheri: fix __minimal_malloc
Szabolcs Nagy [Tue, 1 Mar 2022 12:42:26 +0000 (12:42 +0000)] 
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.

2 years agocheri: fix static linking early allocation
Szabolcs Nagy [Mon, 18 Jul 2022 06:12:56 +0000 (07:12 +0100)] 
cheri: fix static linking early allocation

Store mmap result to intptr_t instead of long.

2 years agocheri: don't use dl_random for pointer mangling
Szabolcs Nagy [Tue, 1 Mar 2022 17:36:12 +0000 (17:36 +0000)] 
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.

2 years agoaarch64: morello: add purecap start code
Szabolcs Nagy [Thu, 20 Oct 2022 11:18:26 +0000 (12:18 +0100)] 
aarch64: morello: add purecap start code

Written in C so the self relocation code in crt1.o is easier to
maintain.

The purecap ELF entry is special: passes separate argc, argv, envp,
auxv in registers instead of on the stack.

For each module there will be separate RW and RX capabilities that
cover the writable and all load segments respectively. The relative
reloc processing code is prepared for such separate capabilities.

The static link detection (for self relocation) is not ideal, it
relies on relocations that don't work in PIC, so it is ifdefed out
for Scrt1.o. (Currently adrp of undefined weak symbol is not fixed
up by the linker to be 0 so we use movz to detect the presence of
__rela_dyn_start.)

2 years agocheri: change __libc_start_main prototype
Szabolcs Nagy [Tue, 30 Aug 2022 09:01:44 +0000 (10:01 +0100)] 
cheri: change __libc_start_main prototype

The prototype of __libc_start_main is changed to

  void
  __libc_start_main (int main (int, char **, char **, void *),
                     int argc, char **argv, char **envp, void *auxv,
                     void rtld_fini (void), void *sp);

so envp is passed down separately and the unused init, fini args are
dropped.

2 years agoaarch64: morello: purecap crti.S and crtn.S
Carlos Eduardo Seo [Thu, 18 Mar 2021 18:02:54 +0000 (15:02 -0300)] 
aarch64: morello: purecap crti.S and crtn.S

Purecap ABI versions of crti.S and crtn.S.

2 years agocheri: aarch64: Add header for CHERI permissions
Carlos Eduardo Seo [Mon, 18 Jul 2022 17:47:32 +0000 (14:47 -0300)] 
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

2 years agocheri: elf: use elfptr_t for auxv parsing
Szabolcs Nagy [Mon, 14 Mar 2022 08:44:32 +0000 (08:44 +0000)] 
cheri: elf: use elfptr_t for auxv parsing

2 years agocheri: elf: Adjust Elf64_auxv_t for capabilities
Szabolcs Nagy [Thu, 10 Jun 2021 12:50:17 +0000 (13:50 +0100)] 
cheri: elf: Adjust Elf64_auxv_t for capabilities

The Elf64_auxv_t needs to be adjusted for the new capability size.

2 years agocheri: elf: Add new AT_* auxv type definitions
Carlos Eduardo Seo [Fri, 20 May 2022 14:39:29 +0000 (14:39 +0000)] 
cheri: elf: Add new AT_* auxv type definitions

Follows the morello pure capability user ABI of linux.

2 years agoelf: add EF_AARCH64_CHERI_PURECAP
Szabolcs Nagy [Fri, 29 Apr 2022 13:27:32 +0000 (14:27 +0100)] 
elf: add EF_AARCH64_CHERI_PURECAP

2 years agoelf: add Arm Morello relocations to elf.h
Carlos Eduardo Seo [Wed, 18 Nov 2020 20:22:25 +0000 (17:22 -0300)] 
elf: add Arm Morello relocations to elf.h

2 years agoTODO(uapi): narrow capability in mmap and mremap
Szabolcs Nagy [Fri, 5 Aug 2022 10:44:57 +0000 (11:44 +0100)] 
TODO(uapi): narrow capability in mmap and mremap

This is a temporary workaround.

length is rounded up to pagesize and don't use exact bound (bounds
will be larger if exact value is not representable).

capability permissions are roughly emulated too.

TODO: kernel should do this

2 years agoTODO(uapi): aarch64: morello: add HWCAP2_MORELLO
Szabolcs Nagy [Wed, 13 Jul 2022 12:49:00 +0000 (13:49 +0100)] 
TODO(uapi): aarch64: morello: add HWCAP2_MORELLO

TODO: this is the value in the 5.18 kernel, will change later.

2 years agoTODO(uapi): aarch64: morello: use non-ifunc gettimeofday
Szabolcs Nagy [Thu, 17 Mar 2022 10:09:46 +0000 (10:09 +0000)] 
TODO(uapi): aarch64: morello: use non-ifunc gettimeofday

TODO: Remove this once morello has vdso gettimeofday.

2 years agoTODO(uapi): aarch64: morello: make brk always fail
Szabolcs Nagy [Thu, 3 Jun 2021 09:05:53 +0000 (10:05 +0100)] 
TODO(uapi): aarch64: morello: make brk always fail

TODO: drop this once linux brk always fails.

2 years agoTODO(uapi): cheri: fix clone_args
Szabolcs Nagy [Mon, 2 Aug 2021 10:34:56 +0000 (11:34 +0100)] 
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.

2 years agoaarch64: morello: define PROT_MAX
Szabolcs Nagy [Fri, 21 Oct 2022 11:10:11 +0000 (12:10 +0100)] 
aarch64: morello: define PROT_MAX

Specifies the prot flags a mapping may gain via mprotect or MAP_FIXED.
On CHERI targets this is used to get capability with more permissions
than the original mmap protection would imply.

2 years agoaarch64: morello: fix missing variadic argument in fcntl
Szabolcs Nagy [Fri, 15 Jul 2022 13:10:53 +0000 (14:10 +0100)] 
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.

2 years agoaarch64: morello: add prctl with correct vararg handling
Szabolcs Nagy [Wed, 26 Oct 2022 09:19:30 +0000 (10:19 +0100)] 
aarch64: morello: add prctl with correct vararg handling

prctl is a variadic function and on morello args that were not passed
cannot be accessed so the generic code does not work.

2 years agoaarch64: morello: fix vfork
Szabolcs Nagy [Tue, 12 Jul 2022 10:13:57 +0000 (11:13 +0100)] 
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.

2 years agoaarch64: morello: add purecap syscall support
Carlos Eduardo Seo [Thu, 8 Apr 2021 15:49:27 +0000 (12:49 -0300)] 
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.

2 years agoaarch64: fix VDSO setup to only apply to known ABIs
Szabolcs Nagy [Wed, 11 May 2022 09:30:36 +0000 (10:30 +0100)] 
aarch64: fix VDSO setup to only apply to known ABIs

New syscall ABI requires different VDSO support code.

2 years agoTODO(api): cheri: fix syscall return type
Szabolcs Nagy [Thu, 14 Jul 2022 13:22:26 +0000 (14:22 +0100)] 
TODO(api): cheri: fix syscall return type

TODO: this affects API (syscall return type is long)
so breaks portability and requires doc updates.

2 years agoaarch64: morello: string: memcpy
Szabolcs Nagy [Tue, 26 Apr 2022 07:19:58 +0000 (08:19 +0100)] 
aarch64: morello: string: memcpy

from arm optimized-routines morello branch.