]> git.ipfire.org Git - thirdparty/glibc.git/log
thirdparty/glibc.git
2 years agoaarch64: morello: string: dummy c strrchr
Szabolcs Nagy [Tue, 26 Apr 2022 07:19:24 +0000 (08:19 +0100)] 
aarch64: morello: string: dummy c strrchr

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

avoids out of bound access of the generic implementation.

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

avoids out of bounds access of the generic implementation.

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

Add macro definitions for purecap ABI in sysdep.h.

2 years agoTODO(gcc): cheri: work around a gcc bug in _dl_setup_stack_chk_guard
Szabolcs Nagy [Fri, 15 Jul 2022 18:33:23 +0000 (19:33 +0100)] 
TODO(gcc): cheri: work around a gcc bug in _dl_setup_stack_chk_guard

morello purecap gcc in some cases inlines 16byte memcpy as a capability
load, which is wrong if the source or dest may be unaligned.

stack guard only needs random for the address portion since only that
part is compared, so 8 byte is enough with 64 bit addresses, but the
current code is only right on little endian systems.

TODO: drop when gcc is fixed

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

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

2 years agocheri: headers: Define {u}intptr_t and {u}intcap_t for CHERI
Szabolcs Nagy [Fri, 11 Jun 2021 11:52:26 +0000 (12:52 +0100)] 
cheri: headers: Define {u}intptr_t and {u}intcap_t for CHERI

The CHERI pure capability programming model for C requires special
definition of {u}intptr_t.

Only the pure capability model is supported for hosted compilation,
but for freestanding compilation there is limited support for other
(hybrid capability) programming models too, which require new
{u}intcap_t type definitions.

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

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

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

There is no longer PLT reference to matherr in libm.

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

The base symbol version is 2.36.

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

2 years agoaarch64: morello: configure change for purecap abi
Szabolcs Nagy [Fri, 8 Apr 2022 15:27:01 +0000 (16:27 +0100)] 
aarch64: morello: configure change for purecap abi

Detect default-abi and add aarch64-purecap make variable.

Purecap abi sets HIDDEN_VAR_NEEDS_DYNAMIC_RELOC and unsets
SUPPORT_STATIC_PIE.

2 years agoaarch64: morello: Use separate lp64 and morello sysdep directories
Szabolcs Nagy [Tue, 26 Apr 2022 14:29:04 +0000 (15:29 +0100)] 
aarch64: morello: Use separate lp64 and morello sysdep directories

Provide separate directories for lp64 and purecap abi related sysdep
functionality.

purecap may be better name than morello, but we started with morello
and that is more future compatible with alternative cheri-like
extensions on top of aarch64.

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

aarch64-linux-gnu compiler is a lp64,purecap multilib gcc and
supported glibc variants:

  aarch64-linux-gnu
  aarch64-linux-gnu-purecap
  aarch64-linux-gnu-purecap-nopie

aarch64-linux-gnu_purecap compiler is a default purecap gcc, with
supported glibc variants:

  aarch64-linux-gnu_purecap
  aarch64-linux-gnu_purecap-nopie

purecap libgomp and libitm builds fail so disabled for now.

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

This simplifies adding the Morello purecap abi target.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

The test used scratch_buffer_dupfree incorrectly:

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

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

Run one test and avoid the issues above.

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

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

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

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

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

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

The code assumed unsigned long can represent pointers.

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

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

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

The alloca size did not consider the optional width parameter for
padding which could cause buffer underflow. The width is currently used
e.g. by _dl_map_object_from_fd which passes 2 * sizeof(void *) which
can be larger than the alloca buffer size on targets where
sizeof(void *) >= 2 * sizeof(unsigned long).

Even if large width is not used on existing targets it is better to fix
the formatting code to avoid surprises.

2 years agomalloc: Fix alignment logic in obstack
Szabolcs Nagy [Wed, 16 Mar 2022 14:07:04 +0000 (14:07 +0000)] 
malloc: Fix alignment logic in obstack

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

Use more robust alignment logic: this one should work on any target.
Note: this is an installed header so it must be namespace clean and
portable hence it uses unsigned long for the alignment offset.

2 years agomalloc: Use uintptr_t in alloc_buffer
Szabolcs Nagy [Wed, 16 Mar 2022 12:09:15 +0000 (12:09 +0000)] 
malloc: Use uintptr_t in alloc_buffer

The values represnt pointers and not sizes. The members of struct
alloc_buffer are already uintptr_t.

2 years agomalloc: Use uintptr_t for pointer alignment
Carlos Eduardo Seo [Wed, 26 Jan 2022 19:00:13 +0000 (16:00 -0300)] 
malloc: Use uintptr_t for pointer alignment

Avoid integer casts that assume unsigned long can represent pointers.

2 years agoUse uintptr_t in fts for pointer alignment
Szabolcs Nagy [Tue, 12 Jul 2022 09:59:16 +0000 (10:59 +0100)] 
Use uintptr_t in fts for pointer alignment

The code assumed unsigned long can represent pointers.

2 years agoFix invalid pointer dereference in wcpcpy_chk
Szabolcs Nagy [Tue, 21 Jun 2022 14:57:48 +0000 (15:57 +0100)] 
Fix invalid pointer dereference in wcpcpy_chk

The src pointer is const and points to a different object, so accessing
dest via src is invalid.

2 years agoFix invalid pointer dereference in wcscpy_chk
Szabolcs Nagy [Tue, 21 Jun 2022 13:43:30 +0000 (14:43 +0100)] 
Fix invalid pointer dereference in wcscpy_chk

The src pointer is const and points to a different object, so accessing
dest via src is invalid.

2 years agoaarch64: Fix the extension header write in getcontext and swapcontext
Szabolcs Nagy [Fri, 29 Jul 2022 07:00:06 +0000 (08:00 +0100)] 
aarch64: Fix the 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.

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

2 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

The initializer for a tunable_t set the bool initialized flag to NULL.
This causes a build failure when pointer to bool conversion warns.

2 years agoFix OOB read in stdlib thousand grouping parsing [BZ #29727]
Szabolcs Nagy [Tue, 11 Oct 2022 14:24:41 +0000 (15:24 +0100)] 
Fix OOB read in stdlib thousand grouping parsing [BZ #29727]

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

This affects scanf formats like %'d, %'f and the internal but
exposed __strto{l,ul,f,d,..}_internal with grouping flag set
and an LC_NUMERIC locale where thousands_len > 1.

Avoid OOB access by considering thousands_len when initializing cp.
This fixes bug 29727.

Found by the morello port with strict bounds checking where

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

crashed using a locale with thousands_len==3.

2 years agomath: Fix asin and acos invalid exception with old gcc
Szabolcs Nagy [Thu, 13 Oct 2022 10:10:10 +0000 (11:10 +0100)] 
math: Fix asin and acos invalid exception with old gcc

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

(x-x)/(x-x) is more robust against optimizations and works for all
out of bounds values including x==nan.

The gcc issue https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95115
should be fixed on release branches starting from gcc-10, but it is
better to change the code in case glibc is built with older gcc.

2 years agoelf: Reinstate on DL_DEBUG_BINDINGS _dl_lookup_symbol_x
Adhemerval Zanella [Tue, 25 Oct 2022 16:19:16 +0000 (13:19 -0300)] 
elf: Reinstate on DL_DEBUG_BINDINGS _dl_lookup_symbol_x

The prelink removal done by 6628c742b2c16e wrongly removed the debug
support.

Checked on x86_64-linux-gnu.

(cherry picked from commit 891a7958a28eac6d4af1517dd2896fef5e4951d4)

2 years agolinux: Fix generic struct_stat for 64 bit time (BZ# 29657)
Adhemerval Zanella [Wed, 19 Oct 2022 22:14:04 +0000 (19:14 -0300)] 
linux: Fix generic struct_stat for 64 bit time (BZ# 29657)

The generic Linux struct_stat misses the conditionals to use
bits/struct_stat_time64_helper.h in the __USE_TIME_BITS64 for
architecture that uses __TIMESIZE == 32 (currently csky and nios2).

Since newer ports should not support 32 bit time_t, the generic
implementation should be used as default.

For arm, hppa, and sh a copy of default struct_stat is added,
while for csky and nios a new one based on generic is used, along
with conditionals to use bits/struct_stat_time64_helper.h.

The default struct_stat is also replaced with the generic one.

Checked on aarch64-linux-gnu and arm-linux-gnueabihf.

(cherry picked from commit 7a6ca82f8007ddbd43e2b8fce806ba7101ee47f5)

2 years agoAvoid undefined behaviour in ibm128 implementation of llroundl (BZ #29488)
Aurelien Jarno [Sun, 9 Oct 2022 22:39:33 +0000 (00:39 +0200)] 
Avoid undefined behaviour in ibm128 implementation of llroundl (BZ #29488)

Detecting an overflow edge case depended on signed overflow of a long
long. Replace the additions and the overflow checks by
__builtin_add_overflow().

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

2 years agoFix BZ #29463 in the ibm128 implementation of y1l too
Michael Hudson-Doyle [Mon, 22 Aug 2022 02:05:04 +0000 (14:05 +1200)] 
Fix BZ #29463 in the ibm128 implementation of y1l too

Avoid moving code across SET_RESTORE_ROUNDL in order to fix
[BZ #29463].

Tested-by: Aurelien Jarno <aurelien@aurel32.net>
Reviewed-by: Aurelien Jarno <aurelien@aurel32.net>
Reviewed-by: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
(cherry picked from commit b6e37b7805b0182c3e25cdab39ebf5f001c04d05)

2 years agoelf: Do not completely clear reused namespace in dlmopen (bug 29600)
Florian Weimer [Fri, 14 Oct 2022 09:02:25 +0000 (11:02 +0200)] 
elf: Do not completely clear reused namespace in dlmopen (bug 29600)

The data in the _ns_debug member must be preserved, otherwise
_dl_debug_initialize enters an infinite loop.  To be conservative,
only clear the libc_map member for now, to fix bug 29528.

Fixes commit d0e357ff45a75553dee3b17ed7d303bfa544f6fe
("elf: Call __libc_early_init for reused namespaces (bug 29528)"),
by reverting most of it.

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

2 years agonss: Use shared prefix in IPv4 address in tst-reload1
Florian Weimer [Fri, 23 Sep 2022 17:30:57 +0000 (19:30 +0200)] 
nss: Use shared prefix in IPv4 address in tst-reload1

Otherwise, sorting based on the longest-matching prefix in
getaddrinfo can reorder the addresses in ways the test does not
expect, depending on the IPv4 address of the host.

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

2 years agonss: Fix tst-nss-files-hosts-long on single-stack hosts (bug 24816)
Florian Weimer [Tue, 13 Sep 2022 14:11:40 +0000 (16:11 +0200)] 
nss: Fix tst-nss-files-hosts-long on single-stack hosts (bug 24816)

getent implicitly passes AI_ADDRCONFIG to getaddrinfo by default.
Use --no-addrconfig to suppress that, so that both IPv4 and IPv6
lookups succeed even if the address family is not supported by the
host.

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

2 years agonss: Implement --no-addrconfig option for getent
Florian Weimer [Tue, 13 Sep 2022 14:10:20 +0000 (16:10 +0200)] 
nss: Implement --no-addrconfig option for getent

The ahosts, ahostsv4, ahostsv6 commands unconditionally pass
AI_ADDRCONFIG to getaddrinfo, which is not always desired.

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

2 years agoEnsure calculations happen with desired rounding mode in y1lf128
Michael Hudson-Doyle [Thu, 11 Aug 2022 23:29:31 +0000 (11:29 +1200)] 
Ensure calculations happen with desired rounding mode in y1lf128

math/test-float128-y1 fails on x86_64 and ppc64el with gcc 12 and -O3,
because code inside a block guarded by SET_RESTORE_ROUNDL is being moved
after the rounding mode has been restored. Use math_force_eval to
prevent this (and insert some math_opt_barrier calls to prevent code
from being moved before the rounding mode is set).

Fixes #29463

Reviewed-By: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
(cherry picked from commit 2b274fd8c9c776cf70fcdb8356e678ada522a7b0)

2 years agonscd: Drop local address tuple variable [BZ #29607]
Siddhesh Poyarekar [Tue, 4 Oct 2022 22:43:50 +0000 (18:43 -0400)] 
nscd: Drop local address tuple variable [BZ #29607]

When a request needs to be resent (e.g. due to insufficient buffer
space), the references to subsequent tuples in the local variable are
stale and should not be used.  This used to work by accident before, but
since 1d495912a it no longer does.  Instead of trying to reset it, just
let gethostbyname4_r write into TUMPBUF6 for us, thus maintaining a
consistent state at all times.  This is now consistent with what is done
in gaih_inet for getaddrinfo.

Resolves: BZ #29607
Reported-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
(cherry picked from commit 6e33e5c4b73cea7b8aa3de0947123db16200fb65)

2 years agox86-64: Require BMI1/BMI2 for AVX2 strrchr and wcsrchr implementations
Aurelien Jarno [Mon, 3 Oct 2022 21:46:11 +0000 (23:46 +0200)] 
x86-64: Require BMI1/BMI2 for AVX2 strrchr and wcsrchr implementations

The AVX2 strrchr and wcsrchr implementation uses the 'blsmsk'
instruction which belongs to the BMI1 CPU feature and the 'shrx'
instruction, which belongs to the BMI2 CPU feature.

Fixes: df7e295d18ff ("x86: Optimize {str|wcs}rchr-avx2")
Partially resolves: BZ #29611

Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
(cherry picked from commit 7e8283170c5d6805b609a040801d819e362a6292)

2 years agox86-64: Require BMI2 and LZCNT for AVX2 memrchr implementation
Aurelien Jarno [Mon, 3 Oct 2022 21:46:11 +0000 (23:46 +0200)] 
x86-64: Require BMI2 and LZCNT for AVX2 memrchr implementation

The AVX2 memrchr implementation uses the 'shlxl' instruction, which
belongs to the BMI2 CPU feature and uses the 'lzcnt' instruction, which
belongs to the LZCNT CPU feature.

Fixes: af5306a735eb ("x86: Optimize memrchr-avx2.S")
Partially resolves: BZ #29611

Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
(cherry picked from commit 3c0c78afabfed4b6fc161c159e628fbf14ff370b)

2 years agox86-64: Require BMI2 for AVX2 (raw|w)memchr implementations
Aurelien Jarno [Mon, 3 Oct 2022 21:46:11 +0000 (23:46 +0200)] 
x86-64: Require BMI2 for AVX2 (raw|w)memchr implementations

The AVX2 memchr, rawmemchr and wmemchr implementations use the 'bzhi'
and 'sarx' instructions, which belongs to the BMI2 CPU feature.

Fixes: acfd088a1963 ("x86: Optimize memchr-avx2.S")
Partially resolves: BZ #29611

Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
(cherry picked from commit e3e7fab7fe5186d18ca2046d99ba321c27db30ad)

2 years agox86-64: Require BMI2 for AVX2 wcs(n)cmp implementations
Aurelien Jarno [Mon, 3 Oct 2022 21:46:11 +0000 (23:46 +0200)] 
x86-64: Require BMI2 for AVX2 wcs(n)cmp implementations

The AVX2 wcs(n)cmp implementations use the 'bzhi' instruction, which
belongs to the BMI2 CPU feature.

NB: It also uses the 'tzcnt' BMI1 instruction, but it is executed as BSF
as BSF if the CPU doesn't support TZCNT, and produces the same result
for non-zero input.

Partially fixes: b77b06e0e296 ("x86: Optimize strcmp-avx2.S")
Partially resolves: BZ #29611

Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
(cherry picked from commit f31a5a884ed84bd37032729d4d1eb9d06c9f3c29)

2 years agox86-64: Require BMI2 for AVX2 strncmp implementation
Aurelien Jarno [Mon, 3 Oct 2022 21:46:11 +0000 (23:46 +0200)] 
x86-64: Require BMI2 for AVX2 strncmp implementation

The AVX2 strncmp implementations uses the 'bzhi' instruction, which
belongs to the BMI2 CPU feature.

NB: It also uses the 'tzcnt' BMI1 instruction, but it is executed as BSF
as BSF if the CPU doesn't support TZCNT, and produces the same result
for non-zero input.

Partially fixes: b77b06e0e296 ("x86: Optimize strcmp-avx2.S")
Partially resolves: BZ #29611

Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
(cherry picked from commit fc7de1d9b99ae1676bc626ddca422d7abee0eb48)

2 years agox86-64: Require BMI2 for AVX2 strcmp implementation
Aurelien Jarno [Mon, 3 Oct 2022 21:46:11 +0000 (23:46 +0200)] 
x86-64: Require BMI2 for AVX2 strcmp implementation

The AVX2 strcmp implementation uses the 'bzhi' instruction, which
belongs to the BMI2 CPU feature.

NB: It also uses the 'tzcnt' BMI1 instruction, but it is executed as BSF
as BSF if the CPU doesn't support TZCNT, and produces the same result
for non-zero input.

Partially fixes: b77b06e0e296 ("x86: Optimize strcmp-avx2.S")
Partially resolves: BZ #29611

Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
(cherry picked from commit 4d64c6445735e9b34e2ac8e369312cbfc2f88e17)

2 years agox86-64: Require BMI2 for AVX2 str(n)casecmp implementations
Aurelien Jarno [Mon, 3 Oct 2022 21:46:11 +0000 (23:46 +0200)] 
x86-64: Require BMI2 for AVX2 str(n)casecmp implementations

The AVX2 str(n)casecmp implementations use the 'bzhi' instruction, which
belongs to the BMI2 CPU feature.

NB: It also uses the 'tzcnt' BMI1 instruction, but it is executed as BSF
as BSF if the CPU doesn't support TZCNT, and produces the same result
for non-zero input.

Partially fixes: b77b06e0e296 ("x86: Optimize strcmp-avx2.S")
Partially resolves: BZ #29611

Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
(cherry picked from commit 10f79d3670b036925da63dc532b122d27ce65ff8)

2 years agox86: include BMI1 and BMI2 in x86-64-v3 level
Aurelien Jarno [Mon, 3 Oct 2022 21:46:11 +0000 (23:46 +0200)] 
x86: include BMI1 and BMI2 in x86-64-v3 level

The "System V Application Binary Interface AMD64 Architecture Processor
Supplement" mandates the BMI1 and BMI2 CPU features for the x86-64-v3
level.

Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
(cherry picked from commit b80f16adbd979831bf25ea491e1261e81885c2b6)

2 years agohppa: undef __ASSUME_SET_ROBUST_LIST
John David Anglin [Tue, 20 Sep 2022 20:14:14 +0000 (20:14 +0000)] 
hppa: undef __ASSUME_SET_ROBUST_LIST

QEMU does not support support set_robust_list. Thus, we need
to enable detection of set_robust_list system call.

Signed-off-by: John David Anglin <dave.anglin@bell.net>
2 years agohppa: Fix initialization of dp register [BZ 29635]
John David Anglin [Sat, 1 Oct 2022 19:49:25 +0000 (19:49 +0000)] 
hppa: Fix initialization of dp register [BZ 29635]

After upgrading glibc to Debian 2.35-1, gdb faulted on
startup and dropped core in a function call in the main
application.  This was caused by not initializing the
global dp register for the main application early enough.

Restore the code to initialize dp in _dl_start_user.
It was removed when code was added to initialize dp in
elf_machine_runtime_setup.

Signed-off-by: John David Anglin <dave.anglin@bell.net>
2 years agostdlib: Fix __getrandom_nocancel type and arc4random usage (BZ #29638)
Adhemerval Zanella [Thu, 29 Sep 2022 19:15:20 +0000 (16:15 -0300)] 
stdlib: Fix __getrandom_nocancel type and arc4random usage (BZ #29638)

Using an unsigned type prevents the fallback to be used if kernel
does not support getrandom syscall.

Checked on x86_64-linux-gnu.

Reviewed-by: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
(cherry picked from commit 13db9ee2cb3b77e25f852be7d6952882e1be6f00)

2 years agoget_nscd_addresses: Fix subscript typos [BZ #29605]
Jörg Sonnenberger [Mon, 26 Sep 2022 17:59:16 +0000 (13:59 -0400)] 
get_nscd_addresses: Fix subscript typos [BZ #29605]

Fix the subscript on air->family, which was accidentally set to COUNT
when it should have remained as I.

Resolves: BZ #29605

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

2 years agom68k: Enforce 4-byte alignment on internal locks (BZ #29537)
Adhemerval Zanella [Tue, 30 Aug 2022 13:33:15 +0000 (10:33 -0300)] 
m68k: Enforce 4-byte alignment on internal locks (BZ #29537)

A new internal definition, __LIBC_LOCK_ALIGNMENT, is used to force
the 4-byte alignment only for m68k, other architecture keep the
natural alignment of the type used internally (and hppa does not
require 16-byte alignment for kernel-assisted CAS).

Reviewed-by: Florian Weimer <fweimer@redhat.com>
(cherry picked from commit aeb4d2e9815d459e2640a31f5abb8ef803830107)

2 years agogconv: Use 64-bit interfaces in gconv_parseconfdir (bug 29583)
Florian Weimer [Tue, 20 Sep 2022 10:12:43 +0000 (12:12 +0200)] 
gconv: Use 64-bit interfaces in gconv_parseconfdir (bug 29583)

It's possible that inode numbers are outside the 32-bit range.
The existing code only handles the in-libc case correctly, and
still uses the legacy interfaces when building iconv.

Suggested-by: Helge Deller <deller@gmx.de>
(cherry picked from commit f97905f24631097af325d6a231093071c3077a5f)

2 years agoelf: Implement force_first handling in _dl_sort_maps_dfs (bug 28937)
Florian Weimer [Tue, 20 Sep 2022 09:00:42 +0000 (11:00 +0200)] 
elf: Implement force_first handling in _dl_sort_maps_dfs (bug 28937)

The implementation in _dl_close_worker requires that the first
element of l_initfini is always this very map (“We are always the
zeroth entry, and since we don't include ourselves in the
dependency analysis start at 1.”).  Rather than fixing that
assumption, this commit adds an implementation of the force_first
argument to the new dependency sorting algorithm.  This also means
that the directly dlopen'ed shared object is always initialized last,
which is the least surprising behavior in the presence of cycles.

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

2 years agoelf: Rename _dl_sort_maps parameter from skip to force_first
Florian Weimer [Tue, 6 Sep 2022 05:38:10 +0000 (07:38 +0200)] 
elf: Rename _dl_sort_maps parameter from skip to force_first

The new implementation will not be able to skip an arbitrary number
of objects.

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

2 years agoscripts/dso-ordering-test.py: Generate program run-time dependencies
Florian Weimer [Tue, 6 Sep 2022 05:38:10 +0000 (07:38 +0200)] 
scripts/dso-ordering-test.py: Generate program run-time dependencies

The main program needs to depend on all shared objects, even objects
that have link-time dependencies among shared objects.  Filtering
out shared objects that already have an link-time dependencies is not
necessary here; make will do this automatically.

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

2 years agoelf: Fix hwcaps string size overestimation
Javier Pello [Mon, 5 Sep 2022 18:09:01 +0000 (20:09 +0200)] 
elf: Fix hwcaps string size overestimation

Commit dad90d528259b669342757c37dedefa8577e2636 added glibc-hwcaps
support for LD_LIBRARY_PATH and, for this, it adjusted the total
string size required in _dl_important_hwcaps. However, in doing so
it inadvertently altered the calculation of the size required for
the power set strings, as the computation of the power set string
size depended on the first value assigned to the total variable,
which is later shifted, resulting in overallocation of string
space. Fix this now by using a different variable to hold the
string size required for glibc-hwcaps.

Signed-off-by: Javier Pello <devel@otheo.eu>
(cherry picked from commit a23820f6052a740246fdc7dcd9c43ce8eed0c45a)

2 years agoelf: Run tst-audit-tlsdesc, tst-audit-tlsdesc-dlopen everywhere
Florian Weimer [Tue, 13 Sep 2022 17:57:43 +0000 (19:57 +0200)] 
elf: Run tst-audit-tlsdesc, tst-audit-tlsdesc-dlopen everywhere

The test is valid for all TLS models, but we want to make a reasonable
effort to test the GNU2 model specifically.  For example, aarch64
defaults to GNU2, but does not have -mtls-dialect=gnu2, and the test
was not run there.

Suggested-by: Martin Coufal <mcoufal@redhat.com>
(cherry picked from commit dd2315a866a4ac2b838ea1cb10c5ea1c35d51a2f)

Fixes early backport commit 924e4f3eaa502ce82fccf8537f021a796d158771
("elf: Call __libc_early_init for reused namespaces (bug 29528)");
it had a wrong conflict resolution.

2 years agoNEWS: Note bug 12154 and bug 29305 as fixed
Florian Weimer [Tue, 13 Sep 2022 11:22:27 +0000 (13:22 +0200)] 
NEWS: Note bug 12154 and bug 29305 as fixed

2 years agoresolv: Fix building tst-resolv-invalid-cname for earlier C standards
Florian Weimer [Tue, 30 Aug 2022 11:30:03 +0000 (13:30 +0200)] 
resolv: Fix building tst-resolv-invalid-cname for earlier C standards

This fixes this compiler error:

tst-resolv-invalid-cname.c: In function ‘test_mode_to_string’:
tst-resolv-invalid-cname.c:164:10: error: label at end of compound statement
     case test_mode_num:
          ^~~~~~~~~~~~~

Fixes commit 9caf782276ecea4bc86fc94fbb52779736f3106d
("resolv: Add new tst-resolv-invalid-cname").

(cherry picked from commit d09aa4a17229bcaa2ec7642006b12612498582e7)

2 years agonss_dns: Rewrite _nss_dns_gethostbyname4_r using current interfaces
Florian Weimer [Tue, 30 Aug 2022 08:02:49 +0000 (10:02 +0200)] 
nss_dns: Rewrite _nss_dns_gethostbyname4_r using current interfaces

Introduce struct alloc_buffer to this function, and use it and
struct ns_rr_cursor in gaih_getanswer_slice.  Adjust gaih_getanswer
and gaih_getanswer_noaaaa accordingly.

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

2 years agoresolv: Add new tst-resolv-invalid-cname
Florian Weimer [Tue, 30 Aug 2022 08:02:49 +0000 (10:02 +0200)] 
resolv: Add new tst-resolv-invalid-cname

This test checks resolution through CNAME chains that do not contain
host names (bug 12154).

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

2 years agonss_dns: In gaih_getanswer_slice, skip strange aliases (bug 12154)
Florian Weimer [Tue, 30 Aug 2022 08:02:49 +0000 (10:02 +0200)] 
nss_dns: In gaih_getanswer_slice, skip strange aliases (bug 12154)

If the name is not a host name, skip adding it to the result, instead
of reporting query failure.  This fixes bug 12154 for getaddrinfo.

This commit still keeps the old parsing code, and only adjusts when
a host name is copied.

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

2 years agonss_dns: Rewrite getanswer_r to match getanswer_ptr (bug 12154, bug 29305)
Florian Weimer [Tue, 30 Aug 2022 08:02:49 +0000 (10:02 +0200)] 
nss_dns: Rewrite getanswer_r to match getanswer_ptr (bug 12154, bug 29305)

Allocate the pointer arrays only at the end, when their sizes
are known.  This addresses bug 29305.

Skip over invalid names instead of failing lookups.  This partially
fixes bug 12154 (for gethostbyname, fixing getaddrinfo requires
different changes).

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

2 years agonss_dns: Remove remnants of IPv6 address mapping
Florian Weimer [Tue, 30 Aug 2022 08:02:49 +0000 (10:02 +0200)] 
nss_dns: Remove remnants of IPv6 address mapping

res_use_inet6 always returns false since commit 3f8b44be0a658266adff5
("resolv: Remove support for RES_USE_INET6 and the inet6 option").

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

2 years agonss_dns: Rewrite _nss_dns_gethostbyaddr2_r and getanswer_ptr
Florian Weimer [Tue, 30 Aug 2022 08:02:49 +0000 (10:02 +0200)] 
nss_dns: Rewrite _nss_dns_gethostbyaddr2_r and getanswer_ptr

The simplification takes advantage of the split from getanswer_r.
It fixes various aliases issues, and optimizes NSS buffer usage.
The new DNS packet parsing helpers are used, too.

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

2 years agonss_dns: Split getanswer_ptr from getanswer_r
Florian Weimer [Tue, 30 Aug 2022 08:02:49 +0000 (10:02 +0200)] 
nss_dns: Split getanswer_ptr from getanswer_r

And expand the use of name_ok and qtype in getanswer_ptr (the
former also in getanswer_r).

After further cleanups, not much code will be shared between the
two functions.

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

2 years agoresolv: Add DNS packet parsing helpers geared towards wire format
Florian Weimer [Tue, 30 Aug 2022 08:02:49 +0000 (10:02 +0200)] 
resolv: Add DNS packet parsing helpers geared towards wire format

The public parser functions around the ns_rr record type produce
textual domain names, but usually, this is not what we need while
parsing DNS packets within glibc.  This commit adds two new helper
functions, __ns_rr_cursor_init and __ns_rr_cursor_next, for writing
packet parsers, and struct ns_rr_cursor, struct ns_rr_wire as
supporting types.

In theory, it is possible to avoid copying the owner name
into the rname field in __ns_rr_cursor_next, but this would need
more functions that work on compressed names.

Eventually, __res_context_send could be enhanced to preserve the
result of the packet parsing that is necessary for matching the
incoming UDP packets, so that this works does not have to be done
twice.

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

2 years agoresolv: Add internal __ns_name_length_uncompressed function
Florian Weimer [Tue, 30 Aug 2022 08:02:49 +0000 (10:02 +0200)] 
resolv: Add internal __ns_name_length_uncompressed function

This function is useful for checking that the question name is
uncompressed (as it should be).

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

2 years agoresolv: Add the __ns_samebinaryname function
Florian Weimer [Tue, 30 Aug 2022 08:02:49 +0000 (10:02 +0200)] 
resolv: Add the __ns_samebinaryname function

During packet parsing, only the binary name is available.  If the name
equality check is performed before conversion to text, we can sometimes
skip the last step.

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

2 years agoresolv: Add internal __res_binary_hnok function
Florian Weimer [Tue, 30 Aug 2022 08:02:49 +0000 (10:02 +0200)] 
resolv: Add internal __res_binary_hnok function

During package parsing, only the binary representation is available,
and it is convenient to check that directly for conformance with host
name requirements.

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

2 years agoresolv: Add tst-resolv-aliases
Florian Weimer [Tue, 30 Aug 2022 08:02:49 +0000 (10:02 +0200)] 
resolv: Add tst-resolv-aliases

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

2 years agoresolv: Add tst-resolv-byaddr for testing reverse lookup
Florian Weimer [Tue, 30 Aug 2022 08:02:49 +0000 (10:02 +0200)] 
resolv: Add tst-resolv-byaddr for testing reverse lookup

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

2 years agonscd: Fix netlink cache invalidation if epoll is used [BZ #29415]
Fabian Vogt [Wed, 27 Jul 2022 09:44:07 +0000 (11:44 +0200)] 
nscd: Fix netlink cache invalidation if epoll is used [BZ #29415]

Processes cache network interface information such as whether IPv4 or IPv6
are enabled. This is only checked again if the "netlink timestamp" provided
by nscd changed, which is triggered by netlink socket activity.

However, in the epoll handler for the netlink socket, it was missed to
assign the new timestamp to the nscd database. The handler for plain poll
did that properly, copy that over.

This bug caused that e.g. processes which started before network
configuration got unusuable addresses from getaddrinfo, like IPv6 only even
though only IPv4 is available:
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1041

It's a bit hard to reproduce, so I verified this by checking the timestamp
on calls to __check_pf manually. Without this patch it's stuck at 1, now
it's increasing on network changes as expected.

Signed-off-by: Fabian Vogt <fvogt@suse.de>
(cherry picked from commit 02ca25fef2785974011e9c5beecc99b900b69fd7)

2 years agoAdd NEWS entry for CVE-2022-39046
Siddhesh Poyarekar [Tue, 6 Sep 2022 13:31:50 +0000 (09:31 -0400)] 
Add NEWS entry for CVE-2022-39046

(cherry picked from commit 76fe56020e7ef354685b2284580ac1630c078a2b)

2 years agosyslog: Remove extra whitespace between timestamp and message (BZ#29544)
Adhemerval Zanella [Mon, 5 Sep 2022 12:34:39 +0000 (09:34 -0300)] 
syslog: Remove extra whitespace between timestamp and message (BZ#29544)

The rfc3164 clear states that a single space character must follow
the timestamp field.

Checked on x86_64-linux-gnu.

2 years agoelf: Restore how vDSO dependency is printed with LD_TRACE_LOADED_OBJECTS (BZ #29539)
Adhemerval Zanella [Tue, 30 Aug 2022 16:35:52 +0000 (13:35 -0300)] 
elf: Restore how vDSO dependency is printed with LD_TRACE_LOADED_OBJECTS (BZ #29539)

The d7703d3176d225d5743b21811d888619eba39e82 changed how vDSO like
dependencies are printed, instead of just the name and address it
follows other libraries mode and prints 'name => path'.

Unfortunately, this broke some ldd consumer that uses the output to
filter out the program's dependencies.  For instance CMake
bundleutilities module [1], where GetPrequirite uses the regex to filter
out 'name => path' [2].

This patch restore the previous way to print just the name and the
mapping address.

Checked on x86_64-linux-gnu.

[1] https://github.com/Kitware/CMake/tree/master/Tests/BundleUtilities
[2] https://github.com/Kitware/CMake/blob/master/Modules/GetPrerequisites.cmake#L733

Reviewed-by: Florian Weimer <fweimer@redhat.com>
(cherry picked from commit 1e903124cec4492463d075c6c061a2a772db77bf)

2 years agoApply asm redirections in wchar.h before first use
Raphael Moreira Zinsly [Wed, 24 Aug 2022 14:43:37 +0000 (11:43 -0300)] 
Apply asm redirections in wchar.h before first use

Similar to d0fa09a770, but for wchar.h.  Fixes [BZ #27087] by applying
all long double related asm redirections before using functions in
bits/wchar2.h.
Moves the function declarations from wcsmbs/bits/wchar2.h to a new file
wcsmbs/bits/wchar2-decl.h that will be included first in wcsmbs/wchar.h.

Tested with build-many-glibcs.py.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
(cherry picked from commit c7509d49c4e8fa494120c5ead21338559dad16f5)

2 years agoelf: Call __libc_early_init for reused namespaces (bug 29528)
Florian Weimer [Fri, 26 Aug 2022 19:15:43 +0000 (21:15 +0200)] 
elf: Call __libc_early_init for reused namespaces (bug 29528)

libc_map is never reset to NULL, neither during dlclose nor on a
dlopen call which reuses the namespace structure.  As a result, if a
namespace is reused, its libc is not initialized properly.  The most
visible result is a crash in the <ctype.h> functions.

To prevent similar bugs on namespace reuse from surfacing,
unconditionally initialize the chosen namespace to zero using memset.

(cherry picked from commit d0e357ff45a75553dee3b17ed7d303bfa544f6fe)

2 years agosyslog: Fix large messages (BZ#29536)
Adhemerval Zanella [Sun, 28 Aug 2022 19:52:53 +0000 (16:52 -0300)] 
syslog: Fix large messages (BZ#29536)

The a583b6add407c17cd change did not handle large messages that
would require a heap allocation correctly, where the message itself
is not take in consideration.

This patch fixes it and extend the tst-syslog to check for large
messages as well.

Checked on x86_64-linux-gnu.

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

2 years agoLinux: Fix enum fsconfig_command detection in <sys/mount.h>
Florian Weimer [Tue, 16 Aug 2022 07:25:23 +0000 (09:25 +0200)] 
Linux: Fix enum fsconfig_command detection in <sys/mount.h>

The #ifdef FSOPEN_CLOEXEC check did not work because the macro
was always defined in this header prior to the check, so that
the <linux/mount.h> contents did not matter.

Fixes commit 774058d72942249f71d74e7f2b639f77184160a6
("linux: Fix sys/mount.h usage with kernel headers").

(cherry picked from commit 2955ef4b7c9b56fcd7abfeddef7ee83c60abff98)

2 years agolinux: Fix sys/mount.h usage with kernel headers
Adhemerval Zanella [Wed, 10 Aug 2022 17:24:47 +0000 (14:24 -0300)] 
linux: Fix sys/mount.h usage with kernel headers

Now that kernel exports linux/mount.h and includes it on linux/fs.h,
its definitions might clash with glibc exports sys/mount.h.  To avoid
the need to rearrange the Linux header to be always after glibc one,
the glibc sys/mount.h is changed to:

  1. Undefine the macros also used as enum constants.  This covers prior
     inclusion of <linux/mount.h> (for instance MS_RDONLY).

  2. Include <linux/mount.h> based on the usual __has_include check
     (needs to use __has_include ("linux/mount.h") to paper over GCC
     bugs.

  3. Define enum fsconfig_command only if FSOPEN_CLOEXEC is not defined.
     (FSOPEN_CLOEXEC should be a very close proxy.)

  4. Define struct mount_attr if MOUNT_ATTR_SIZE_VER0 is not defined.
     (Added in the same commit on the Linux side.)

This patch also adds some tests to check if including linux/fs.h and
linux/mount.h after and before sys/mount.h does work.

Checked on x86_64-linux-gnu.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
(cherry picked from commit 774058d72942249f71d74e7f2b639f77184160a6)

2 years agolinux: Use compile_c_snippet to check linux/mount.h availability
Adhemerval Zanella [Wed, 10 Aug 2022 17:24:46 +0000 (14:24 -0300)] 
linux: Use compile_c_snippet to check linux/mount.h availability

Checked on x86_64-linux-gnu.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
(cherry picked from commit e1226cdc6b209539a92d32d5b620ba53fd35abf3)

2 years agolinux: Mimic kernel defition for BLOCK_SIZE
Adhemerval Zanella [Wed, 10 Aug 2022 17:24:45 +0000 (14:24 -0300)] 
linux: Mimic kernel defition for BLOCK_SIZE

To avoid possible warnings if the kernel header is included before
sys/mount.h.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
(cherry picked from commit c68b6044bc7945716431f1adc091b17c39b80a06)

2 years agolinux: Use compile_c_snippet to check linux/pidfd.h availability
Adhemerval Zanella [Wed, 10 Aug 2022 17:24:44 +0000 (14:24 -0300)] 
linux: Use compile_c_snippet to check linux/pidfd.h availability

Instead of tying to a specific kernel version.

Checked on x86_64-linux-gnu.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
(cherry picked from commit 1542019b69b7ec7b2cd34357af035e406d153631)

2 years agoglibcextract.py: Add compile_c_snippet
Adhemerval Zanella [Wed, 10 Aug 2022 19:24:06 +0000 (16:24 -0300)] 
glibcextract.py: Add compile_c_snippet

It might be used on tests to check if a snippet build with the provided
compiler and flags.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
(cherry picked from commit 841afa116e32b3c7195475769c26bf46fd870d32)

2 years agoNEWS: Add entry for bug 28846
Arjun Shankar [Mon, 22 Aug 2022 16:21:14 +0000 (18:21 +0200)] 
NEWS: Add entry for bug 28846

2 years agosocket: Check lengths before advancing pointer in CMSG_NXTHDR
Arjun Shankar [Tue, 2 Aug 2022 09:10:25 +0000 (11:10 +0200)] 
socket: Check lengths before advancing pointer in CMSG_NXTHDR

The inline and library functions that the CMSG_NXTHDR macro may expand
to increment the pointer to the header before checking the stride of
the increment against available space.  Since C only allows incrementing
pointers to one past the end of an array, the increment must be done
after a length check.  This commit fixes that and includes a regression
test for CMSG_FIRSTHDR and CMSG_NXTHDR.

The Linux, Hurd, and generic headers are all changed.

Tested on Linux on armv7hl, i686, x86_64, aarch64, ppc64le, and s390x.

[BZ #28846]

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

2 years agoalpha: Fix generic brk system call emulation in __brk_call (bug 29490)
Florian Weimer [Mon, 22 Aug 2022 09:04:47 +0000 (11:04 +0200)] 
alpha: Fix generic brk system call emulation in __brk_call (bug 29490)

The kernel special-cases the zero argument for alpha brk, and we can
use that to restore the generic Linux error handling behavior.

Fixes commit b57ab258c1140bc45464b4b9908713e3e0ee35aa ("Linux:
Introduce __brk_call for invoking the brk system call").

(cherry picked from commit e7ad26ee3cb74e61d0637c888f24dd478d77af58)