]> git.ipfire.org Git - thirdparty/glibc.git/log
thirdparty/glibc.git
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.

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

memset from arm optimized-routines morello branch.

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

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

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

2 years agoaarch64: morello: purecap rawmemchr
Carlos Eduardo Seo [Mon, 12 Jul 2021 18:06:26 +0000 (15:06 -0300)] 
aarch64: morello: purecap rawmemchr

Modified rawmemchr to support Arm Morello Capabilities.

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

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

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

2 years agoaarch64: morello: string: dummy c strcpy and stpcpy
Szabolcs Nagy [Tue, 26 Apr 2022 07:11:57 +0000 (08:11 +0100)] 
aarch64: morello: string: dummy c strcpy and stpcpy

2 years agoaarch64: morello: string: dummy c strcmp
Szabolcs Nagy [Tue, 26 Apr 2022 07:18:54 +0000 (08:18 +0100)] 
aarch64: morello: string: dummy c strcmp

2 years agoaarch64: morello: string: dummy c strncmp
Szabolcs Nagy [Tue, 15 Mar 2022 14:49:16 +0000 (14:49 +0000)] 
aarch64: morello: string: dummy c strncmp

2 years agoaarch64: morello: string: dummy c strchr
Szabolcs Nagy [Tue, 26 Apr 2022 07:18:43 +0000 (08:18 +0100)] 
aarch64: morello: string: dummy c strchr

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

2 years agoaarch64: morello: string: dummy c strspn
Szabolcs Nagy [Wed, 16 Mar 2022 10:58:57 +0000 (10:58 +0000)] 
aarch64: morello: string: dummy c strspn

avoids out of bound access of the generic implementation.

2 years agoaarch64: morello: string: dummy c strcspn
Szabolcs Nagy [Wed, 16 Mar 2022 10:59:17 +0000 (10:59 +0000)] 
aarch64: morello: string: dummy c strcspn

avoids out of bounds access of the generic implementation.

2 years agoaarch64: morello: update sysdep.h for purecap ABI
Carlos Eduardo Seo [Tue, 18 May 2021 20:24:34 +0000 (17:24 -0300)] 
aarch64: morello: update sysdep.h for purecap ABI

Add macro definitions for purecap ABI in sysdep.h.

2 years agoTODO(gcc): cheri: work around a gcc bug in _dl_setup_stack_chk_guard
Szabolcs Nagy [Fri, 15 Jul 2022 18:33:23 +0000 (19:33 +0100)] 
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

2 years agocheri: __LP64__ is not defined for purecap ABI
Carlos Eduardo Seo [Wed, 26 Jan 2022 19:19:33 +0000 (16:19 -0300)] 
cheri: __LP64__ is not defined for purecap ABI

There is no ideal ABI macro, so we assume __CHERI_PURE_CAPABILITY__
implies 64 bit long, 64 bit address and 128 bit pointer.

2 years agocheri: headers: Define {u}intptr_t and {u}intcap_t for CHERI
Szabolcs Nagy [Fri, 11 Jun 2021 11:52:26 +0000 (12:52 +0100)] 
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.

2 years agoaarch64: morello: use separate c++-types.data
Szabolcs Nagy [Tue, 12 Jul 2022 12:37:15 +0000 (13:37 +0100)] 
aarch64: morello: use separate c++-types.data

The c++ mangling ABI for intptr_t and pthread_t are different on
morello.

2 years agoaarch64: morello: use separate localplt data for morello
Szabolcs Nagy [Tue, 26 Apr 2022 08:09:18 +0000 (09:09 +0100)] 
aarch64: morello: use separate localplt data for morello

There is no longer PLT reference to matherr in libm.

2 years agoaarch64: morello: Add separate lp64 and morello linux abilists
Szabolcs Nagy [Fri, 8 Apr 2022 15:39:40 +0000 (16:39 +0100)] 
aarch64: morello: Add separate lp64 and morello linux abilists

The base symbol version is 2.36.

2 years agoaarch64: morello: Add purecap abi-variants on linux
Szabolcs Nagy [Fri, 8 Apr 2022 15:51:13 +0000 (16:51 +0100)] 
aarch64: morello: Add purecap abi-variants on linux

2 years agoaarch64: morello: configure change for purecap abi
Szabolcs Nagy [Fri, 8 Apr 2022 15:27:01 +0000 (16:27 +0100)] 
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.

2 years agoaarch64: morello: Use separate lp64 and morello sysdep directories
Szabolcs Nagy [Tue, 26 Apr 2022 14:29:04 +0000 (15:29 +0100)] 
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.

2 years agoaarch64: morello: add purecap support to build-many-glibcs.py
Szabolcs Nagy [Mon, 25 Apr 2022 09:52:12 +0000 (10:52 +0100)] 
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.

2 years agoaarch64: Use fewer ifdefs in bits/fcntl.h
Szabolcs Nagy [Fri, 15 Jul 2022 07:42:53 +0000 (08:42 +0100)] 
aarch64: Use fewer ifdefs in bits/fcntl.h

This simplifies adding the Morello purecap abi target.

2 years agoaarch64: cleanup MOVL definition in sysdep.h
Szabolcs Nagy [Wed, 13 Jul 2022 13:48:59 +0000 (14:48 +0100)] 
aarch64: cleanup MOVL definition in sysdep.h

PTR_REG is for ILP32, there is no point using it under __LP64__.

2 years agolibio: adjust _IO_FILE / _IO_FILE_complete for 128 bit pointers
Szabolcs Nagy [Mon, 26 Jul 2021 19:31:38 +0000 (16:31 -0300)] 
libio: adjust _IO_FILE / _IO_FILE_complete for 128 bit pointers

The size of the reserved space has to be adjusted because it underflows
with 16 byte pointers.  With the new value there should be enough space
for 2 more pointers in the struct on CHERI targets.

2 years agostatic: glibc-bug: NL_CURRENT_INDIRECT is broken so disable it
Szabolcs Nagy [Fri, 18 Mar 2022 10:14:58 +0000 (10:14 +0000)] 
static: glibc-bug: NL_CURRENT_INDIRECT is broken so disable it

nl_langinfo_l ignores its locale argument with NL_CURRENT_INDIRECT
which is wrong when that argument does not match the current thread's
locale.

upstream glibc is not tested with static linking so this is not found.

2 years agocheri: Fix elf/tst-dlmodcount test
Szabolcs Nagy [Thu, 14 Apr 2022 17:34:26 +0000 (18:34 +0100)] 
cheri: Fix elf/tst-dlmodcount test

switch statement does not work for intptr_t, use a large int type
that's guaranteed to work.

2 years agoFix stdlib/test-dlclose-exit-race to not hang
Szabolcs Nagy [Wed, 13 Apr 2022 07:18:10 +0000 (08:18 +0100)] 
Fix stdlib/test-dlclose-exit-race to not hang

Use the standard wrapper that kills the test after a timeout.

2 years agoFix resource/bug-ulimit1 test
Szabolcs Nagy [Fri, 6 May 2022 13:19:54 +0000 (14:19 +0100)] 
Fix resource/bug-ulimit1 test

ulimit is a variadic function and the second argument must have type
long (or unsigned long).

2 years agoFix elf/tst-dlmopen-twice to support enough link namespaces
Szabolcs Nagy [Tue, 18 Oct 2022 15:33:52 +0000 (16:33 +0100)] 
Fix elf/tst-dlmopen-twice to support enough link namespaces

The test dlmopens 10 namespaces recursively, which requires a glibc
tunable setting, otherwise it may run out of static TLS.

2 years agoFix missing NUL terminator in stdio-common/scanf13 test
Szabolcs Nagy [Tue, 11 Oct 2022 13:57:16 +0000 (14:57 +0100)] 
Fix missing NUL terminator in stdio-common/scanf13 test

sscanf is only defined on nul terminated string input, but '\0' was
missing in this test which caused _IO_str_init_static_internal to
read OOB on the stack when computing the bounds of the string.

2 years agoFix malloc/tst-scratch_buffer OOB access
Szabolcs Nagy [Tue, 11 Oct 2022 12:23:25 +0000 (13:23 +0100)] 
Fix malloc/tst-scratch_buffer OOB access

The test used scratch_buffer_dupfree incorrectly:

- The passed in size must be <= buf.length.
- Must be called at most once on a buf object since it frees it.
- After it is called buf.data and buf.length must not be accessed.

All of these were violated, the test happened to work because the
buffer was on the stack, which meant the test copied out-of-bounds
bytes from the stack into a new buffer and then compared those bytes.

Run one test and avoid the issues above.

2 years agoFix off-by-one OOB read in elf/tst-tls20
Szabolcs Nagy [Tue, 11 Oct 2022 12:07:59 +0000 (13:07 +0100)] 
Fix off-by-one OOB read in elf/tst-tls20

The int mods[nmods] array on the stack was overread by one.

2 years agoFix off-by-one OOB write in iconv/tst-iconv-mt
Szabolcs Nagy [Mon, 26 Sep 2022 14:38:19 +0000 (15:38 +0100)] 
Fix off-by-one OOB write in iconv/tst-iconv-mt

The iconv buffer sizes must not include the \0 string terminator.

When \0 cannot be part of a valid character encoding glibc iconv
would copy it to the output as expected, but then later the explicit
output termination with *outbufpos = '\0' is out of bounds.

2 years agoUse uintptr_t in string/tester for pointer alignment
Szabolcs Nagy [Mon, 21 Mar 2022 12:36:16 +0000 (12:36 +0000)] 
Use uintptr_t in string/tester for pointer alignment

The code assumed unsigned long can represent pointers.

2 years agoFix the symbolic link of multilib dirs
Szabolcs Nagy [Wed, 8 Jun 2022 13:09:28 +0000 (14:09 +0100)] 
Fix the symbolic link of multilib dirs

If dir contains several / then "ln -s . $dir" does not link it to the
current directory. Use the existing rellns.sh script to compute the
correct relative path to .