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

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

3 years agoTODO(relro): cheri: make __attribute_relro a nop
Szabolcs Nagy [Thu, 10 Jun 2021 15:10:15 +0000 (16:10 +0100)] 
TODO(relro): cheri: make __attribute_relro a nop

relro does not work in the libc, because capabilities are readonly
even before the page protection is applied.

3 years agoTODO(ddc): aarch64: morello: purecap support in the CSU
Carlos Eduardo Seo [Thu, 18 Mar 2021 18:02:54 +0000 (15:02 -0300)] 
TODO(ddc): aarch64: morello: purecap support in the CSU

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

TODO: must not use ddc but caps from auxv
TODO: start.S: dynamic linked case is now detected by x0 != 0 (ld.so passes
__rtld_fini there), but the value of c0 on entry is not abi, just that
it has to be passed back to the libc start code in c5, so ideally the
linker should be fixed to reliably emit __rela_dyn_start when a static
exe must self relocate.

3 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

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

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

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

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

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

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

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

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

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

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

3 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

3 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

3 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

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

3 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

3 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

3 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

3 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

3 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

3 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

3 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

3 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

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

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

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

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

TODO: there is no good ABI macro to check, for now we assume
__CHERI_PURE_CAPABILITY__ implies 64 bit long, 64 bit address and
128 bit pointer.

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

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

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

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

3 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

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

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

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

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

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

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

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

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

3 years agocheri: Fix pointer alignment in fts
Szabolcs Nagy [Tue, 12 Jul 2022 09:59:16 +0000 (10:59 +0100)] 
cheri: Fix pointer alignment in fts

ALIGN has to work on pointers and the code assumed unsigned long can
always represent pointers.

3 years agocheri: Fix invalid pointer deref in wcpcpy_chk
Szabolcs Nagy [Tue, 21 Jun 2022 14:57:48 +0000 (15:57 +0100)] 
cheri: Fix invalid pointer deref in wcpcpy_chk

Accessing src via the dest pointer is invalid.

3 years agocheri: Fix invalid pointer deref in wcscpy_chk
Szabolcs Nagy [Tue, 21 Jun 2022 13:43:30 +0000 (14:43 +0100)] 
cheri: Fix invalid pointer deref in wcscpy_chk

The src pointer is const, accessing dest via it fails on CHERI targets.

3 years agoFix string/tester alignment code
Szabolcs Nagy [Mon, 21 Mar 2022 12:36:16 +0000 (12:36 +0000)] 
Fix string/tester alignment code

The code assumed pointers can be converted to unsigned long without
loss of information.

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

3 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

3 years agoaarch64: fix extension header write in getcontext and swapcontext
Szabolcs Nagy [Fri, 29 Jul 2022 07:00:06 +0000 (08:00 +0100)] 
aarch64: fix extension header write in getcontext and swapcontext

The extension header is two 32bit words and in the last header both
should be 0. There is plenty space in the __reserved area, but it's
better not to write more than we mean to.

3 years agoaarch64: don't build wordcopy
Szabolcs Nagy [Thu, 28 Jul 2022 13:29:19 +0000 (14:29 +0100)] 
aarch64: don't build wordcopy

Use an empty wordcopy.c to avoid building the generic one.
It does not seem to be used anywhere.

3 years agoscripts: Use bool in tunables initializer
Szabolcs Nagy [Tue, 8 Jun 2021 13:03:38 +0000 (14:03 +0100)] 
scripts: Use bool in tunables initializer

3 years agodlfcn: Pass caller pointer to static dlopen implementation (bug 29446)
Florian Weimer [Thu, 4 Aug 2022 15:54:48 +0000 (17:54 +0200)] 
dlfcn: Pass caller pointer to static dlopen implementation (bug 29446)

Fixes commit 0c1c3a771eceec46e66ce1183cf988e2303bd373 ("dlfcn: Move
dlopen into libc").

(cherry picked from commit ed0185e4129130cbe081c221efb758fb400623ce)

3 years agowcsmbs: Add missing test-c8rtomb/test-mbrtoc8 dependency
H.J. Lu [Fri, 29 Jul 2022 17:50:56 +0000 (10:50 -0700)] 
wcsmbs: Add missing test-c8rtomb/test-mbrtoc8 dependency

Make test-c8rtomb.out and test-mbrtoc8.out depend on $(gen-locales) for

  xsetlocale (LC_ALL, "de_DE.UTF-8");
  xsetlocale (LC_ALL, "zh_HK.BIG5-HKSCS");

Reviewed-by: Sunil K Pandey <skpgkp2@gmail.com>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
(cherry picked from commit e03f5ccd6cc8f829416156eac75acee501626c1f)

3 years agostdlib: Suppress gcc diagnostic that char8_t is a keyword in C++20 in uchar.h.
Tom Honermann [Sun, 24 Jul 2022 05:11:43 +0000 (01:11 -0400)] 
stdlib: Suppress gcc diagnostic that char8_t is a keyword in C++20 in uchar.h.

gcc 13 issues the following diagnostic for the uchar.h header when the
-Wc++20-compat option is enabled in C++ modes that do not enable char8_t
as a builtin type (C++17 and earlier by default; subject to _GNU_SOURCE
and the gcc -f[no-]char8_t option).
  warning: identifier ‘char8_t’ is a keyword in C++20 [-Wc++20-compat]
This change modifies the uchar.h header to suppress the diagnostic through
the use of '#pragma GCC diagnostic' directives for gcc 10 and later (the
-Wc++20-compat option was added in gcc version 10).  Unfortunately, a bug
in gcc currently prevents those directives from having the intended effect
as reported at https://gcc.gnu.org/PR106423.  A patch for that issue has
been submitted and is available in the email thread archive linked below.
  https://gcc.gnu.org/pipermail/gcc-patches/2022-July/598736.html

(cherry picked from commit 825f84f133bd840347dc49229b6d831f07d04775)

3 years agoCreate ChangeLog.old/ChangeLog.25. glibc-2.36
Carlos O'Donell [Fri, 29 Jul 2022 22:03:09 +0000 (18:03 -0400)] 
Create ChangeLog.old/ChangeLog.25.

3 years agoPrepare for glibc 2.36 release.
Carlos O'Donell [Fri, 29 Jul 2022 21:59:01 +0000 (17:59 -0400)] 
Prepare for glibc 2.36 release.

Update version.h, and include/features.h.

3 years agoUpdate install.texi, and regenerate INSTALL.
Carlos O'Donell [Fri, 29 Jul 2022 21:51:16 +0000 (17:51 -0400)] 
Update install.texi, and regenerate INSTALL.

3 years agoUpdate NEWS bug list.
Carlos O'Donell [Fri, 29 Jul 2022 21:49:20 +0000 (17:49 -0400)] 
Update NEWS bug list.

3 years agoUpdate libc.pot for 2.36 release.
Carlos O'Donell [Fri, 29 Jul 2022 17:01:35 +0000 (13:01 -0400)] 
Update libc.pot for 2.36 release.

3 years agotst-pidfd.c: UNSUPPORTED if we get EPERM on valid pidfd_getfd call
Mark Wielaard [Sun, 26 Jun 2022 20:17:17 +0000 (22:17 +0200)] 
tst-pidfd.c: UNSUPPORTED if we get EPERM on valid pidfd_getfd call

pidfd_getfd can fail for a valid pidfd with errno EPERM for various
reasons in a restricted environment. Use FAIL_UNSUPPORTED in that case.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
3 years agostdlib: Tuned down tst-arc4random-thread internal parameters
Adhemerval Zanella [Wed, 27 Jul 2022 11:59:15 +0000 (08:59 -0300)] 
stdlib: Tuned down tst-arc4random-thread internal parameters

With new arc4random implementation, the internal parameters might
require a lot of runtime and/or trigger some contention on older
kernels (which might trigger spurious timeout failures).

Also, since we are now testing getrandom entropy instead of an
userspace RNG, there is no much need to extensive testing.

With this change the tst-arc4random-thread goes from about 1m to
5s on a Ryzen 9 with 5.15.0-41-generic.

Checked on x86_64-linux-gnu.

Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
3 years agoLoongArch: Add greg_t and gregset_t.
caiyinyu [Wed, 27 Jul 2022 19:25:40 +0000 (03:25 +0800)] 
LoongArch: Add greg_t and gregset_t.

3 years agoLoongArch: Fix VDSO_HASH and VDSO_NAME.
caiyinyu [Wed, 27 Jul 2022 18:36:52 +0000 (02:36 +0800)] 
LoongArch: Fix VDSO_HASH and VDSO_NAME.

3 years agoriscv: Update rv64 libm test ulps
Darius Rad [Tue, 26 Jul 2022 12:54:55 +0000 (08:54 -0400)] 
riscv: Update rv64 libm test ulps

Generated on a Microsemi Polarfire Icicle Kit running Linux version
5.15.32.  Same ULPs were also produced on QEMU 5.2.0 running Linux
5.18.0.

3 years agoriscv: Update nofpu libm test ulps
Darius Rad [Tue, 26 Jul 2022 12:54:38 +0000 (08:54 -0400)] 
riscv: Update nofpu libm test ulps

3 years agoarc4random: simplify design for better safety
Jason A. Donenfeld [Tue, 26 Jul 2022 19:58:22 +0000 (21:58 +0200)] 
arc4random: simplify design for better safety

Rather than buffering 16 MiB of entropy in userspace (by way of
chacha20), simply call getrandom() every time.

This approach is doubtlessly slower, for now, but trying to prematurely
optimize arc4random appears to be leading toward all sorts of nasty
properties and gotchas. Instead, this patch takes a much more
conservative approach. The interface is added as a basic loop wrapper
around getrandom(), and then later, the kernel and libc together can
work together on optimizing that.

This prevents numerous issues in which userspace is unaware of when it
really must throw away its buffer, since we avoid buffering all
together. Future improvements may include userspace learning more from
the kernel about when to do that, which might make these sorts of
chacha20-based optimizations more possible. The current heuristic of 16
MiB is meaningless garbage that doesn't correspond to anything the
kernel might know about. So for now, let's just do something
conservative that we know is correct and won't lead to cryptographic
issues for users of this function.

This patch might be considered along the lines of, "optimization is the
root of all evil," in that the much more complex implementation it
replaces moves too fast without considering security implications,
whereas the incremental approach done here is a much safer way of going
about things. Once this lands, we can take our time in optimizing this
properly using new interplay between the kernel and userspace.

getrandom(0) is used, since that's the one that ensures the bytes
returned are cryptographically secure. But on systems without it, we
fallback to using /dev/urandom. This is unfortunate because it means
opening a file descriptor, but there's not much of a choice. Secondly,
as part of the fallback, in order to get more or less the same
properties of getrandom(0), we poll on /dev/random, and if the poll
succeeds at least once, then we assume the RNG is initialized. This is a
rough approximation, as the ancient "non-blocking pool" initialized
after the "blocking pool", not before, and it may not port back to all
ancient kernels, though it does to all kernels supported by glibc
(≥3.2), so generally it's the best approximation we can do.

The motivation for including arc4random, in the first place, is to have
source-level compatibility with existing code. That means this patch
doesn't attempt to litigate the interface itself. It does, however,
choose a conservative approach for implementing it.

Cc: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
Cc: Florian Weimer <fweimer@redhat.com>
Cc: Cristian Rodríguez <crrodriguez@opensuse.org>
Cc: Paul Eggert <eggert@cs.ucla.edu>
Cc: Mark Harris <mark.hsj@gmail.com>
Cc: Eric Biggers <ebiggers@kernel.org>
Cc: linux-crypto@vger.kernel.org
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
3 years agoLoongArch: Update NEWS and README for the LoongArch port.
caiyinyu [Tue, 19 Jul 2022 01:22:10 +0000 (09:22 +0800)] 
LoongArch: Update NEWS and README for the LoongArch port.

3 years agoLoongArch: Update build-many-glibcs.py for the LoongArch Port.
caiyinyu [Tue, 19 Jul 2022 01:22:09 +0000 (09:22 +0800)] 
LoongArch: Update build-many-glibcs.py for the LoongArch Port.

3 years agoLoongArch: Hard Float Support
caiyinyu [Tue, 19 Jul 2022 01:22:08 +0000 (09:22 +0800)] 
LoongArch: Hard Float Support

3 years agoLoongArch: Build Infrastructure
caiyinyu [Tue, 19 Jul 2022 01:22:07 +0000 (09:22 +0800)] 
LoongArch: Build Infrastructure

3 years agoLoongArch: Add ABI Lists
caiyinyu [Tue, 19 Jul 2022 01:22:06 +0000 (09:22 +0800)] 
LoongArch: Add ABI Lists

3 years agoLoongArch: Linux ABI
caiyinyu [Tue, 19 Jul 2022 01:20:51 +0000 (09:20 +0800)] 
LoongArch: Linux ABI

3 years agoLoongArch: Linux Syscall Interface
caiyinyu [Tue, 19 Jul 2022 01:20:50 +0000 (09:20 +0800)] 
LoongArch: Linux Syscall Interface

3 years agoLoongArch: Atomic and Locking Routines
caiyinyu [Tue, 19 Jul 2022 01:20:49 +0000 (09:20 +0800)] 
LoongArch: Atomic and Locking Routines

3 years agoLoongArch: Generic <math.h> and soft-fp Routines
caiyinyu [Tue, 19 Jul 2022 01:20:48 +0000 (09:20 +0800)] 
LoongArch: Generic <math.h> and soft-fp Routines

3 years agoLoongArch: Thread-Local Storage Support
caiyinyu [Tue, 19 Jul 2022 01:20:47 +0000 (09:20 +0800)] 
LoongArch: Thread-Local Storage Support

3 years agoLoongArch: ABI Implementation
caiyinyu [Tue, 19 Jul 2022 01:20:46 +0000 (09:20 +0800)] 
LoongArch: ABI Implementation

3 years agoLoongArch: Add relocations and ELF flags to elf.h and scripts/glibcelf.py
caiyinyu [Tue, 19 Jul 2022 01:20:45 +0000 (09:20 +0800)] 
LoongArch: Add relocations and ELF flags to elf.h and scripts/glibcelf.py

3 years agoLoongArch: Add LoongArch entries to config.h.in
caiyinyu [Tue, 19 Jul 2022 01:20:44 +0000 (09:20 +0800)] 
LoongArch: Add LoongArch entries to config.h.in

3 years agostruct stat is not posix conformant on microblaze with __USE_FILE_OFFSET64
Arnout Vandecappelle (Essensium/Mind) [Mon, 25 Jul 2022 09:25:15 +0000 (11:25 +0200)] 
struct stat is not posix conformant on microblaze with __USE_FILE_OFFSET64

Commit a06b40cdf5ba0d2ab4f9b4c77d21e45ff284fac7 updated stat.h to use
__USE_XOPEN2K8 instead of __USE_MISC to add the st_atim, st_mtim and
st_ctim members to struct stat. However, for microblaze, there are two
definitions of struct stat, depending on the __USE_FILE_OFFSET64 macro.
The second one was not updated.

Change __USE_MISC to __USE_XOPEN2K8 in the __USE_FILE_OFFSET64 version
of struct stat for microblaze.

3 years agoLinux: dirent/tst-readdir64-compat needs to use TEST_COMPAT (bug 27654)
Florian Weimer [Mon, 25 Jul 2022 07:39:22 +0000 (09:39 +0200)] 
Linux: dirent/tst-readdir64-compat needs to use TEST_COMPAT (bug 27654)

The hppa port starts libc at GLIBC_2.2, but has earlier symbol
versions in other shared objects.  This means that the compat
symbol for readdir64 is not actually present in libc even though
have-GLIBC_2.1.3 is defined as yes at the make level.

Fixes commit 15e50e6c966fa0f26612602a95f0129543d9f9d5 ("Linux:
dirent/tst-readdir64-compat can be a regular test") by mostly
reverting it.

3 years agomanual: Add documentation for arc4random functions
Adhemerval Zanella Netto [Thu, 21 Jul 2022 13:05:07 +0000 (10:05 -0300)] 
manual: Add documentation for arc4random functions

3 years agos390x: Add optimized chacha20
Adhemerval Zanella Netto [Thu, 21 Jul 2022 13:05:06 +0000 (10:05 -0300)] 
s390x: Add optimized chacha20

It adds vectorized ChaCha20 implementation based on libgcrypt
cipher/chacha20-s390x.S.  The final state register clearing is
omitted.

On a z15 it shows the following improvements (using formatted
bench-arc4random data):

GENERIC                                    MB/s
-----------------------------------------------
arc4random [single-thread]               198.92
arc4random_buf(16) [single-thread]       244.49
arc4random_buf(32) [single-thread]       282.73
arc4random_buf(48) [single-thread]       286.64
arc4random_buf(64) [single-thread]       320.06
arc4random_buf(80) [single-thread]       297.43
arc4random_buf(96) [single-thread]       310.96
arc4random_buf(112) [single-thread]      308.10
arc4random_buf(128) [single-thread]      309.90
-----------------------------------------------

VX.                                        MB/s
-----------------------------------------------
arc4random [single-thread]               430.26
arc4random_buf(16) [single-thread]       735.14
arc4random_buf(32) [single-thread]      1029.99
arc4random_buf(48) [single-thread]      1206.76
arc4random_buf(64) [single-thread]      1311.92
arc4random_buf(80) [single-thread]      1378.74
arc4random_buf(96) [single-thread]      1445.06
arc4random_buf(112) [single-thread]     1484.32
arc4random_buf(128) [single-thread]     1517.30
-----------------------------------------------

Checked on s390x-linux-gnu.

3 years agopowerpc64: Add optimized chacha20
Adhemerval Zanella Netto [Thu, 21 Jul 2022 13:05:05 +0000 (10:05 -0300)] 
powerpc64: Add optimized chacha20

It adds vectorized ChaCha20 implementation based on libgcrypt
cipher/chacha20-ppc.c.  It targets POWER8 and it is used on default
for LE.

On a POWER8 it shows the following improvements (using formatted
bench-arc4random data):

POWER8

GENERIC                                    MB/s
-----------------------------------------------
arc4random [single-thread]               138.77
arc4random_buf(16) [single-thread]       174.36
arc4random_buf(32) [single-thread]       228.11
arc4random_buf(48) [single-thread]       252.31
arc4random_buf(64) [single-thread]       270.11
arc4random_buf(80) [single-thread]       278.97
arc4random_buf(96) [single-thread]       287.78
arc4random_buf(112) [single-thread]      291.92
arc4random_buf(128) [single-thread]      295.25

POWER8                                     MB/s
-----------------------------------------------
arc4random [single-thread]               198.06
arc4random_buf(16) [single-thread]       278.79
arc4random_buf(32) [single-thread]       448.89
arc4random_buf(48) [single-thread]       551.09
arc4random_buf(64) [single-thread]       646.12
arc4random_buf(80) [single-thread]       698.04
arc4random_buf(96) [single-thread]       756.06
arc4random_buf(112) [single-thread]      784.12
arc4random_buf(128) [single-thread]      808.04
-----------------------------------------------

Checked on powerpc64-linux-gnu and powerpc64le-linux-gnu.
Reviewed-by: Paul E. Murphy <murphyp@linux.ibm.com>
3 years agox86: Add AVX2 optimized chacha20
Adhemerval Zanella Netto [Thu, 21 Jul 2022 13:05:04 +0000 (10:05 -0300)] 
x86: Add AVX2 optimized chacha20

It adds vectorized ChaCha20 implementation based on libgcrypt
cipher/chacha20-amd64-avx2.S.  It is used only if AVX2 is supported
and enabled by the architecture.

As for generic implementation, the last step that XOR with the
input is omited.  The final state register clearing is also
omitted.

On a Ryzen 9 5900X it shows the following improvements (using
formatted bench-arc4random data):

SSE                                        MB/s
-----------------------------------------------
arc4random [single-thread]               704.25
arc4random_buf(16) [single-thread]      1018.17
arc4random_buf(32) [single-thread]      1315.27
arc4random_buf(48) [single-thread]      1449.36
arc4random_buf(64) [single-thread]      1511.16
arc4random_buf(80) [single-thread]      1539.48
arc4random_buf(96) [single-thread]      1571.06
arc4random_buf(112) [single-thread]     1596.16
arc4random_buf(128) [single-thread]     1613.48
-----------------------------------------------

AVX2                                       MB/s
-----------------------------------------------
arc4random [single-thread]               922.61
arc4random_buf(16) [single-thread]      1478.70
arc4random_buf(32) [single-thread]      2241.80
arc4random_buf(48) [single-thread]      2681.28
arc4random_buf(64) [single-thread]      2913.43
arc4random_buf(80) [single-thread]      3009.73
arc4random_buf(96) [single-thread]      3141.16
arc4random_buf(112) [single-thread]     3254.46
arc4random_buf(128) [single-thread]     3305.02
-----------------------------------------------

Checked on x86_64-linux-gnu.

3 years agox86: Add SSE2 optimized chacha20
Adhemerval Zanella Netto [Thu, 21 Jul 2022 13:05:03 +0000 (10:05 -0300)] 
x86: Add SSE2 optimized chacha20

It adds vectorized ChaCha20 implementation based on libgcrypt
cipher/chacha20-amd64-ssse3.S.  It replaces the ROTATE_SHUF_2 (which
uses pshufb) by ROTATE2 and thus making the original implementation
SSE2.

As for generic implementation, the last step that XOR with the
input is omited. The final state register clearing is also
omitted.

On a Ryzen 9 5900X it shows the following improvements (using
formatted bench-arc4random data):

GENERIC                                    MB/s
-----------------------------------------------
arc4random [single-thread]               443.11
arc4random_buf(16) [single-thread]       552.27
arc4random_buf(32) [single-thread]       626.86
arc4random_buf(48) [single-thread]       649.81
arc4random_buf(64) [single-thread]       663.95
arc4random_buf(80) [single-thread]       674.78
arc4random_buf(96) [single-thread]       675.17
arc4random_buf(112) [single-thread]      680.69
arc4random_buf(128) [single-thread]      683.20
-----------------------------------------------

SSE                                        MB/s
-----------------------------------------------
arc4random [single-thread]               704.25
arc4random_buf(16) [single-thread]      1018.17
arc4random_buf(32) [single-thread]      1315.27
arc4random_buf(48) [single-thread]      1449.36
arc4random_buf(64) [single-thread]      1511.16
arc4random_buf(80) [single-thread]      1539.48
arc4random_buf(96) [single-thread]      1571.06
arc4random_buf(112) [single-thread]     1596.16
arc4random_buf(128) [single-thread]     1613.48
-----------------------------------------------

Checked on x86_64-linux-gnu.

3 years agoaarch64: Add optimized chacha20
Adhemerval Zanella Netto [Thu, 21 Jul 2022 13:05:02 +0000 (10:05 -0300)] 
aarch64: Add optimized chacha20

It adds vectorized ChaCha20 implementation based on libgcrypt
cipher/chacha20-aarch64.S.  It is used as default and only
little-endian is supported (BE uses generic code).

As for generic implementation, the last step that XOR with the
input is omited.  The final state register clearing is also
omitted.

On a virtualized Linux on Apple M1 it shows the following
improvements (using formatted bench-arc4random data):

GENERIC                                    MB/s
-----------------------------------------------
arc4random [single-thread]               380.89
arc4random_buf(16) [single-thread]       500.73
arc4random_buf(32) [single-thread]       552.61
arc4random_buf(48) [single-thread]       566.82
arc4random_buf(64) [single-thread]       574.01
arc4random_buf(80) [single-thread]       581.02
arc4random_buf(96) [single-thread]       591.19
arc4random_buf(112) [single-thread]      592.29
arc4random_buf(128) [single-thread]      596.43
-----------------------------------------------

OPTIMIZED                                  MB/s
-----------------------------------------------
arc4random [single-thread]               569.60
arc4random_buf(16) [single-thread]       825.78
arc4random_buf(32) [single-thread]       987.03
arc4random_buf(48) [single-thread]      1042.39
arc4random_buf(64) [single-thread]      1075.50
arc4random_buf(80) [single-thread]      1094.68
arc4random_buf(96) [single-thread]      1130.16
arc4random_buf(112) [single-thread]     1129.58
arc4random_buf(128) [single-thread]     1137.91
-----------------------------------------------

Checked on aarch64-linux-gnu.

3 years agobenchtests: Add arc4random benchtest
Adhemerval Zanella Netto [Thu, 21 Jul 2022 13:05:01 +0000 (10:05 -0300)] 
benchtests: Add arc4random benchtest

It shows both throughput (total bytes obtained in the test duration)
and latecy for both arc4random and arc4random_buf with different
sizes.

Checked on x86_64-linux-gnu, aarch64-linux, and powerpc64le-linux-gnu.

3 years agostdlib: Add arc4random tests
Adhemerval Zanella Netto [Thu, 21 Jul 2022 13:05:00 +0000 (10:05 -0300)] 
stdlib: Add arc4random tests

The basic tst-arc4random-chacha20.c checks if the output of ChaCha20
implementation matches the reference test vectors from RFC8439.

The tst-arc4random-fork.c check if subprocesses generate distinct
streams of randomness (if fork handling is done correctly).

The tst-arc4random-stats.c is a statistical test to the randomness of
arc4random, arc4random_buf, and arc4random_uniform.

The tst-arc4random-thread.c check if threads generate distinct streams
of randomness (if function are thread-safe).

Checked on x86_64-linux-gnu, aarch64-linux, and powerpc64le-linux-gnu.

Co-authored-by: Florian Weimer <fweimer@redhat.com>
Checked on x86_64-linux-gnu and aarch64-linux-gnu.

3 years agostdlib: Add arc4random, arc4random_buf, and arc4random_uniform (BZ #4417)
Adhemerval Zanella Netto [Thu, 21 Jul 2022 13:04:59 +0000 (10:04 -0300)] 
stdlib: Add arc4random, arc4random_buf, and arc4random_uniform (BZ #4417)

The implementation is based on scalar Chacha20 with per-thread cache.
It uses getrandom or /dev/urandom as fallback to get the initial entropy,
and reseeds the internal state on every 16MB of consumed buffer.

To improve performance and lower memory consumption the per-thread cache
is allocated lazily on first arc4random functions call, and if the
memory allocation fails getentropy or /dev/urandom is used as fallback.
The cache is also cleared on thread exit iff it was initialized (so if
arc4random is not called it is not touched).

Although it is lock-free, arc4random is still not async-signal-safe
(the per thread state is not updated atomically).

The ChaCha20 implementation is based on RFC8439 [1], omitting the final
XOR of the keystream with the plaintext because the plaintext is a
stream of zeros.  This strategy is similar to what OpenBSD arc4random
does.

The arc4random_uniform is based on previous work by Florian Weimer,
where the algorithm is based on Jérémie Lumbroso paper Optimal Discrete
Uniform Generation from Coin Flips, and Applications (2013) [2], who
credits Donald E. Knuth and Andrew C. Yao, The complexity of nonuniform
random number generation (1976), for solving the general case.

The main advantage of this method is the that the unit of randomness is not
the uniform random variable (uint32_t), but a random bit.  It optimizes the
internal buffer sampling by initially consuming a 32-bit random variable
and then sampling byte per byte.  Depending of the upper bound requested,
it might lead to better CPU utilization.

Checked on x86_64-linux-gnu, aarch64-linux, and powerpc64le-linux-gnu.

Co-authored-by: Florian Weimer <fweimer@redhat.com>
Reviewed-by: Yann Droneaud <ydroneaud@opteya.com>
[1] https://datatracker.ietf.org/doc/html/rfc8439
[2] https://arxiv.org/pdf/1304.1916.pdf

3 years agolocale: Optimize tst-localedef-path-norm
Adhemerval Zanella [Tue, 19 Jul 2022 13:30:34 +0000 (10:30 -0300)] 
locale: Optimize tst-localedef-path-norm

The locale generation are issues in parallel to try speed locale
generation.  The maximum number of jobs are limited to the online
CPU (in hope to not overcommit on environments with lower cores
than tests).

On a Ryzen 9, the test execution improves from ~6.7s to ~1.4s.

Tested-by: Mark Wielaard <mark@klomp.org>
3 years agomalloc: Simplify implementation of __malloc_assert
Florian Weimer [Thu, 21 Jul 2022 10:12:08 +0000 (12:12 +0200)] 
malloc: Simplify implementation of __malloc_assert

It is prudent not to run too much code after detecting heap
corruption, and __fxprintf is really complex.  The line number
and file name do not carry much information, so it is not included
in the error message.  (__libc_message only supports %s formatting.)
The function name and assertion should provide some context.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
3 years agoUpdate scripts/config.* files from upstream GNU config version
Adhemerval Zanella [Fri, 8 Jul 2022 01:14:24 +0000 (01:14 +0000)] 
Update scripts/config.* files from upstream GNU config version

This patch updates various miscellaneous files from their upstream
sources (version 2022-05-25).

It is required for loongarch support.

Checked on aarch64-linux-gnu.

3 years agolinux: return UNSUPPORTED from tst-mount if entering mount namespace fails
Michael Hudson-Doyle [Sun, 17 Jul 2022 23:16:57 +0000 (11:16 +1200)] 
linux: return UNSUPPORTED from tst-mount if entering mount namespace fails

Before this the test fails if run in a chroot by a non-root user:

warning: could not become root outside namespace (Operation not permitted)
../sysdeps/unix/sysv/linux/tst-mount.c:36: numeric comparison failure
   left: 1 (0x1); from: errno
  right: 19 (0x13); from: ENODEV
error: ../sysdeps/unix/sysv/linux/tst-mount.c:39: not true: fd != -1
error: ../sysdeps/unix/sysv/linux/tst-mount.c:46: not true: r != -1
error: ../sysdeps/unix/sysv/linux/tst-mount.c:48: not true: r != -1
../sysdeps/unix/sysv/linux/tst-mount.c:52: numeric comparison failure
   left: 1 (0x1); from: errno
  right: 9 (0x9); from: EBADF
error: ../sysdeps/unix/sysv/linux/tst-mount.c:55: not true: mfd != -1
../sysdeps/unix/sysv/linux/tst-mount.c:58: numeric comparison failure
   left: 1 (0x1); from: errno
  right: 2 (0x2); from: ENOENT
error: ../sysdeps/unix/sysv/linux/tst-mount.c:61: not true: r != -1
../sysdeps/unix/sysv/linux/tst-mount.c:65: numeric comparison failure
   left: 1 (0x1); from: errno
  right: 2 (0x2); from: ENOENT
error: ../sysdeps/unix/sysv/linux/tst-mount.c:68: not true: pfd != -1
error: ../sysdeps/unix/sysv/linux/tst-mount.c:75: not true: fd_tree != -1
../sysdeps/unix/sysv/linux/tst-mount.c:88: numeric comparison failure
   left: 1 (0x1); from: errno
  right: 38 (0x26); from: ENOSYS
error: 12 test failures

Checking that the test can enter a new mount namespace is more correct
than just checking the return value of support_become_root() as the test
code changes the mount namespace it runs in so running it as root on a
system that does not support mount namespaces should still skip.

Also change the test to remove the unnecessary fork.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
3 years agox86: Add support to build st{p|r}{n}{cpy|cat} with explicit ISA level
Noah Goldstein [Wed, 13 Jul 2022 23:33:01 +0000 (16:33 -0700)] 
x86: Add support to build st{p|r}{n}{cpy|cat} with explicit ISA level

1. Add default ISA level selection in non-multiarch/rtld
   implementations.

2. Add ISA level build guards to different implementations.
    - I.e strcpy-avx2.S which is ISA level 3 will only build if
      compiled ISA level <= 3. Otherwise there is no reason to
      include it as we will always use one of the ISA level 4
      implementations (strcpy-evex.S).

3. Refactor the ifunc selector and ifunc implementation list to use
   the ISA level aware wrapper macros that allow functions below the
   compiled ISA level (with a guranteed replacement) to be skipped.

Tested with and without multiarch on x86_64 for ISA levels:
{generic, x86-64-v2, x86-64-v3, x86-64-v4}

And m32 with and without multiarch.

3 years agox86: Add support to build wcscpy with explicit ISA level
Noah Goldstein [Wed, 13 Jul 2022 23:33:00 +0000 (16:33 -0700)] 
x86: Add support to build wcscpy with explicit ISA level

1. Add ISA level build guards to different implementations.
    - wcscpy-ssse3.S is used as ISA level 2/3/4.
    - wcscpy-generic.c is only used at ISA level 1 and will
      only build if compiled with ISA level == 1. Otherwise
      there is no reason to include it as we will always use
      wcscpy-ssse3.S

2. Refactor the ifunc selector and ifunc implementation list to use
   the ISA level aware wrapper macros that allow functions below the
   compiled ISA level (with a guranteed replacement) to be skipped.

Tested with and without multiarch on x86_64 for ISA levels:
{generic, x86-64-v2, x86-64-v3, x86-64-v4}

And m32 with and without multiarch.

3 years agox86: Add support to build strcmp/strlen/strchr with explicit ISA level
Noah Goldstein [Wed, 13 Jul 2022 23:32:59 +0000 (16:32 -0700)] 
x86: Add support to build strcmp/strlen/strchr with explicit ISA level

1. Add default ISA level selection in non-multiarch/rtld
   implementations.

2. Add ISA level build guards to different implementations.
    - I.e strcmp-avx2.S which is ISA level 3 will only build if
      compiled ISA level <= 3. Otherwise there is no reason to
      include it as we will always use one of the ISA level 4
      implementations (strcmp-evex.S).

3. Refactor the ifunc selector and ifunc implementation list to use
   the ISA level aware wrapper macros that allow functions below the
   compiled ISA level (with a guranteed replacement) to be skipped.

Tested with and without multiarch on x86_64 for ISA levels:
{generic, x86-64-v2, x86-64-v3, x86-64-v4}

And m32 with and without multiarch.

3 years agoelf: Fix wrong fscanf usage on tst-pldd
Adhemerval Zanella [Tue, 5 Jul 2022 15:58:40 +0000 (12:58 -0300)] 
elf: Fix wrong fscanf usage on tst-pldd

The fix done b2cd93fce666fdc8c9a5c64af2741a8a6940ac99 does not really
work since macro strification does not expand the sizeof nor the
arithmetic operation.

Checked on x86_64-linux-gnu.