]> git.ipfire.org Git - thirdparty/glibc.git/log
thirdparty/glibc.git
3 years agox86: Set Prefer_No_VZEROUPPER and add Prefer_AVX2_STRCMP
H.J. Lu [Fri, 26 Feb 2021 13:36:59 +0000 (05:36 -0800)] 
x86: Set Prefer_No_VZEROUPPER and add Prefer_AVX2_STRCMP

1. Set Prefer_No_VZEROUPPER if RTM is usable to avoid RTM abort triggered
by VZEROUPPER inside a transactionally executing RTM region.
2. Since to compare 2 32-byte strings, 256-bit EVEX strcmp requires 2
loads, 3 VPCMPs and 2 KORDs while AVX2 strcmp requires 1 load, 2 VPCMPEQs,
1 VPMINU and 1 VPMOVMSKB, AVX2 strcmp is faster than EVEX strcmp.  Add
Prefer_AVX2_STRCMP to prefer AVX2 strcmp family functions.

(cherry picked from commit 1da50d4bda07f04135dca39f40e79fc9eabed1f8)

3 years agotest-strnlen.c: Check that strnlen won't go beyond the maximum length
H.J. Lu [Sat, 27 Mar 2021 16:06:39 +0000 (09:06 -0700)] 
test-strnlen.c: Check that strnlen won't go beyond the maximum length

Place strings ending at page boundary without the null byte.  If an
implementation goes beyond EXP_LEN, it will trigger the segfault.

(cherry picked from commit cb882b21b63606aabd6e55afe23b42434d95f2ef)

3 years agotest-strnlen.c: Initialize wchar_t string with wmemset [BZ #27655]
H.J. Lu [Sat, 27 Mar 2021 16:15:00 +0000 (09:15 -0700)] 
test-strnlen.c: Initialize wchar_t string with wmemset [BZ #27655]

Use wmemset to initialize wchar_t string.

(cherry picked from commit 86859b7e58d8670b186c5209ba25f0fbd6612fb7)

3 years agoNEWS: Add a bug fix entry for BZ #28755
H.J. Lu [Thu, 27 Jan 2022 04:28:51 +0000 (20:28 -0800)] 
NEWS: Add a bug fix entry for BZ #28755

3 years agox86: Fix __wcsncmp_avx2 in strcmp-avx2.S [BZ# 28755]
Noah Goldstein [Sun, 9 Jan 2022 22:02:21 +0000 (16:02 -0600)] 
x86: Fix __wcsncmp_avx2 in strcmp-avx2.S [BZ# 28755]

Fixes [BZ# 28755] for wcsncmp by redirecting length >= 2^56 to
__wcscmp_avx2. For x86_64 this covers the entire address range so any
length larger could not possibly be used to bound `s1` or `s2`.

test-strcmp, test-strncmp, test-wcscmp, and test-wcsncmp all pass.

Signed-off-by: Noah Goldstein <goldstein.w.n@gmail.com>
(cherry picked from commit ddf0992cf57a93200e0c782e2a94d0733a5a0b87)
(cherry picked from commit b50d5b746cc0af5ad52164dcb0d3628f08b05a0d)

3 years agoaarch64: align stack in clone [BZ #27939]
Szabolcs Nagy [Tue, 1 Jun 2021 08:23:40 +0000 (09:23 +0100)] 
aarch64: align stack in clone [BZ #27939]

The AArch64 PCS requires 16 byte aligned stack.  Previously if the
caller passed an unaligned stack to clone then the child crashed.

Fixes bug 27939.

(cherry picked from commit 3842ba494963b1d76ad5f68b8d1e5c2279160e31)

3 years agosupport: Fix xclone build failures on ia64 and hppa
Florian Weimer [Fri, 25 Jun 2021 07:30:00 +0000 (09:30 +0200)] 
support: Fix xclone build failures on ia64 and hppa

(cherry picked from commit 97ed4749becdc20481688ee074e90507ca3501dd)

3 years agoLinux: Detect user namespace support in io/tst-getcwd-smallbuff
Florian Weimer [Mon, 24 Jan 2022 17:14:24 +0000 (18:14 +0100)] 
Linux: Detect user namespace support in io/tst-getcwd-smallbuff

Otherwise the test fails with certain container runtimes.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
(cherry picked from commit 5b8e7980c5dabd9aaefeba4f0208baa8cf7653ee)

3 years agorealpath: Avoid overwriting preexisting error (CVE-2021-3998)
Siddhesh Poyarekar [Mon, 24 Jan 2022 16:06:41 +0000 (21:36 +0530)] 
realpath: Avoid overwriting preexisting error (CVE-2021-3998)

Set errno and failure for paths that are too long only if no other error
occurred earlier.

Related: BZ #28770

Reviewed-by: Andreas Schwab <schwab@linux-m68k.org>
Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
(cherry picked from commit 84d2d0fe20bdf94feed82b21b4d7d136db471f03)

3 years agogetcwd: Set errno to ERANGE for size == 1 (CVE-2021-3999)
Siddhesh Poyarekar [Fri, 21 Jan 2022 18:02:56 +0000 (23:32 +0530)] 
getcwd: Set errno to ERANGE for size == 1 (CVE-2021-3999)

No valid path returned by getcwd would fit into 1 byte, so reject the
size early and return NULL with errno set to ERANGE.  This change is
prompted by CVE-2021-3999, which describes a single byte buffer
underflow and overflow when all of the following conditions are met:

- The buffer size (i.e. the second argument of getcwd) is 1 byte
- The current working directory is too long
- '/' is also mounted on the current working directory

Sequence of events:

- In sysdeps/unix/sysv/linux/getcwd.c, the syscall returns ENAMETOOLONG
  because the linux kernel checks for name length before it checks
  buffer size

- The code falls back to the generic getcwd in sysdeps/posix

- In the generic func, the buf[0] is set to '\0' on line 250

- this while loop on line 262 is bypassed:

    while (!(thisdev == rootdev && thisino == rootino))

  since the rootfs (/) is bind mounted onto the directory and the flow
  goes on to line 449, where it puts a '/' in the byte before the
  buffer.

- Finally on line 458, it moves 2 bytes (the underflowed byte and the
  '\0') to the buf[0] and buf[1], resulting in a 1 byte buffer overflow.

- buf is returned on line 469 and errno is not set.

This resolves BZ #28769.

Reviewed-by: Andreas Schwab <schwab@linux-m68k.org>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Signed-off-by: Qualys Security Advisory <qsa@qualys.com>
Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
(cherry picked from commit 23e0e8f5f1fb5ed150253d986ecccdc90c2dcd5e)

3 years agosupport: Add xclone
Adhemerval Zanella [Wed, 10 Mar 2021 15:26:30 +0000 (12:26 -0300)] 
support: Add xclone

It is a wrapper for Linux clone syscall, to simplify the call to the
use only the most common arguments and remove architecture specific
handling (such as ia64 different name and signature).

(cherry picked from commit de8995a2a04163617c1a233b4b81356ef9f9741f)

3 years agotst-realpath-toolong: Fix hurd build
Siddhesh Poyarekar [Mon, 24 Jan 2022 05:27:09 +0000 (10:57 +0530)] 
tst-realpath-toolong: Fix hurd build

Define PATH_MAX to a constant if it isn't already defined, like in hurd.

Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
(cherry picked from commit 976db046bc3a3738f69255ae00b0a09b8e77fd9c)

3 years agorealpath: Set errno to ENAMETOOLONG for result larger than PATH_MAX [BZ #28770]
Siddhesh Poyarekar [Thu, 13 Jan 2022 05:58:36 +0000 (11:28 +0530)] 
realpath: Set errno to ENAMETOOLONG for result larger than PATH_MAX [BZ #28770]

realpath returns an allocated string when the result exceeds PATH_MAX,
which is unexpected when its second argument is not NULL.  This results
in the second argument (resolved) being uninitialized and also results
in a memory leak since the caller expects resolved to be the same as the
returned value.

Return NULL and set errno to ENAMETOOLONG if the result exceeds
PATH_MAX.  This fixes [BZ #28770], which is CVE-2021-3998.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
(cherry picked from commit ee8d5e33adb284601c00c94687bc907e10aec9bb)

3 years agosupport: Add helpers to create paths longer than PATH_MAX
Siddhesh Poyarekar [Tue, 18 Jan 2022 07:59:36 +0000 (13:29 +0530)] 
support: Add helpers to create paths longer than PATH_MAX

Add new helpers support_create_and_chdir_toolong_temp_directory and
support_chdir_toolong_temp_directory to create and descend into
directory trees longer than PATH_MAX.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
(cherry picked from commit fb7bff12e81c677a6622f724edd4d4987dd9d971)

3 years agoelf: Fix glibc-hwcaps priorities with cache flags mismatches [BZ #27046]
Florian Weimer [Fri, 25 Jun 2021 06:02:30 +0000 (08:02 +0200)] 
elf: Fix glibc-hwcaps priorities with cache flags mismatches [BZ #27046]

If lib->flags (in the cache) did not match GLRO (dl_correct_cache_id),
searching for further glibc-hwcaps entries did not happen, and it
was possible that the best glibc-hwcaps was not found.  By accident,
this causes a test failure for elf/tst-glibc-hwcaps-prepend-cache
on armv7l.

This commit changes the cache lookup logic to continue searching
if (a) no match has been found, (b) a named glibc-hwcaps match
has been found(), or (c) non-glibc-hwcaps match has been found
and the entry flags and cache default flags do not match.

_DL_CACHE_DEFAULT_ID is used instead of GLRO (dl_correct_cache_id)
because the latter is only written once on i386 if loading
of libc.so.5 libraries is selected, so GLRO (dl_correct_cache_id)
should probably removed in a future change.

Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
(cherry picked from commit 66db95b6e8264c5a6307f6a9e5285fec76907254)

3 years agopowerpc: Fix unrecognized instruction errors with recent binutils
Paul A. Clarke [Sat, 25 Sep 2021 14:57:15 +0000 (09:57 -0500)] 
powerpc: Fix unrecognized instruction errors with recent binutils

Recent versions of binutils (with commit
b25f942e18d6ecd7ec3e2d2e9930eb4f996c258a) stopped preserving "sticky"
options across a base `.machine` directive, nullifying the use of
passing "-many" through GCC to the assembler.  As a result, some
instructions which were recognized even under older, more stringent
`.machine` directives become unrecognized instructions in that
context.

In `sysdeps/powerpc/tst-set_ppr.c`, the use of the `mfppr32` extended
mnemonic became unrecognized, as the default compilation with GCC for
32bit powerpc adds a `.machine ppc` in the resulting assembly, so the
command line option `-Wa,-many` is essentially ignored, and the ISA 2.06
instructions and mnemonics, like `mfppr32`, are unrecognized.

The compilation of `sysdeps/powerpc/tst-set_ppr.c` fails with:
Error: unrecognized opcode: `mfppr32'

Add appropriate `.machine` directives in the assembly to bracket the
`mfppr32` instruction.

Part of a 2019 fix (commit 9250e6610fdb0f3a6f238d2813e319a41fb7a810) to
the above test's Makefile to add `-many` to the compilation when GCC
itself stopped passing `-many` to the assember no longer has any effect,
so remove that.

Reported-by: Joseph Myers <joseph@codesourcery.com>
(cherry picked from commit ee874f44fd55988808a4a162ef21bfa2cc8dc6f7)

3 years agoCVE-2022-23218: Buffer overflow in sunrpc svcunix_create (bug 28768)
Florian Weimer [Mon, 17 Jan 2022 10:49:25 +0000 (11:49 +0100)] 
CVE-2022-23218: Buffer overflow in sunrpc svcunix_create (bug 28768)

The sunrpc function svcunix_create suffers from a stack-based buffer
overflow with overlong pathname arguments.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
(cherry picked from commit f545ad4928fa1f27a3075265182b38a4f939a5f7)

3 years ago<shlib-compat.h>: Support compat_symbol_reference for _ISOMAC
Florian Weimer [Tue, 9 Mar 2021 20:07:24 +0000 (21:07 +0100)] 
<shlib-compat.h>: Support compat_symbol_reference for _ISOMAC

This is helpful for testing compat symbols in cases where _ISOMAC
is activated implicitly due to -DMODULE_NAME=testsuite and cannot
be disabled easily.

(cherry picked from commit 36f6e408845c8c539128f3fb9cb132bf1845a2c8)

3 years agosunrpc: Test case for clnt_create "unix" buffer overflow (bug 22542)
Martin Sebor [Mon, 17 Jan 2022 09:21:34 +0000 (10:21 +0100)] 
sunrpc: Test case for clnt_create "unix" buffer overflow (bug 22542)

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
(cherry picked from commit ef972a4c50014a16132b5c75571cfb6b30bef136)

3 years agoCVE-2022-23219: Buffer overflow in sunrpc clnt_create for "unix" (bug 22542)
Florian Weimer [Mon, 17 Jan 2022 09:21:34 +0000 (10:21 +0100)] 
CVE-2022-23219: Buffer overflow in sunrpc clnt_create for "unix" (bug 22542)

Processing an overlong pathname in the sunrpc clnt_create function
results in a stack-based buffer overflow.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
(cherry picked from commit 226b46770c82899b555986583294b049c6ec9b40)

3 years agosocket: Add the __sockaddr_un_set function
Florian Weimer [Mon, 17 Jan 2022 09:21:34 +0000 (10:21 +0100)] 
socket: Add the __sockaddr_un_set function

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
(cherry picked from commit e368b12f6c16b6888dda99ba641e999b9c9643c8)

3 years agox86: use default cache size if it cannot be determined [BZ #28784]
Aurelien Jarno [Mon, 17 Jan 2022 18:41:40 +0000 (19:41 +0100)] 
x86: use default cache size if it cannot be determined [BZ #28784]

In some cases (e.g QEMU, non-Intel/AMD CPU) the cache information can
not be retrieved and the corresponding values are set to 0.

Commit 2d651eb9265d ("x86: Move x86 processor cache info to
cpu_features") changed the behaviour in such case by defining the
__x86_shared_cache_size and __x86_data_cache_size variables to 0 instead
of using the default values. This cause an issue with the i686 SSE2
optimized bzero/routine which assumes that the cache size is at least
128 bytes, and otherwise tries to zero/set the whole address space minus
128 bytes.

Fix that by restoring the original code to only update
__x86_shared_cache_size and __x86_data_cache_size variables if the
corresponding cache sizes are not zero.

Fixes bug 28784
Fixes commit 2d651eb9265d

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
(cherry picked from commit c242fcce06e3102ca663b2f992611d0bda4f2668)

3 years agopowerpc: Fix unrecognized instruction errors with recent GCC
Paul A. Clarke [Tue, 14 Sep 2021 18:13:33 +0000 (13:13 -0500)] 
powerpc: Fix unrecognized instruction errors with recent GCC

Recent binutils commit b25f942e18d6ecd7ec3e2d2e9930eb4f996c258a
changes the behavior of `.machine` directives to override, rather
than augment, the base CPU. This can result in _reduced_ functionality
when, for example, compiling for default machine "power8", but explicitly
asking for ".machine power5", which loses Altivec instructions.

In tst-ucontext-ppc64-vscr.c, while the instructions provoking the new
error messages are bracketed by ".machine power5", which is ostensibly
Power ISA 2.03 (POWER5), the POWER5 processor did not support the
VSX subset, so these instructions are not recognized as "power5".

Error: unrecognized opcode: `vspltisb'
Error: unrecognized opcode: `vpkuwus'
Error: unrecognized opcode: `mfvscr'
Error: unrecognized opcode: `stvx'

Manually adding the VSX subset via ".machine altivec" is sufficient.

Reviewed-by: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
(cherry picked from commit 064b475a2e5662b6b3973fabf505eade86e61510)

3 years agopowerpc64[le]: Allocate extra stack frame on syscall.S
Matheus Castanho [Wed, 1 Dec 2021 14:14:40 +0000 (11:14 -0300)] 
powerpc64[le]: Allocate extra stack frame on syscall.S

The syscall function does not allocate the extra stack frame for scv like other
assembly syscalls using DO_CALL_SCV. So after commit d120fb9941 changed the
offset that is used to save LR, syscall ended up using an invalid offset,
causing regressions on powerpc64. So make sure the extra stack frame is
allocated in syscall.S as well to make it consistent with other uses of
DO_CALL_SCV and avoid similar issues in the future.

Tested on powerpc, powerpc64, and powerpc64le (with and without scv)

Reviewed-by: Raphael M Zinsly <rzinsly@linux.ibm.com>
(cherry picked from commit ae91d3df24a4a1b1f264d101a71a298bff310d14)

3 years agogconv: Do not emit spurious NUL character in ISO-2022-JP-3 (bug 28524)
Nikita Popov [Tue, 2 Nov 2021 08:21:42 +0000 (13:21 +0500)] 
gconv: Do not emit spurious NUL character in ISO-2022-JP-3 (bug 28524)

Bugfix 27256 has introduced another issue:
In conversion from ISO-2022-JP-3 encoding, it is possible
to force iconv to emit extra NUL character on internal state reset.
To do this, it is sufficient to feed iconv with escape sequence
which switches active character set.
The simplified check 'data->__statep->__count != ASCII_set'
introduced by the aforementioned bugfix picks that case and
behaves as if '\0' character has been queued thus emitting it.

To eliminate this issue, these steps are taken:
* Restore original condition
'(data->__statep->__count & ~7) != ASCII_set'.
It is necessary since bits 0-2 may contain
number of buffered input characters.
* Check that queued character is not NUL.
Similar step is taken for main conversion loop.

Bundled test case follows following logic:
* Try to convert ISO-2022-JP-3 escape sequence
switching active character set
* Reset internal state by providing NULL as input buffer
* Ensure that nothing has been converted.

Signed-off-by: Nikita Popov <npv1310@gmail.com>
(cherry picked from commit ff012870b2c02a62598c04daa1e54632e020fd7d)

3 years agopowerpc64[le]: Fix CFI and LR save address for asm syscalls [BZ #28532]
Matheus Castanho [Tue, 26 Oct 2021 13:44:59 +0000 (10:44 -0300)] 
powerpc64[le]: Fix CFI and LR save address for asm syscalls [BZ #28532]

Syscalls based on the assembly templates are missing CFI for r31, which gets
clobbered when scv is used, and info for LR is inaccurate, placed in the wrong
LOC and not using the proper offset. LR was also being saved to the callee's
frame, while the ABI mandates it to be saved to the caller's frame. These are
fixed by this commit.

After this change:

$ readelf -wF libc.so.6 | grep 0004b9d4.. -A 7 && objdump --disassemble=kill libc.so.6
00004a48 0000000000000020 00004a4c FDE cie=00000000 pc=000000000004b9d4..000000000004ba3c
   LOC           CFA      r31   ra
000000000004b9d4 r1+0     u     u
000000000004b9e4 r1+48    u     u
000000000004b9e8 r1+48    c-16  u
000000000004b9fc r1+48    c-16  c+16
000000000004ba08 r1+48    c-16
000000000004ba18 r1+48    u
000000000004ba1c r1+0     u

libc.so.6:     file format elf64-powerpcle

Disassembly of section .text:

000000000004b9d4 <kill>:
   4b9d4:       1f 00 4c 3c     addis   r2,r12,31
   4b9d8:       2c c3 42 38     addi    r2,r2,-15572
   4b9dc:       25 00 00 38     li      r0,37
   4b9e0:       d1 ff 21 f8     stdu    r1,-48(r1)
   4b9e4:       20 00 e1 fb     std     r31,32(r1)
   4b9e8:       98 8f ed eb     ld      r31,-28776(r13)
   4b9ec:       10 00 ff 77     andis.  r31,r31,16
   4b9f0:       1c 00 82 41     beq     4ba0c <kill+0x38>
   4b9f4:       a6 02 28 7d     mflr    r9
   4b9f8:       40 00 21 f9     std     r9,64(r1)
   4b9fc:       01 00 00 44     scv     0
   4ba00:       40 00 21 e9     ld      r9,64(r1)
   4ba04:       a6 03 28 7d     mtlr    r9
   4ba08:       08 00 00 48     b       4ba10 <kill+0x3c>
   4ba0c:       02 00 00 44     sc
   4ba10:       00 00 bf 2e     cmpdi   cr5,r31,0
   4ba14:       20 00 e1 eb     ld      r31,32(r1)
   4ba18:       30 00 21 38     addi    r1,r1,48
   4ba1c:       18 00 96 41     beq     cr5,4ba34 <kill+0x60>
   4ba20:       01 f0 20 39     li      r9,-4095
   4ba24:       40 48 23 7c     cmpld   r3,r9
   4ba28:       20 00 e0 4d     bltlr+
   4ba2c:       d0 00 63 7c     neg     r3,r3
   4ba30:       08 00 00 48     b       4ba38 <kill+0x64>
   4ba34:       20 00 e3 4c     bnslr+
   4ba38:       c8 32 fe 4b     b       2ed00 <__syscall_error>
        ...
   4ba44:       40 20 0c 00     .long 0xc2040
   4ba48:       68 00 00 00     .long 0x68
   4ba4c:       06 00 5f 5f     rlwnm   r31,r26,r0,0,3
   4ba50:       6b 69 6c 6c     xoris   r12,r3,26987

(cherry picked from commit d120fb9941be1fb1934f0b50c6ad64e4c5e404fb)

3 years agonptl: Do not set signal mask on second setjmp return [BZ #28607]
Florian Weimer [Wed, 24 Nov 2021 07:59:54 +0000 (08:59 +0100)] 
nptl: Do not set signal mask on second setjmp return [BZ #28607]

__libc_signal_restore_set was in the wrong place: It also ran
when setjmp returned the second time (after pthread_exit or
pthread_cancel).  This is observable with blocked pending
signals during thread exit.

Fixes commit b3cae39dcbfa2432b3f3aa28854d8ac57f0de1b8
("nptl: Start new threads with all signals blocked [BZ #25098]").

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
(cherry picked from commit e186fc5a31e46f2cbf5ea1a75223b4412907f3d8)

3 years agosupport: Add xpthread_kill
Adhemerval Zanella [Wed, 20 Jan 2021 17:32:23 +0000 (14:32 -0300)] 
support: Add xpthread_kill

Checked on x86_64-linux-gnu.

(cherry picked from commit 0280b390fbd4c55a708985829d58a639475bbffb)

3 years agos390: Use long branches across object boundaries (jgh instead of jh)
Florian Weimer [Wed, 10 Nov 2021 14:21:37 +0000 (15:21 +0100)] 
s390: Use long branches across object boundaries (jgh instead of jh)

Depending on the layout chosen by the linker, the 16-bit displacement
of the jh instruction is insufficient to reach the target label.

Analysis of the linker failure was carried out by Nick Clifton.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Reviewed-by: Stefan Liebler <stli@linux.ibm.com>
(cherry picked from commit 98966749f2b418825ff2ea496a0ee89fe63d2cc8)

3 years agoelf: Replace nsid with args.nsid [BZ #27609]
H.J. Lu [Thu, 30 Sep 2021 17:29:17 +0000 (10:29 -0700)] 
elf: Replace nsid with args.nsid [BZ #27609]

commit ec935dea6332cb22f9881cd1162bad156173f4b0
Author: Florian Weimer <fweimer@redhat.com>
Date:   Fri Apr 24 22:31:15 2020 +0200

    elf: Implement __libc_early_init

has

@@ -856,6 +876,11 @@ no more namespaces available for dlmopen()"));
   /* See if an error occurred during loading.  */
   if (__glibc_unlikely (exception.errstring != NULL))
     {
+      /* Avoid keeping around a dangling reference to the libc.so link
+   map in case it has been cached in libc_map.  */
+      if (!args.libc_already_loaded)
+  GL(dl_ns)[nsid].libc_map = NULL;
+

do_dlopen calls _dl_open with nsid == __LM_ID_CALLER (-2), which calls
dl_open_worker with args.nsid = nsid.  dl_open_worker updates args.nsid
if it is __LM_ID_CALLER.  After dl_open_worker returns, it is wrong to
use nsid.

Replace nsid with args.nsid after dl_open_worker returns.  This fixes
BZ #27609.

(cherry picked from commit 1e1ecea62e899acb58c3fdf3b320a0833ddd0dff)

3 years agoS390: Add PCI_MIO and SIE HWCAPs
Stefan Liebler [Tue, 5 Oct 2021 14:14:10 +0000 (16:14 +0200)] 
S390: Add PCI_MIO and SIE HWCAPs

Both new HWCAPs were introduced in these kernel commits:
7e8403ecaf884f307b627f3c371475913dd29292
  "s390: add HWCAP_S390_PCI_MIO to ELF hwcaps"
7e82523f2583e9813e4109df3656707162541297
  "s390/hwcaps: make sie capability regular hwcap"

Also note that the kernel commit 511ad531afd4090625def4d9aba1f5227bd44b8e
"s390/hwcaps: shorten HWCAP defines" has shortened the prefix of the macros
from "HWCAP_S390_" to "HWCAP_".  For compatibility reasons, we do not
change the prefix in public glibc header file.

(cherry picked from commit f2e06656d04a9fcb0603802a4f8ce7aa3a1f055e)

3 years agoposix: Fix attribute access mode on getcwd [BZ #27476]
Aurelien Jarno [Fri, 10 Sep 2021 17:39:35 +0000 (19:39 +0200)] 
posix: Fix attribute access mode on getcwd [BZ #27476]

There is a GNU extension that allows to call getcwd(NULL, >0). It is
described in the documentation, but also directly in the unistd.h
header, just above the declaration.

Therefore the attribute access mode added in commit 06febd8c6705
is not correct. Drop it.

(cherry picked from commit 63a788f48a713f2081f200dd054df3e728b0e7c2)

3 years agoFix failing nss/tst-nss-files-hosts-long with local resolver
Aurelien Jarno [Thu, 2 Sep 2021 22:28:14 +0000 (00:28 +0200)] 
Fix failing nss/tst-nss-files-hosts-long with local resolver

When a local resolver like unbound is listening on the IPv4 loopback
address 127.0.0.1, the nss/tst-nss-files-hosts-long test fails. This is
due to:
- the default resolver in the absence of resolv.conf being 127.0.0.1
- the default DNS NSS database configuration in the absence of
  nsswitch.conf being 'hosts: dns [!UNAVAIL=return] file'

This causes the requests for 'test4' and 'test6' to first be sent to the
local resolver, which responds with NXDOMAIN in the likely case those
records do no exist. In turn that causes the access to /etc/hosts to be
skipped, which is the purpose of that test.

Fix that by providing a simple nsswitch.conf file forcing access to
/etc/hosts for that test. I have tested that the only changed result in
the testsuite is that test.

(cherry picked from commit 2738480a4b0866723fb8c633f36bdd34a8767581)

3 years agoMIPS: Setup errno for {f,l,}xstat
Jiaxun Yang [Tue, 7 Sep 2021 05:31:42 +0000 (13:31 +0800)] 
MIPS: Setup errno for {f,l,}xstat

{f,l,}xstat stub for MIPS is using INTERNAL_SYSCALL
to do xstat syscall for glibc ver, However it leaves
errno untouched and thus giving bad errno output.

Setup errno properly when syscall returns non-zero.

Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
(cherry picked from commit 66016ec8aeefd40e016d7040d966484c764b0e9c)

3 years agoRISC-V: Update rv64 ULPs
Aurelien Jarno [Wed, 1 Sep 2021 21:49:27 +0000 (23:49 +0200)] 
RISC-V: Update rv64 ULPs

Generated on both a Microsemi Polarfire Icicle Kit and a BeagleV
Starlight, resulting in identical ULPs.

3 years agolinux: Remove shmmax check from tst-sysvshm-linux
Adhemerval Zanella [Tue, 2 Feb 2021 12:55:50 +0000 (09:55 -0300)] 
linux: Remove shmmax check from tst-sysvshm-linux

The shmmax expected value is tricky to check because kernel clamps it
to INT_MAX in two cases:

  1. Compat symbols with IPC_64, i.e, 32-bit binaries running on 64-bit
     kernels.

  2. Default symbol without IPC_64 (defined as IPC_OLD within Linux) and
     glibc always use IPC_64 for 32-bit ABIs (to support 64-bit time_t).
     It means that 32-bit binaries running on 32-bit kernels will not see
     shmmax being clamped.

And finding out whether the compat symbol is used would require checking
the underlying kernel against the current ABI.  The shmall and shmmni
already provided enough coverage.

Checked on x86_64-linux-gnu and i686-linux-gnu.  It should fix the
tst-sysvshm-linux failures on 32-bit kernels.

(cherry picked from commit 913201078502ad3f10043db02a8efce5d75387c2)

3 years agolibrt: add test (bug 28213)
Nikita Popov [Thu, 12 Aug 2021 10:39:50 +0000 (16:09 +0530)] 
librt: add test (bug 28213)

This test implements following logic:
1) Create POSIX message queue.
   Register a notification with mq_notify (using NULL attributes).
   Then immediately unregister the notification with mq_notify.
   Helper thread in a vulnerable version of glibc
   should cause NULL pointer dereference after these steps.
2) Once again, register the same notification.
   Try to send a dummy message.
   Test is considered successfulif the dummy message
   is successfully received by the callback function.

Signed-off-by: Nikita Popov <npv1310@gmail.com>
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
(cherry picked from commit 4cc79c217744743077bf7a0ec5e0a4318f1e6641)

3 years agolibrt: fix NULL pointer dereference (bug 28213)
Nikita Popov [Mon, 9 Aug 2021 14:47:34 +0000 (20:17 +0530)] 
librt: fix NULL pointer dereference (bug 28213)

Helper thread frees copied attribute on NOTIFY_REMOVED message
received from the OS kernel.  Unfortunately, it fails to check whether
copied attribute actually exists (data.attr != NULL).  This worked
earlier because free() checks passed pointer before actually
attempting to release corresponding memory.  But
__pthread_attr_destroy assumes pointer is not NULL.

So passing NULL pointer to __pthread_attr_destroy will result in
segmentation fault.  This scenario is possible if
notification->sigev_notify_attributes == NULL (which means default
thread attributes should be used).

Signed-off-by: Nikita Popov <npv1310@gmail.com>
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
(cherry picked from commit b805aebd42364fe696e417808a700fdb9800c9e8)

4 years agox86_64: Remove unneeded static PIE check for undefined weak diagnostic
Fangrui Song [Thu, 8 Jul 2021 21:26:22 +0000 (14:26 -0700)] 
x86_64: Remove unneeded static PIE check for undefined weak diagnostic

https://sourceware.org/bugzilla/show_bug.cgi?id=21782 dropped an ld
diagnostic for R_X86_64_PC32 referencing an undefined weak symbol in
-pie links.  Arguably keeping the diagnostic like other ports is more
correct, since statically resolving movl foo(%rip), %eax to the
link-time zero address produces a corrupted output.

It turns out that --enable-static-pie builds do not depend on the ld
behavior. GCC generates GOT indirection for weak declarations for
-fPIE/-fPIC, so what ld does with the PC-relative relocation doesn't
really matter.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
(cherry picked from commit 115d242456de158e698ffb0f9a5fee3118e9e825)

4 years agowordexp: handle overflow in positional parameter number (bug 28011)
Andreas Schwab [Fri, 25 Jun 2021 13:02:47 +0000 (15:02 +0200)] 
wordexp: handle overflow in positional parameter number (bug 28011)

Use strtoul instead of atoi so that overflow can be detected.

(cherry picked from commit 5adda61f62b77384718b4c0d8336ade8f2b4b35c)

4 years agoelf: Use _dl_catch_error from base namespace in dl-libc.c [BZ #27646]
Florian Weimer [Thu, 17 Jun 2021 13:06:43 +0000 (15:06 +0200)] 
elf: Use _dl_catch_error from base namespace in dl-libc.c [BZ #27646]

dlerrror_run in elf/dl-libc.c needs to call GLRO (dl_catch_error)
from the base namespace, just like the exported dlerror
implementation.

Fixes commit b2964eb1d9a6b8ab1250e8a881cf406182da5875 ("dlfcn:
Failures after dlmopen should not terminate process [BZ #24772]").

Backport notes: GLRO (dl_catch_error) is replaced with
_dl_catch_error_ptr to preserve _rtld_global_ro layout.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
(cherry picked from commit c2059edce20c124d1a99f1a94cc52e83b77a917a)

4 years agoFix use of __pthread_attr_copy in mq_notify (bug 27896)
Florian Weimer [Tue, 1 Jun 2021 15:51:41 +0000 (17:51 +0200)] 
Fix use of __pthread_attr_copy in mq_notify (bug 27896)

__pthread_attr_copy can fail and does not initialize the attribute
structure in that case.

If __pthread_attr_copy is never called and there is no allocated
attribute, pthread_attr_destroy should not be called, otherwise
there is a null pointer dereference in rt/tst-mqueue6.

Fixes commit 42d359350510506b87101cf77202fefcbfc790cb
("Use __pthread_attr_copy in mq_notify (bug 27896)").

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
(cherry picked from commit 217b6dc298156bdb0d6aea9ea93e7e394a5ff091)

4 years agoUse __pthread_attr_copy in mq_notify (bug 27896)
Andreas Schwab [Thu, 27 May 2021 10:49:47 +0000 (12:49 +0200)] 
Use __pthread_attr_copy in mq_notify (bug 27896)

Make a deep copy of the pthread attribute object to remove a potential
use-after-free issue.

(cherry picked from commit 42d359350510506b87101cf77202fefcbfc790cb)

4 years agodlfcn: Failures after dlmopen should not terminate process [BZ #15271]
Florian Weimer [Wed, 21 Apr 2021 17:49:51 +0000 (19:49 +0200)] 
dlfcn: Failures after dlmopen should not terminate process [BZ #15271]

Commit 9e78f6f6e7134a5f299cc8de77370218f8019237 ("Implement
_dl_catch_error, _dl_signal_error in libc.so [BZ #16628]") has the
side effect that distinct namespaces, as created by dlmopen, now have
separate implementations of the rtld exception mechanism.  This means
that the call to _dl_catch_error from libdl in a secondary namespace
does not actually install an exception handler because the
thread-local variable catch_hook in the libc.so copy in the secondary
namespace is distinct from that of the base namepace.  As a result, a
dlsym/dlopen/... failure in a secondary namespace terminates the process
with a dynamic linker error because it looks to the exception handler
mechanism as if no handler has been installed.

Backport notes: GLRO (dl_catch_error) is replaced with
_dl_catch_error_ptr to preserve _rtld_global_ro layout.

(cherry picked from commit b2964eb1d9a6b8ab1250e8a881cf406182da5875)

4 years agopowerpc: Fix handling of scv return error codes [BZ #27892]
Nicholas Piggin [Thu, 20 May 2021 14:00:36 +0000 (11:00 -0300)] 
powerpc: Fix handling of scv return error codes [BZ #27892]

When using scv for templated ASM syscalls, current code interprets any
negative return value as error, but the only valid error codes are in
the range -4095..-1 according to the ABI.

This commit also fixes 'signal.gen.test' strace test, where the issue
was first identified.

Reviewed-by: Matheus Castanho <msc@linux.ibm.com>
(cherry picked from commit 7de36744ee1325f35d3fe0ca079dd33c40b12267)

4 years agonptl: Do not build nptl/tst-pthread-gdb-attach as PIE
Florian Weimer [Thu, 22 Apr 2021 17:53:15 +0000 (19:53 +0200)] 
nptl: Do not build nptl/tst-pthread-gdb-attach as PIE

(cherry picked from commit 6f3e54d404cfe1ba7d1444e6dfcfd77b102d9287)

4 years agonptl: Check for compatible GDB in nptl/tst-pthread-gdb-attach
Florian Weimer [Thu, 22 Apr 2021 09:07:43 +0000 (11:07 +0200)] 
nptl: Check for compatible GDB in nptl/tst-pthread-gdb-attach

Also do not clear the subprocess environment, in case running
GDB needs certain environment variables.

(cherry picked from commit f553dc066071a4465321fbc122bed8a75afd996b)

4 years agonptl_db: Support different libpthread/ld.so load orders (bug 27744)
Florian Weimer [Wed, 21 Apr 2021 09:50:43 +0000 (11:50 +0200)] 
nptl_db: Support different libpthread/ld.so load orders (bug 27744)

libthread_db is loaded once GDB encounters libpthread, and at this
point, ld.so may not have been processed by GDB yet. As a result,
_rtld_global cannot be accessed by regular means from libthread_db.
To make this work until GDB can be fixed, acess _rtld_global through
a pointer stored in libpthread.

The new test does not reproduce bug 27744 with
--disable-hardcoded-path-in-tests, but is still a valid smoke test.
With --enable-hardcoded-path-in-tests, it is necessary to avoid
add-symbol-file because this can tickle a GDB bug.

Fixes commit 1daccf403b1bd86370eb94edca794dc106d02039 ("nptl: Move
stack list variables into _rtld_global").

Tested-by: Emil Velikov <emil.velikov@collabora.com>
(cherry picked from commit a64afc225240b2b27129ccfb0516d7c958b98040)

4 years agox86: tst-cpu-features-supports.c: Update AMX check
H.J. Lu [Thu, 22 Apr 2021 01:40:08 +0000 (18:40 -0700)] 
x86: tst-cpu-features-supports.c: Update AMX check

Pass "amx-bf16", "amx-int8" and "amx-tile", instead of "amx_bf16",
"amx_int8" and "amx_tile", to __builtin_cpu_supports for GCC 11.

(cherry picked from commit 7fc9152e831fb24091c0ceabdcecb9b07dd29dd6)

4 years agoRemove PR_TAGGED_ADDR_ENABLE from sys/prctl.h
Szabolcs Nagy [Tue, 2 Feb 2021 15:02:09 +0000 (15:02 +0000)] 
Remove PR_TAGGED_ADDR_ENABLE from sys/prctl.h

The value of PR_TAGGED_ADDR_ENABLE was incorrect in the installed
headers and the prctl command macros were missing that are needed
for it to be useful (PR_SET_TAGGED_ADDR_CTRL).  Linux headers have
the definitions since 5.4 so it's widely available, we don't need
to repeat these definitions.  The remaining definitions are from
Linux 5.10.

To build glibc with --enable-memory-tagging, Linux 5.4 headers and
binutils 2.33.1 or newer is needed.

Reviewed-by: DJ Delorie <dj@redhat.com>
(cherry picked from commit f4596d9540021265a99697fceef8a434c47e8bcf)

4 years agoFix SXID_ERASE behavior in setuid programs (BZ #27471)
Siddhesh Poyarekar [Tue, 16 Mar 2021 07:07:55 +0000 (12:37 +0530)] 
Fix SXID_ERASE behavior in setuid programs (BZ #27471)

When parse_tunables tries to erase a tunable marked as SXID_ERASE for
setuid programs, it ends up setting the envvar string iterator
incorrectly, because of which it may parse the next tunable
incorrectly.  Given that currently the implementation allows malformed
and unrecognized tunables pass through, it may even allow SXID_ERASE
tunables to go through.

This change revamps the SXID_ERASE implementation so that:

- Only valid tunables are written back to the tunestr string, because
  of which children of SXID programs will only inherit a clean list of
  identified tunables that are not SXID_ERASE.

- Unrecognized tunables get scrubbed off from the environment and
  subsequently from the child environment.

- This has the side-effect that a tunable that is not identified by
  the setxid binary, will not be passed on to a non-setxid child even
  if the child could have identified that tunable.  This may break
  applications that expect this behaviour but expecting such tunables
  to cross the SXID boundary is wrong.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
(cherry picked from commit 2ed18c5b534d9e92fc006202a5af0df6b72e7aca)

4 years agoEnhance setuid-tunables test
Siddhesh Poyarekar [Tue, 16 Mar 2021 07:07:54 +0000 (12:37 +0530)] 
Enhance setuid-tunables test

Instead of passing GLIBC_TUNABLES via the environment, pass the
environment variable from parent to child.  This allows us to test
multiple variables to ensure better coverage.

The test list currently only includes the case that's already being
tested.  More tests will be added later.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
(cherry picked from commit 061fe3f8add46a89b7453e87eabb9c4695005ced)

4 years agotst-env-setuid: Use support_capture_subprogram_self_sgid
Siddhesh Poyarekar [Tue, 16 Mar 2021 07:07:53 +0000 (12:37 +0530)] 
tst-env-setuid: Use support_capture_subprogram_self_sgid

Use the support_capture_subprogram_self_sgid to spawn an sgid child.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
(cherry picked from commit ca335281068a1ed549a75ee64f90a8310755956f)

4 years agosupport: Add capability to fork an sgid child
Siddhesh Poyarekar [Fri, 9 Apr 2021 15:25:45 +0000 (20:55 +0530)] 
support: Add capability to fork an sgid child

Add a new function support_capture_subprogram_self_sgid that spawns an
sgid child of the running program with its own image and returns the
exit code of the child process.  This functionality is used by at
least three tests in the testsuite at the moment, so it makes sense to
consolidate.

There is also a new function support_subprogram_wait which should
provide simple system() like functionality that does not set up file
actions.  This is useful in cases where only the return code of the
spawned subprocess is interesting.

This patch also ports tst-secure-getenv to this new function.  A
subsequent patch will port other tests.  This also brings an important
change to tst-secure-getenv behaviour.  Now instead of succeeding, the
test fails as UNSUPPORTED if it is unable to spawn a setgid child,
which is how it should have been in the first place.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
(cherry picked from commit 716a3bdc41b2b4b864dc64475015ba51e35e1273)

4 years agosupport: Pass environ to child process
Siddhesh Poyarekar [Mon, 15 Mar 2021 11:53:30 +0000 (17:23 +0530)] 
support: Pass environ to child process

Pass environ to posix_spawn so that the child process can inherit
environment of the test.

(cherry picked from commit e958490f8c74e660bd93c128b3bea746e268f3f6)

4 years agosupport: Typo and formatting fixes
Siddhesh Poyarekar [Mon, 15 Mar 2021 10:30:06 +0000 (16:00 +0530)] 
support: Typo and formatting fixes

- Add a newline to the end of error messages in transfer().
- Fixed the name of support_subprocess_init().

(cherry picked from commit 95c68080a3ded882789b1629f872c3ad531efda0)

4 years agotunables: Fix comparison of tunable values
Siddhesh Poyarekar [Tue, 16 Mar 2021 13:01:02 +0000 (18:31 +0530)] 
tunables: Fix comparison of tunable values

The simplification of tunable_set interfaces took care of
signed/unsigned conversions while setting values, but comparison with
bounds ended up being incorrect; comparing TUNABLE_SIZE_T values for
example will fail because SIZE_MAX is seen as -1.

Add comparison helpers that take tunable types into account and use
them to do comparison instead.

(cherry picked from commit d1a3dcabf2f89233a99a4a9be08f9f407da0b6b4)

4 years agolinux: always update select timeout (BZ #27706)
Adhemerval Zanella [Thu, 8 Apr 2021 10:39:32 +0000 (07:39 -0300)] 
linux: always update select timeout (BZ #27706)

The timeout should be updated even on failure for time64 support.

Checked on i686-linux-gnu.

(cherry-pick from commit cedbf6d5f3f70ca911176de87d6e453eeab4b7a1)

4 years agolinux: Normalize and return timeout on select (BZ #27651)
Adhemerval Zanella [Wed, 31 Mar 2021 16:53:34 +0000 (13:53 -0300)] 
linux: Normalize and return timeout on select (BZ #27651)

The commit 2433d39b697, which added time64 support to select, changed
the function to use __NR_pselect6 (or __NR_pelect6_time64) on all
architectures.  However, on architectures where the symbol was
implemented with __NR_select the kernel normalizes the passed timeout
instead of return EINVAL.  For instance, the input timeval
{ 0, 5000000 } is interpreted as { 5, 0 }.

And as indicated by BZ #27651, this semantic seems to be expected
and changing it results in some performance issues (most likely
the program does not check the return code and keeps issuing
select with unormalized tv_usec argument).

To avoid a different semantic depending whether which syscall the
architecture used to issue, select now always normalize the timeout
input.  This is a slight change for some ABIs (for instance aarch64).

Checked on x86_64-linux-gnu and i686-linux-gnu.

(cherry picked from commit 9d7c5cc38e58fb0923e88901f87174a511b61552)

4 years agolibsupport: Add support_select_normalizes_timeout
Adhemerval Zanella [Fri, 9 Apr 2021 13:05:13 +0000 (10:05 -0300)] 
libsupport: Add support_select_normalizes_timeout

It will be used on a select() test.

(cherry-pick from commit 49a40ba18e2cb948259771317fe6ff6f5eb68683)

4 years agolibsupport: Add support_select_modifies_timeout
Adhemerval Zanella [Fri, 9 Apr 2021 13:02:30 +0000 (10:02 -0300)] 
libsupport: Add support_select_modifies_timeout

It will be used on a select() test.

(cherry picked from commit 5628f103f5937611730845390928cb43ef716012)

4 years agomisc: Fix tst-select timeout handling (BZ#27648)
Adhemerval Zanella [Thu, 25 Mar 2021 19:57:45 +0000 (16:57 -0300)] 
misc: Fix tst-select timeout handling (BZ#27648)

Instead of polling the stderr, create two pipes and fork to check
if child timeout as expected similar to tst-pselect.c.  Also lower
the timeout value.

Checked on x86_64-linux-gnu.

(cherry picked from commit 1b53b5d970c232b48843c778ac4566ff5b566c3b)

4 years agotst: Provide test for select
Lukasz Majewski [Sat, 13 Mar 2021 22:34:21 +0000 (23:34 +0100)] 
tst: Provide test for select

This change adds new test to assess select()'s timeout related
functionality (the rdfs set provides valid fd - stderr - but during
normal program operation there is no data to be read, so one just
waits for timeout).

To be more specific - two use cases are checked:
- if select() times out immediately when passed struct timeval has
  zero values of tv_usec and tv_sec.
- if select() times out after timeout specified in passed argument

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
(cherry picked from commit bff3019afc77eb51634471827daaa1c17a6dc5bd)

4 years agoUpdate Nios II libm-test-ulps.
Joseph Myers [Thu, 1 Apr 2021 20:14:50 +0000 (20:14 +0000)] 
Update Nios II libm-test-ulps.

This has a subset of the changes in the version applied to master
(only those that actually appear in a regeneration on 2.33 branch).

4 years agomalloc: Fix a realloc crash with heap tagging [BZ 27468]
Szabolcs Nagy [Thu, 25 Feb 2021 14:49:58 +0000 (14:49 +0000)] 
malloc: Fix a realloc crash with heap tagging [BZ 27468]

_int_free must be called with a chunk that has its tag reset. This was
missing in a rare case that could crash when heap tagging is enabled:
when in a multi-threaded process the current arena runs out of memory
during realloc, but another arena still has space to finish the realloc
then _int_free was called without clearing the user allocation tags.

Fixes bug 27468.

Reviewed-by: DJ Delorie <dj@redhat.com>
(cherry picked from commit 42cc96066b22ba065db11096c78881a55e45def4)

4 years agoS390: Also check vector support in memmove ifunc-selector [BZ #27511]
Stefan Liebler [Tue, 23 Mar 2021 16:29:26 +0000 (17:29 +0100)] 
S390: Also check vector support in memmove ifunc-selector [BZ #27511]

The arch13 memmove variant is currently selected by the ifunc selector
if the Miscellaneous-Instruction-Extensions Facility 3 facility bit
is present, but the function is also using vector instructions.
If the vector support is not present, one is receiving an operation
exception.

Therefore this patch also checks for vector support in the ifunc
selector and in ifunc-impl-list.c.

Just to be sure, the configure check is now also testing an arch13
vector instruction and an arch13 Miscellaneous-Instruction-Extensions
Facility 3 instruction.

(cherry picked from commit 7759be2593b689cb1eafc0f52ee7f59c639e5d2f)

4 years agotest-container: Always copy test-specific support files [BZ #27537]
DJ Delorie [Thu, 11 Mar 2021 17:50:02 +0000 (12:50 -0500)] 
test-container: Always copy test-specific support files [BZ #27537]

There's a small chance that a fresh checkout will result in some of
the test-specific container files will have the same timestamp and
size, which breaks the rsync logic in test-container, resulting in
tests running with the wrong support files.

This patch changes the rsync logic to always copy the test-specific
files, which normally would always be copied anyway.  The rsync logic
for the testroot itself is unchanged.

(cherry picked from commit 20bee7134801cc932ff87fac511289b92fc94944)

4 years agonptl: Remove private futex optimization [BZ #27304]
Florian Weimer [Thu, 4 Feb 2021 14:00:20 +0000 (15:00 +0100)] 
nptl: Remove private futex optimization [BZ #27304]

It is effectively used, unexcept for pthread_cond_destroy, where we do
not want it; see bug 27304.  The internal locks do not support a
process-shared mode.

This fixes commit dc6cfdc934db9997c33728082d63552b9eee4563 ("nptl:
Move pthread_cond_destroy implementation into libc").

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
(cherry picked from commit c4ad832276f4dadfa40904109b26a521468f66bc)

4 years agopthread_once hangs when init routine throws an exception [BZ #18435]
Jakub Jelinek [Thu, 4 Mar 2021 14:15:33 +0000 (15:15 +0100)] 
pthread_once hangs when init routine throws an exception [BZ #18435]

This is another attempt at making pthread_once handle throwing exceptions
from the init routine callback.  As the new testcases show, just switching
to the cleanup attribute based cleanup does fix the tst-once5 test, but
breaks the new tst-oncey3 test.  That is because when throwing exceptions,
only the unwind info registered cleanups (i.e. C++ destructors or cleanup
attribute), when cancelling threads and there has been unwind info from the
cancellation point up to whatever needs cleanup both unwind info registered
cleanups and THREAD_SETMEM (self, cleanup, ...) registered cleanups are
invoked, but once we hit some frame with no unwind info, only the
THREAD_SETMEM (self, cleanup, ...) registered cleanups are invoked.
So, to stay fully backwards compatible (allow init routines without
unwind info which encounter cancellation points) and handle exception throwing
we actually need to register the pthread_once cleanups in both unwind info
and in the THREAD_SETMEM (self, cleanup, ...) way.
If an exception is thrown, only the former will happen and we in that case
need to also unregister the THREAD_SETMEM (self, cleanup, ...) registered
handler, because otherwise after catching the exception the user code could
call deeper into the stack some cancellation point, get cancelled and then
a stale cleanup handler would clobber stack and probably crash.
If a thread calling init routine is cancelled and unwind info ends before
the pthread_once frame, it will be cleaned up through self->cleanup as
before.  And if unwind info is present, unwind_stop first calls the
self->cleanup registered handler for the frame, then it will call the
unwind info registered handler but that will already see __do_it == 0
and do nothing.

(cherry picked from commit f0419e6a10740a672b28e112c409ae24f5e890ab)

4 years agoelf: ld.so --help calls _dl_init_paths without a main map [BZ #27577]
Florian Weimer [Mon, 15 Mar 2021 09:33:43 +0000 (10:33 +0100)] 
elf: ld.so --help calls _dl_init_paths without a main map [BZ #27577]

In this case, use the link map of the dynamic loader itself as
a replacement.  This is more than just a hack: if we ever support
DT_RUNPATH/DT_RPATH for the dynamic loader, reporting it for
ld.so --help (without further command line arguments) would be the
right thing to do.

Fixes commit 332421312576bd7095e70589154af99b124dd2d1 ("elf: Always
set l in _dl_init_paths (bug 23462)").

(cherry picked from commit 4e6db99c665d3b82a70a3e218860ef087b1555b4)

4 years agoelf: Always set l in _dl_init_paths (bug 23462)
Carlos O'Donell [Fri, 12 Mar 2021 15:44:47 +0000 (16:44 +0100)] 
elf: Always set l in _dl_init_paths (bug 23462)

After d1d5471579eb0426671bf94f2d71e61dfb204c30 ("Remove dead
DL_DST_REQ_STATIC code.") we always setup the link map l to make the
static and shared cases the same.  The bug is that in elf/dl-load.c
(_dl_init_paths) we conditionally set l only in the #ifdef SHARED
case, but unconditionally use it later.  The simple solution is to
remove the #ifdef SHARED conditional, because it's no longer needed,
and unconditionally setup l for both the static and shared cases. A
regression test is added to run a static binary with
LD_LIBRARY_PATH='$ORIGIN' which crashes before the fix and runs after
the fix.

Co-Authored-By: Florian Weimer <fweimer@redhat.com>
(cherry picked from commit 332421312576bd7095e70589154af99b124dd2d1)

4 years agox86: Handle _SC_LEVEL1_ICACHE_LINESIZE [BZ #27444]
H.J. Lu [Sat, 6 Mar 2021 18:19:32 +0000 (10:19 -0800)] 
x86: Handle _SC_LEVEL1_ICACHE_LINESIZE [BZ #27444]

commit 2d651eb9265d1366d7b9e881bfddd46db9c1ecc4
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Fri Sep 18 07:55:14 2020 -0700

    x86: Move x86 processor cache info to cpu_features

missed _SC_LEVEL1_ICACHE_LINESIZE.

1. Add level1_icache_linesize to struct cpu_features.
2. Initialize level1_icache_linesize by calling handle_intel,
handle_zhaoxin and handle_amd with _SC_LEVEL1_ICACHE_LINESIZE.
3. Return level1_icache_linesize for _SC_LEVEL1_ICACHE_LINESIZE.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
(cherry picked from commit f53ffc9b90cbd92fa5518686daf4091bdd1d4889)

4 years agoio: Return EBAFD for negative file descriptor on fstat (BZ #27559)
Adhemerval Zanella [Thu, 11 Mar 2021 11:21:06 +0000 (08:21 -0300)] 
io: Return EBAFD for negative file descriptor on fstat (BZ #27559)

Now that fstat is implemented on top fstatat we need to handle negative
inputs.  The implementation now rejects AT_FDCWD, which would otherwise
be accepted by the kernel.

Checked on x86_64-linux-gnu and on i686-linux-gnu.

(cherry picked from commit 94caafa040e4b4289c968cd70d53041b1463ac4d)

4 years agonscd: Fix double free in netgroupcache [BZ #27462]
DJ Delorie [Thu, 25 Feb 2021 21:08:21 +0000 (16:08 -0500)] 
nscd: Fix double free in netgroupcache [BZ #27462]

In commit 745664bd798ec8fd50438605948eea594179fba1 a use-after-free
was fixed, but this led to an occasional double-free.  This patch
tracks the "live" allocation better.

Tested manually by a third party.

Related: RHBZ 1927877

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
(cherry picked from commit dca565886b5e8bd7966e15f0ca42ee5cff686673)

4 years agox86: Set minimum x86-64 level marker [BZ #27318]
H.J. Lu [Tue, 2 Feb 2021 21:45:58 +0000 (13:45 -0800)] 
x86: Set minimum x86-64 level marker [BZ #27318]

Since the full ISA set used in an ELF binary is unknown to compiler,
an x86-64 ISA level marker indicates the minimum, not maximum, ISA set
required to run such an ELF binary.  We never guarantee a library with
an x86-64 ISA level v3 marker doesn't contain other ISAs beyond x86-64
ISA level v3, like AVX VNNI.  We check the x86-64 ISA level marker for
the minimum ISA set.  Since -march=sandybridge enables only some ISAs
in x86-64 ISA level v3, we should set the needed ISA marker to v2.
Otherwise, libc is compiled with -march=sandybridge will fail to run on
Sandy Bridge:

$ ./elf/ld.so ./libc.so
./libc.so: (p) CPU ISA level is lower than required: needed: 7; got: 3

Set the minimum, instead of maximum, x86-64 ISA level marker should have
no impact on the glibc-hwcaps directory assignment logic in ldconfig nor
ld.so.

(cherry picked from commit 339bf918ea4830fb35614632e96f3aab3237adce)

4 years agonss: Re-enable NSS module loading after chroot [BZ #27389]
DJ Delorie [Thu, 18 Feb 2021 20:26:30 +0000 (15:26 -0500)] 
nss: Re-enable NSS module loading after chroot [BZ #27389]

The glibc 2.33 release enabled /etc/nsswitch.conf reloading,
and to prevent potential security issues like CVE-2019-14271
the re-loading of nsswitch.conf and all mdoules was disabled
when the root filesystem changes (see bug 27077).

Unfortunately php-lpfm and openldap both require the ability
to continue to load NSS modules after chroot. The packages
do not exec after the chroot, and so do not cause the
protections to be reset. The only solution is to re-enable
only NSS module loading (not nsswitch.conf reloading) and so
get back the previous glibc behaviour.

In the future we may introduce a way to harden applications
so they do not reload NSS modules once the root filesystem
changes, or that only files/dns are available pre-loaded
(or builtin).

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
(cherry picked from commit 58673149f37389495c098421085ffdb468b3f7ad)

4 years agox86: Add CPU-specific diagnostics to ld.so --list-diagnostics
Florian Weimer [Wed, 24 Feb 2021 12:12:04 +0000 (13:12 +0100)] 
x86: Add CPU-specific diagnostics to ld.so --list-diagnostics

(cherry picked from commit 01a5746b6c8a44dc29d33e056b63485075a6a3cc)

Adjusted to not print the rep_movsb_stop_threshold field, which
does not exist in glibc 2.33.

4 years agox86: Automate generation of PREFERRED_FEATURE_INDEX_1 bitfield
Florian Weimer [Tue, 2 Mar 2021 13:58:05 +0000 (14:58 +0100)] 
x86: Automate generation of PREFERRED_FEATURE_INDEX_1 bitfield

Use a .def file to define the bitfield layout, so that it is possible
to iterate over field members using the preprocessor.

(cherry picked from commit e4933c8a92ea08eecdf3ab45e7f76c95dc3d20ac)

4 years agold.so: Implement the --list-diagnostics option
Florian Weimer [Tue, 2 Mar 2021 14:46:42 +0000 (15:46 +0100)] 
ld.so: Implement the --list-diagnostics option

(cherry picked from commit 851f32cf7bf7067f73b991610778915edd57d7b4)

4 years agostring: Work around GCC PR 98512 in rawmemchr
Florian Weimer [Fri, 19 Feb 2021 12:29:00 +0000 (13:29 +0100)] 
string: Work around GCC PR 98512 in rawmemchr

(cherry picked from commit 044e603b698093cf48f6e6229e0b66acf05227e4)

4 years agoS390: Add new hwcap values.
Stefan Liebler [Tue, 16 Feb 2021 15:18:56 +0000 (16:18 +0100)] 
S390: Add new hwcap values.

The new hwcap values indicate support for arch14 architecture.

(cherry picked from commit 25251c0707fe34f30a27381a5fabc35435a96621)

4 years agotunables: Disallow negative values for some tunables
Siddhesh Poyarekar [Fri, 5 Feb 2021 08:39:24 +0000 (14:09 +0530)] 
tunables: Disallow negative values for some tunables

The glibc.malloc.mmap_max tunable as well as al of the INT_32 tunables
don't have use for negative values, so pin the hardcoded limits in the
non-negative range of INT.  There's no real benefit in any of those
use cases for the extended range of unsigned, so I have avoided added
a new type to keep things simple.

(cherry picked from commit 228f30ab4724d4087d5f52018873fde22efea6e2)

4 years agox86: Use SIZE_MAX instead of (long int)-1 for tunable range value
Siddhesh Poyarekar [Wed, 3 Feb 2021 14:33:19 +0000 (20:03 +0530)] 
x86: Use SIZE_MAX instead of (long int)-1 for tunable range value

The tunable types are SIZE_T, so set the ranges to the correct maximum
value, i.e. SIZE_MAX.

(cherry picked from commit a1b8b06a55c1ee581d5ef860cec214b0c27a66f0)

4 years agotunables: Simplify TUNABLE_SET interface
Siddhesh Poyarekar [Fri, 5 Feb 2021 07:48:58 +0000 (13:18 +0530)] 
tunables: Simplify TUNABLE_SET interface

The TUNABLE_SET interface took a primitive C type argument, which
resulted in inconsistent type conversions internally due to incorrect
dereferencing of types, especialy on 32-bit architectures.  This
change simplifies the TUNABLE setting logic along with the interfaces.

Now all numeric tunable values are stored as signed numbers in
tunable_num_t, which is intmax_t.  All calls to set tunables cast the
input value to its primitive type and then to tunable_num_t for
storage.  This relies on gcc-specific (although I suspect other
compilers woul also do the same) unsigned to signed integer conversion
semantics, i.e. the bit pattern is conserved.  The reverse conversion
is guaranteed by the standard.

(cherry picked from commit 61117bfa1b08ca048e6512c0652c568300fedf6a)

4 years agonsswitch: return result when nss database is locked [BZ #27343]
Sergei Trofimovich [Fri, 5 Feb 2021 07:32:18 +0000 (07:32 +0000)] 
nsswitch: return result when nss database is locked [BZ #27343]

Before the change nss_database_check_reload_and_get() did not populate
the '*result' value when it returned success in a case of chroot
detection. This caused initgroups() to use garage pointer in the
following test (extracted from unbound):

```

int main() {
    // load some NSS modules
    struct passwd * pw = getpwnam("root");

    chdir("/tmp");
    chroot("/tmp");
    chdir("/");
    // access nsswitch.conf in a chroot
    initgroups("root", 0);
}
```

Reviewed-by: DJ Delorie <dj@redhat.com>
4 years agoPrepare for glibc 2.33 release glibc-2.33
Adhemerval Zanella [Mon, 1 Feb 2021 16:46:41 +0000 (13:46 -0300)] 
Prepare for glibc 2.33 release

Update version.h, features.h, and ChangeLog.old/ChangeLog.22.

4 years agoUpdate NEWS with bugs
Adhemerval Zanella [Mon, 1 Feb 2021 16:44:05 +0000 (13:44 -0300)] 
Update NEWS with bugs

4 years agoUpdate translations
Adhemerval Zanella [Mon, 1 Feb 2021 17:09:36 +0000 (14:09 -0300)] 
Update translations

Add missing Serbian translation.

4 years agoNEWS: Fix typo in CVE-2021-3326 entry
Florian Weimer [Fri, 29 Jan 2021 17:20:54 +0000 (18:20 +0100)] 
NEWS: Fix typo in CVE-2021-3326 entry

4 years agoelf: Fix tests that rely on ld.so.cache for cross-compiling
Adhemerval Zanella [Fri, 29 Jan 2021 13:30:19 +0000 (10:30 -0300)] 
elf: Fix tests that rely on ld.so.cache for cross-compiling

For configurations with cross-compiling equal to 'maybe' or 'no',
ldconfig will not run and thus the ld.so.cache will not be created
on the container testroot.pristine.

This lead to failures on both tst-glibc-hwcaps-prepend-cache and
tst-ldconfig-ld_so_conf-update on environments where the same
compiler can be used to build different ABIs (powerpc and x86 for
instance).

This patch addas a new test-container hook, ldconfig.run, that
triggers a ldconfig execution prior the test execution.

Checked on x86_64-linux-gnu and i686-linux-gnu.

4 years agoNEWS: Mention CVE-2021-3326 (iconv assertion with ISO-20220-JP-3)
Florian Weimer [Fri, 29 Jan 2021 16:29:57 +0000 (17:29 +0100)] 
NEWS: Mention CVE-2021-3326 (iconv assertion with ISO-20220-JP-3)

4 years agoNEWS: Add entry for glibc-hwcaps and deprecate legacy hwcaps
Florian Weimer [Fri, 29 Jan 2021 16:26:18 +0000 (17:26 +0100)] 
NEWS: Add entry for glibc-hwcaps and deprecate legacy hwcaps

4 years agox86: Properly set usable CET feature bits [BZ #26625]
H.J. Lu [Wed, 27 Jan 2021 04:48:45 +0000 (20:48 -0800)] 
x86: Properly set usable CET feature bits [BZ #26625]

commit 94cd37ebb293321115a36a422b091fdb72d2fb08
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Sep 16 05:27:32 2020 -0700

    x86: Use HAS_CPU_FEATURE with IBT and SHSTK [BZ #26625]

broke

GLIBC_TUNABLES=glibc.cpu.hwcaps=-IBT,-SHSTK

since it can no longer disable IBT nor SHSTK.  Handle IBT and SHSTK with:

1. Revert commit 94cd37ebb293321115a36a422b091fdb72d2fb08.
2. Clears the usable CET feature bits if kernel doesn't support CET.
3. Add GLIBC_TUNABLES tests without dlopen.
4. Add tests to verify that CPU_FEATURE_USABLE on IBT and SHSTK matches
_get_ssp.
5. Update GLIBC_TUNABLES tests with dlopen to verify that CET is disabled
with GLIBC_TUNABLES.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
4 years agoUpdate translations
Adhemerval Zanella [Thu, 28 Jan 2021 16:45:09 +0000 (13:45 -0300)] 
Update translations

4 years agoUpdate libc.pot for 2.33 release
Adhemerval Zanella [Wed, 27 Jan 2021 20:09:23 +0000 (17:09 -0300)] 
Update libc.pot for 2.33 release

4 years agoUpdate ia64 libm-test-ulps
Adhemerval Zanella [Thu, 28 Jan 2021 13:32:53 +0000 (10:32 -0300)] 
Update ia64 libm-test-ulps

4 years agosh: Update libm-tests-ulps
Adhemerval Zanella [Thu, 28 Jan 2021 14:37:17 +0000 (11:37 -0300)] 
sh: Update libm-tests-ulps

4 years agoia64: Fix brk call on statup
Adhemerval Zanella [Thu, 28 Jan 2021 13:27:30 +0000 (10:27 -0300)] 
ia64: Fix brk call on statup

brk used by statup before TCB is properly set, so we can't use
IA64_USE_NEW_STUB.

This patch fixes a regression introduced by 720480934ab910.

Checked on ia64-linux-gnu.

4 years agoUpdate sparc libm-test-ulps
Adhemerval Zanella [Thu, 28 Jan 2021 11:44:11 +0000 (08:44 -0300)] 
Update sparc libm-test-ulps

4 years agoUpdate alpha libm-test-ulps
Adhemerval Zanella [Wed, 27 Jan 2021 20:23:28 +0000 (17:23 -0300)] 
Update alpha libm-test-ulps