]> git.ipfire.org Git - thirdparty/glibc.git/log
thirdparty/glibc.git
2 years agocheri: stdio-common: Add test for %#p printf modifier arm/morello/v2
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 agoFix elf/tst-tls20 stack OOB access
Szabolcs Nagy [Tue, 11 Oct 2022 12:07:59 +0000 (13:07 +0100)] 
Fix elf/tst-tls20 stack OOB access

Off-by-one error found on morello with strict stack bounds.

2 years agoRevert "Fix elf/tst-tls20 stack OOB access"
Szabolcs Nagy [Wed, 26 Oct 2022 08:25:36 +0000 (09:25 +0100)] 
Revert "Fix elf/tst-tls20 stack OOB access"

This reverts commit 37cfa707b08a6d8c060d7fdebf2cc255e1de8908.

2 years agoTODO: fix _dl_runtime_profile entry after revert
Szabolcs Nagy [Fri, 21 Oct 2022 14:46:42 +0000 (15:46 +0100)] 
TODO: fix _dl_runtime_profile entry after revert

TODO: squash into

  commit 392f32c841c9feefdc376129d2ac2215855decc4
  aarch64: morello: add lazy binding entry code

2 years agoRevert "TODO(audit): aarch64: morello: add _dl_runtime_profile entry"
Szabolcs Nagy [Fri, 21 Oct 2022 14:44:36 +0000 (15:44 +0100)] 
Revert "TODO(audit): aarch64: morello: add _dl_runtime_profile entry"

This reverts commit 0c66b05c7f0b2ec5fdf7d37b4150ba517efa5df8.

2 years agoRevert "TODO(gprof): aarch64: morello: add gprof profiling support to asm"
Szabolcs Nagy [Fri, 21 Oct 2022 14:43:44 +0000 (15:43 +0100)] 
Revert "TODO(gprof): aarch64: morello: add gprof profiling support to asm"

This reverts commit 960401b6f740232d2b97bfe9ea4118b394112a5e.

2 years agoRevert "TODO(drop): aarch64: morello: CPU feature detection for Morello"
Szabolcs Nagy [Fri, 21 Oct 2022 14:41:13 +0000 (15:41 +0100)] 
Revert "TODO(drop): aarch64: morello: CPU feature detection for Morello"

This reverts commit 078ebf3e35bd0c50b58dc2ec796530054f69b9a9.

2 years agoRevert "TODO(relro): cheri: make __attribute_relro a nop"
Szabolcs Nagy [Fri, 21 Oct 2022 14:38:35 +0000 (15:38 +0100)] 
Revert "TODO(relro): cheri: make __attribute_relro a nop"

This reverts commit 347f7e2ac1f34f92bc382afe9e5fe32ebe7cf16c.

2 years agoRevert "TODO(l_addr): cheri: rtld: elfptr_t fix in rtld.c program header processing"
Szabolcs Nagy [Fri, 21 Oct 2022 14:37:29 +0000 (15:37 +0100)] 
Revert "TODO(l_addr): cheri: rtld: elfptr_t fix in rtld.c program header processing"

This reverts commit 93ab84cd80067744fb990d0f420dafc04a18d4cb.

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 agoTODO: fix variadic syscalls
Szabolcs Nagy [Tue, 25 Oct 2022 12:10:54 +0000 (13:10 +0100)] 
TODO: fix variadic syscalls

Only use as many varargs as accessible according to the bounds of c9.

TODO: squash into original syscall support

2 years agoTODO: use empty dl-symaddr.c
Szabolcs Nagy [Fri, 21 Oct 2022 15:27:33 +0000 (16:27 +0100)] 
TODO: use empty dl-symaddr.c

TODO: squash into

  commit 0edbd4c6d389b9e2be5ff1d026b4d30ae70a4af9
  aarch64: morello: fix DL_SYMBOL_ADDRESS

2 years agoTODO: use empty wordcopy.c
Szabolcs Nagy [Fri, 21 Oct 2022 15:27:10 +0000 (16:27 +0100)] 
TODO: use empty wordcopy.c

TODO: squash into

  commit 418b9dac8999e5a64b69ee072321cd6eed8d8be1
  aarch64: don't build wordcopy

2 years agoTODO: more l_addr cleanup
Szabolcs Nagy [Fri, 21 Oct 2022 14:51:49 +0000 (15:51 +0100)] 
TODO: more l_addr cleanup

TODO: squash into

  commit f2f4f441fbda6080d0ff742f3bb535c09315ef98
  cheri: elf: Turn l_addr back to ElfW(Addr)

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: 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 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: 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 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 agoTODO(uapi): mmap perm emulation
Szabolcs Nagy [Mon, 24 Oct 2022 14:29:58 +0000 (15:29 +0100)] 
TODO(uapi): mmap perm emulation

2 years agoTODO: update cheri_perms.h
Szabolcs Nagy [Mon, 24 Oct 2022 10:53:56 +0000 (11:53 +0100)] 
TODO: update cheri_perms.h

TODO: squash into initial cheri_perms.h

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 agomath: Fix asin and acos invalid exception
Szabolcs Nagy [Thu, 13 Oct 2022 10:10:10 +0000 (11:10 +0100)] 
math: Fix asin and acos invalid exception

This works around a gcc issue where it const folds inf/inf into nan,
preventing the invalid exception signal to be raised.

(x-x)/(x-x) is more robust against optimizations and works for x==nan
too.

The issue should be fixed in gcc-11.3.0 and gcc-12, but glibc supports
older compilers.

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: 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 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 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 agoaarch64: morello: elf: drop unused load address computation
Szabolcs Nagy [Thu, 8 Sep 2022 13:57:20 +0000 (14:57 +0100)] 
aarch64: morello: elf: drop unused load address computation

l_addr is no longer a capability so this is not needed.

2 years agocheri: elf: Turn l_addr back to ElfW(Addr)
Szabolcs Nagy [Wed, 7 Sep 2022 15:45:18 +0000 (16:45 +0100)] 
cheri: elf: Turn l_addr back to ElfW(Addr)

Pointers are no longer derived from l_addr, but l_map_start (RX) and
l_rw_start (RW) so it does not have to be a capability.

This also allows removing hacks where l_addr was derived from DDC.

2 years agocheri: elf: use RX, RW capabilities to derive pointers
Szabolcs Nagy [Mon, 8 Aug 2022 12:03:57 +0000 (13:03 +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 agoaarch64: morello: RX, RW fixes for relocation processing
Szabolcs Nagy [Fri, 2 Sep 2022 13:57:03 +0000 (14:57 +0100)] 
aarch64: morello: RX, RW fixes for relocation processing

2 years agoaarch64: morello: elf: Return bounded pointer in __tls_get_addr
Szabolcs Nagy [Wed, 7 Sep 2022 13:17:46 +0000 (14:17 +0100)] 
aarch64: morello: elf: 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: 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 agocheri: fix SYMBOL_ADDRESS to return RX derived pointer
Szabolcs Nagy [Tue, 6 Sep 2022 08:08:25 +0000 (09:08 +0100)] 
cheri: 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 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: fix relative relocs
Szabolcs Nagy [Wed, 31 Aug 2022 15:37:40 +0000 (16:37 +0100)] 
aarch64: morello: fix relative relocs

use the reloc processing code from cheri-rel.h which already
supports separate RX and RW capabilities per 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: Setup per module RX and RW capabilities
Szabolcs Nagy [Thu, 1 Sep 2022 08:45:30 +0000 (09:45 +0100)] 
cheri: elf: Setup per module RX and RW capabilities

The l_map_start and l_rw_start of the ld.so and exe comes from the auxv
since they are normally mapped by the kernel.  Some generic code had to
be modified so l_map_start is propagated and not overwritten when it is
recomputed.

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 agoaarch64: morello: Add elf_machine_rtld_base_setup
Szabolcs Nagy [Mon, 8 Aug 2022 10:29:21 +0000 (11:29 +0100)] 
aarch64: morello: Add elf_machine_rtld_base_setup

Use a new hook to do the rtld bootstrap map base address and root
capability setup on CHERI.

This will be needed to use separate per module RX and RW root caps.

2 years agoelf: add dl_{rx,rw}_ptr to derive addresses within a map
Szabolcs Nagy [Mon, 8 Aug 2022 09:56:14 +0000 (10:56 +0100)] 
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 agoaarch64: morello: Use purecap ELF entry ABI in _start
Szabolcs Nagy [Wed, 31 Aug 2022 10:26:46 +0000 (11:26 +0100)] 
aarch64: morello: Use purecap ELF entry ABI in _start

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

The ldso internal _dl_start still expects continuous argc, argv, envp,
auxv, so that's emulated.

2 years agoaarch64: morello: use RW and RX capabilities for static start code
Szabolcs Nagy [Tue, 30 Aug 2022 15:00:57 +0000 (16:00 +0100)] 
aarch64: morello: use RW and RX capabilities for static start code

For each module there will be separate RW and RX capabilities that
cover the writable and all load segments respectively.

Prepare the relative reloc processing in static start code for such
separate capabilities.

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: rewrite start code in C
Szabolcs Nagy [Fri, 26 Aug 2022 08:06:27 +0000 (09:06 +0100)] 
aarch64: morello: rewrite start code in C

2 years agoaarch64: morello: remove ELF_MACHINE_START_ADDRESS
Szabolcs Nagy [Wed, 7 Sep 2022 14:43:09 +0000 (15:43 +0100)] 
aarch64: morello: remove ELF_MACHINE_START_ADDRESS

The start address (l_entry) is now a capability so no need to fix it.

2 years agocheri: elf: make l_entry a capability
Szabolcs Nagy [Tue, 6 Sep 2022 07:40:52 +0000 (08:40 +0100)] 
cheri: elf: make l_entry a capability

Previously the entry address was fixed up to be a capability before
using it so l_entry could be ElfW(Addr), but the code is simpler and
more consistent if l_entry is a capability throughout:

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.

2 years agoTODO: cheri: elf: Add new AT_* auxv types
Szabolcs Nagy [Wed, 31 Aug 2022 10:55:45 +0000 (11:55 +0100)] 
TODO: cheri: elf: Add new AT_* auxv types

Used for purecap ABI.

TODO: squash into
091bcf0e1c cheri: elf: Add new a_type entries

2 years agoTODO: drop unused u64 reloc addr from lazy relocs
Szabolcs Nagy [Thu, 8 Sep 2022 15:18:38 +0000 (16:18 +0100)] 
TODO: drop unused u64 reloc addr from lazy relocs

squash into
3eb1c569eb TODO(l_addr): aarch64: morello: dynamic linking support

2 years agoTODO: aarch64: morello: fix abs sym reloc
Szabolcs Nagy [Tue, 6 Sep 2022 15:31:33 +0000 (16:31 +0100)] 
TODO: aarch64: morello: fix abs sym reloc

TODO: squash into
3eb1c569eb TODO(l_addr): aarch64: morello: dynamic linking support

2 years agoTODO: cheri: elf: turn back to addresses: l_map_end, l_text_end, l_relro_start
Szabolcs Nagy [Tue, 23 Aug 2022 15:37:25 +0000 (16:37 +0100)] 
TODO: cheri: elf: turn back to addresses: l_map_end, l_text_end, l_relro_start

TODO: squash into
51fe1e15ed TODO(incomplete): cheri: rtld: more elfptr_t in linkmap struct

2 years agoaarch64: morello: update HWCAP2_MORELLO value
Szabolcs Nagy [Tue, 23 Aug 2022 15:37:25 +0000 (16:37 +0100)] 
aarch64: morello: update HWCAP2_MORELLO value

Unfortunately this will keep changing during the development
as upstream linux did not want to reserve a bit for morello.

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

TODO: kernel should do this

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 agoTODO: cheri: printf: fix unused variable warning
Szabolcs Nagy [Mon, 10 Oct 2022 12:34:36 +0000 (13:34 +0100)] 
TODO: cheri: printf: fix unused variable warning

warning happens in non-purecap build.

TODO: squash into original cheri printf change

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 agoFix OOB read in stdlib thousand separator handling
Szabolcs Nagy [Tue, 11 Oct 2022 14:24:41 +0000 (15:24 +0100)] 
Fix OOB read in stdlib thousand separator handling

__correctly_grouped_prefixmb only worked with thousands_len == 1,
otherwise it read past the end of cp or thousands.

Avoid OOB access by considering thousands_len when initializing cp.

On morello with strict bounds checking this fixes

FAIL: stdlib/tst-strtod4
FAIL: stdlib/tst-strtod5i

both of which set cs_CZ.UTF-8 locale that has 3 byte thousands_len.

2 years agoelf: Fix _dl_debug_vdprintf stack buffer underflow
Szabolcs Nagy [Tue, 11 Oct 2022 13:22:35 +0000 (14:22 +0100)] 
elf: Fix _dl_debug_vdprintf stack buffer underflow

When printing numbers the alloca buffer size did not consider the
optional width parameter for padding. The width is used e.g. by
_dl_map_object_from_fd which passes '(int) sizeof (void *) * 2'
which can be larger than the buffer size on systems where
sizeof (void *) >= 2 * sizeof (unsigned long).  But even if large
width is not used currently it is better to handle it to avoid
surprises.

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
Szabolcs Nagy [Tue, 11 Oct 2022 12:23:25 +0000 (13:23 +0100)] 
Fix malloc/tst-scratch_buffer

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 elf/tst-tls20 stack OOB access
Szabolcs Nagy [Tue, 11 Oct 2022 12:07:59 +0000 (13:07 +0100)] 
Fix elf/tst-tls20 stack OOB access

Off-by-one error found on morello with strict stack bounds.

2 years agoFix off-by-one error in iconv/tst-iconv-mt
Szabolcs Nagy [Mon, 26 Sep 2022 14:38:19 +0000 (15:38 +0100)] 
Fix off-by-one error 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 agoTODO(drop): aarch64: morello: CPU feature detection for Morello arm/morello/v1
Carlos Eduardo Seo [Fri, 13 Nov 2020 19:33:07 +0000 (16:33 -0300)] 
TODO(drop): aarch64: morello: CPU feature detection for Morello

Initial detection of Arm Morello architecture from the HWCAP2 bit and CPU
identification from MIDR_EL0.

TODO: not needed?
- lp64 does not have to detect
- purecap can assume morello

2 years agoTODO(gprof): aarch64: morello: add gprof profiling support to asm
Szabolcs Nagy [Wed, 13 Jul 2022 14:22:10 +0000 (15:22 +0100)] 
TODO(gprof): aarch64: morello: add gprof profiling support to asm

Assembly prologue code with mcount call for gprof instrumentation.

TODO: untested, likely needs further runtime updates too.

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(audit): aarch64: morello: add _dl_runtime_profile entry
Szabolcs Nagy [Wed, 13 Jul 2022 15:01:24 +0000 (16:01 +0100)] 
TODO(audit): aarch64: morello: add _dl_runtime_profile entry

Required for LD_AUDIT PLT hooks and shared library profiling.

incomplete, untested.

TODO: needs La_aarch64* layout definition for morello
TODO: needs to save c9 for vararg abi

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 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 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 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 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: the value will change

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 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 agoTODO(uapi): cheri: Fix sigevent ABI
Szabolcs Nagy [Thu, 16 Jun 2022 14:37:31 +0000 (15:37 +0100)] 
TODO(uapi): cheri: Fix sigevent ABI

TODO: depends on kernel sigevent definition update.

2 years agoTODO(morello): cheri: fix posix timers
Szabolcs Nagy [Tue, 19 Apr 2022 14:18:56 +0000 (15:18 +0100)] 
TODO(morello): 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).

TODO: this is morello specific and does not work for generic cheri.

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(l_addr): cheri: rtld: elfptr_t fix in rtld.c program header processing
Szabolcs Nagy [Thu, 7 Apr 2022 09:08:51 +0000 (10:08 +0100)] 
TODO(l_addr): cheri: rtld: elfptr_t fix in rtld.c program header processing

TODO: depends on l_addr design

2 years agoTODO(l_addr): aarch64: morello: dynamic linking support
Szabolcs Nagy [Tue, 29 Mar 2022 14:24:38 +0000 (15:24 +0100)] 
TODO(l_addr): 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. This required several APIs to
change ElfW(Addr) to uintptr_t including in generic code (where
elfptr_t used to cover both traditional and capability abis).

RELATIVE and IRELATIVE relocs use a helper function 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)
 uintptr_t elf_machine_load_address_from_args (void *)

The ld.so load address is either AT_BASE or if it is invoked as a
command then derived from AT_PHDR or _DYNAMIC (pcc).

ELF_MACHINE_START_ADDRESS is updated to turn the ElfW(Addr) user entry
into a capability based on l_addr.

TODO: __tls_get_addr should return a bounded pointer.
(in case traditional tls is defined for morello)

note: tls_index struct that is used for trad tls is changed for morello.
(this is abi once trad tls is defined for morello)

arguably _dl_make_tlsdesc_dynamic should set up tlsinfo.ti_size too.
(but it's better to avoid changing the generic code)

TODO: use cheri auxv entries to derive ld.so capabilities, this will
      require separate RW and RX base pointers instead of single l_addr.
      AT_BASE will not be a capability covering ld.so.

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

Prevent lp64 ld.so loading purecap binaries.

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 agoTODO(l_addr): cheri: rtld: elfptr_t fixes in dl-map-segments.h
Szabolcs Nagy [Thu, 7 Apr 2022 07:43:00 +0000 (08:43 +0100)] 
TODO(l_addr): cheri: rtld: elfptr_t fixes in dl-map-segments.h

Ensure map_end is derived from map_start.

Use stricter mmap bounds when using MAP_FIXED:
c->mapend is aligned up to pagesize, but the capability representing
the mapping has bounds that are not page aligned, so use c->dataend
that is the actual end bound of the loaded segment.

TODO: l_addr of a pde is 0 but it should cover the exe.
this will have to be fixed. (and must not use morello asm)

2 years agoTODO(incomplete): cheri: rtld: more elfptr_t in linkmap struct
Szabolcs Nagy [Thu, 7 Apr 2022 12:18:48 +0000 (13:18 +0100)] 
TODO(incomplete): cheri: rtld: more elfptr_t in linkmap struct

TODO: requires follwup patches to make sure all usage of the fields
preserve capabilities.

2 years agocheri: elf: fix pointer provenance of l_tls_initimage
Szabolcs Nagy [Thu, 7 Apr 2022 16:04:59 +0000 (17:04 +0100)] 
cheri: elf: fix pointer provenance of l_tls_initimage

2 years agocheri: rtld: fix _dl_start to return elfptr_t
Szabolcs Nagy [Wed, 20 Apr 2022 08:54:31 +0000 (09:54 +0100)] 
cheri: rtld: fix _dl_start to return elfptr_t

Functions returning a pointer to the user entry need to use an int type
that can represent pointers.

2 years agoaarch64: morello: rtld: add ld.so _start code
Szabolcs Nagy [Tue, 29 Mar 2022 15:30:33 +0000 (16:30 +0100)] 
aarch64: morello: rtld: add 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.

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: 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: fix alignment logic in obstack
Szabolcs Nagy [Wed, 16 Mar 2022 14:07:04 +0000 (14:07 +0000)] 
cheri: malloc: fix alignment logic in obstack

If sizeof(ptrdiff_t) < sizeof(void*) the alignment logic was wrong
(incorrectly assumed that base was already sufficiently aligned).

Use more robust alignment logic: this one should work on any target.
Note: this is an installed header so it must be namespace clean and
portable.