]> git.ipfire.org Git - thirdparty/glibc.git/log
thirdparty/glibc.git
3 years agoFix elf/tst-audit25a with default bind now toolchains codonell/ld-audit
Szabolcs Nagy [Wed, 2 Feb 2022 14:03:58 +0000 (14:03 +0000)] 
Fix elf/tst-audit25a with default bind now toolchains

This test relies on lazy binding for the executable so request that
explicitly in case the toolchain defaults to bind now.

(cherry picked from commit 80a08d0faa9b224019f895800c4d97de4e23e1aa)

3 years agoelf: Fix runtime linker auditing on aarch64 (BZ #26643)
Ben Woodard [Mon, 24 Jan 2022 13:46:18 +0000 (10:46 -0300)] 
elf: Fix runtime linker auditing on aarch64 (BZ #26643)

The rtld audit support show two problems on aarch64:

  1. _dl_runtime_resolve does not preserve x8, the indirect result
      location register, which might generate wrong result calls
      depending of the function signature.

  2. The NEON Q registers pushed onto the stack by _dl_runtime_resolve
     were twice the size of D registers extracted from the stack frame by
     _dl_runtime_profile.

While 2. might result in wrong information passed on the PLT tracing,
1. generates wrong runtime behaviour.

The aarch64 rtld audit support is changed to:

  * Both La_aarch64_regs and La_aarch64_retval are expanded to include
    both x8 and the full sized NEON V registers, as defined by the
    ABI.

  * dl_runtime_profile needed to extract registers saved by
    _dl_runtime_resolve and put them into the new correctly sized
    La_aarch64_regs structure.

  * The LAV_CURRENT check is change to only accept new audit modules
    to avoid the undefined behavior of not save/restore x8.

  * Different than other architectures, audit modules older than
    LAV_CURRENT are rejected (both La_aarch64_regs and La_aarch64_retval
    changed their layout and there are no requirements to support multiple
    audit interface with the inherent aarch64 issues).

  * A new field is also reserved on both La_aarch64_regs and
    La_aarch64_retval to support variant pcs symbols.

Similar to x86, a new La_aarch64_vector type to represent the NEON
register is added on the La_aarch64_regs (so each type can be accessed
directly).

Since LAV_CURRENT was already bumped to support bind-now, there is
no need to increase it again.

Checked on aarch64-linux-gnu.

Co-authored-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
(cherry picked from commit ce9a68c57c260c8417afc93972849ac9ad243ec4)

Resolved conflicts:
NEWS
elf/rtld.c

3 years agoelf: Issue la_symbind for bind-now (BZ #23734)
Adhemerval Zanella [Mon, 24 Jan 2022 13:46:17 +0000 (10:46 -0300)] 
elf: Issue la_symbind for bind-now (BZ #23734)

The audit symbind callback is not called for binaries built with
-Wl,-z,now or when LD_BIND_NOW=1 is used, nor the PLT tracking callbacks
(plt_enter and plt_exit) since this would change the expected
program semantics (where no PLT is expected) and would have performance
implications (such as for BZ#15533).

LAV_CURRENT is also bumped to indicate the audit ABI change (where
la_symbind flags are set by the loader to indicate no possible PLT
trace).

To handle powerpc64 ELFv1 function descriptor, _dl_audit_symbind
requires to know whether bind-now is used so the symbol value is
updated to function text segment instead of the OPD (for lazy binding
this is done by PPC64_LOAD_FUNCPTR on _dl_runtime_resolve).

Checked on x86_64-linux-gnu, i686-linux-gnu, aarch64-linux-gnu,
powerpc64-linux-gnu.

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

Resolved conflicts:
NEWS

3 years agoelf: Move LAV_CURRENT to link_lavcurrent.h
Adhemerval Zanella [Thu, 29 Jul 2021 14:13:57 +0000 (11:13 -0300)] 
elf: Move LAV_CURRENT to link_lavcurrent.h

No functional change.

(cherry picked from commit 54816ae98d57930b7c945f17485714a5574bfe47)

Resolved conflicts:
elf/Makefile

3 years agoelf: Fix initial-exec TLS access on audit modules (BZ #28096)
Adhemerval Zanella [Mon, 24 Jan 2022 13:46:16 +0000 (10:46 -0300)] 
elf: Fix initial-exec TLS access on audit modules (BZ #28096)

For audit modules and dependencies with initial-exec TLS, we can not
set the initial TLS image on default loader initialization because it
would already be set by the audit setup.  However, subsequent thread
creation would need to follow the default behaviour.

This patch fixes it by setting l_auditing link_map field not only
for the audit modules, but also for all its dependencies.  This is
used on _dl_allocate_tls_init to avoid the static TLS initialization
at load time.

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

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

3 years agoelf: Do not fail for failed dlmopen on audit modules (BZ #28061)
Adhemerval Zanella [Wed, 30 Jun 2021 20:33:57 +0000 (17:33 -0300)] 
elf: Do not fail for failed dlmopen on audit modules (BZ #28061)

The dl_main sets the LM_ID_BASE to RT_ADD just before starting to
add load new shared objects.  The state is set to RT_CONSISTENT just
after all objects are loaded.

However if a audit modules tries to dlmopen an inexistent module,
the _dl_open will assert that the namespace is in an inconsistent
state.

This is different than dlopen, since first it will not use
LM_ID_BASE and second _dl_map_object_from_fd is the sole responsible
to set and reset the r_state value.

So the assert on _dl_open can not really be seen if the state is
consistent, since _dt_main resets it.  This patch removes the assert.

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

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

Resolved conflicts:
elf/Makefile
elf/dl-open.c

3 years agoelf: Add la_activity during application exit
Adhemerval Zanella [Mon, 24 Jan 2022 13:46:15 +0000 (10:46 -0300)] 
elf: Add la_activity during application exit

la_activity is not called during application exit, even though
la_objclose is.

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

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

3 years agoelf: Issue audit la_objopen for vDSO
Adhemerval Zanella [Mon, 19 Jul 2021 21:42:26 +0000 (18:42 -0300)] 
elf: Issue audit la_objopen for vDSO

The vDSO is is listed in the link_map chain, but is never the subject of
an la_objopen call.  A new internal flag __RTLD_VDSO is added that
acts as __RTLD_OPENEXEC to allocate the required 'struct auditstate'
extra space for the 'struct link_map'.

The return value from the callback is currently ignored, since there
is no PLT call involved by glibc when using the vDSO, neither the vDSO
are exported directly.

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

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

Resolved conflicts:
elf/Makefile

3 years agoelf: Add audit tests for modules with TLSDESC
Adhemerval Zanella [Wed, 30 Jun 2021 18:51:31 +0000 (15:51 -0300)] 
elf: Add audit tests for modules with TLSDESC

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

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

3 years agoelf: Avoid unnecessary slowdown from profiling with audit (BZ#15533)
Adhemerval Zanella [Wed, 30 Jun 2021 13:24:09 +0000 (10:24 -0300)] 
elf: Avoid unnecessary slowdown from profiling with audit (BZ#15533)

The rtld-audit interfaces introduces a slowdown due to enabling
profiling instrumentation (as if LD_AUDIT implied LD_PROFILE).
However, instrumenting is only necessary if one of audit libraries
provides PLT callbacks (la_pltenter or la_pltexit symbols).  Otherwise,
the slowdown can be avoided.

The following patch adjusts the logic that enables profiling to iterate
over all audit modules and check if any of those provides a PLT hook.
To keep la_symbind to work even without PLT callbacks, _dl_fixup now
calls the audit callback if the modules implements it.

Co-authored-by: Alexander Monakov <amonakov@ispras.ru>
Checked on x86_64-linux-gnu, i686-linux-gnu, and aarch64-linux-gnu.

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

Resolved conflicts:
NEWS
elf/Makefile

3 years agoelf: Add _dl_audit_pltexit
Adhemerval Zanella [Thu, 22 Jul 2021 21:02:42 +0000 (18:02 -0300)] 
elf: Add _dl_audit_pltexit

It consolidates the code required to call la_pltexit audit
callback.

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

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

Resolved conflicts:
sysdeps/hppa/dl-runtime.c

3 years agoelf: Add _dl_audit_pltenter
Adhemerval Zanella [Thu, 22 Jul 2021 20:45:33 +0000 (17:45 -0300)] 
elf: Add _dl_audit_pltenter

It consolidates the code required to call la_pltenter audit
callback.

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

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

3 years agoelf: Add _dl_audit_preinit
Adhemerval Zanella [Thu, 22 Jul 2021 20:10:57 +0000 (17:10 -0300)] 
elf: Add _dl_audit_preinit

It consolidates the code required to call la_preinit audit
callback.

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

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

3 years agoelf: Add _dl_audit_symbind_alt and _dl_audit_symbind
Adhemerval Zanella [Tue, 20 Jul 2021 18:58:35 +0000 (15:58 -0300)] 
elf: Add _dl_audit_symbind_alt and _dl_audit_symbind

It consolidates the code required to call la_symbind{32,64} audit
callback.

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

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

3 years agoelf: Add _dl_audit_objclose
Adhemerval Zanella [Tue, 20 Jul 2021 17:04:51 +0000 (14:04 -0300)] 
elf: Add _dl_audit_objclose

It consolidates the code required to call la_objclose audit
callback.

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

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

3 years agoelf: Add _dl_audit_objsearch
Adhemerval Zanella [Tue, 20 Jul 2021 16:47:36 +0000 (13:47 -0300)] 
elf: Add _dl_audit_objsearch

It consolidates the code required to call la_objsearch audit
callback.

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

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

3 years agoelf: Add _dl_audit_activity_map and _dl_audit_activity_nsid
Adhemerval Zanella [Tue, 20 Jul 2021 14:03:34 +0000 (11:03 -0300)] 
elf: Add _dl_audit_activity_map and _dl_audit_activity_nsid

It consolidates the code required to call la_activity audit
callback.

Also for a new Lmid_t the namespace link_map list are empty, so it
requires to check if before using it.  This can happen for when audit
module is used along with dlmopen.

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

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

3 years agoelf: Add _dl_audit_objopen
Adhemerval Zanella [Mon, 19 Jul 2021 18:47:51 +0000 (15:47 -0300)] 
elf: Add _dl_audit_objopen

It consolidates the code required to call la_objopen audit callback.

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

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

Resolved conflicts:
elf/Makefile

3 years agoelf: Move la_activity (LA_ACT_ADD) after _dl_add_to_namespace_list() (BZ #28062)
Adhemerval Zanella [Thu, 11 Nov 2021 12:28:21 +0000 (09:28 -0300)] 
elf: Move la_activity (LA_ACT_ADD) after _dl_add_to_namespace_list() (BZ #28062)

It ensures that the the namespace is guaranteed to not be empty.

Checked on x86_64-linux-gnu.

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

Resolved conflicts:
elf/Makefile

3 years agoelf: Fix dynamic-link.h usage on rtld.c
Adhemerval Zanella [Wed, 13 Oct 2021 12:49:34 +0000 (09:49 -0300)] 
elf: Fix dynamic-link.h usage on rtld.c

The 4af6982e4c fix does not fully handle RTLD_BOOTSTRAP usage on
rtld.c due two issues:

  1. RTLD_BOOTSTRAP is also used on dl-machine.h on various
     architectures and it changes the semantics of various machine
     relocation functions.

  2. The elf_get_dynamic_info() change was done sideways, previously
     to 490e6c62aa get-dynamic-info.h was included by the first
     dynamic-link.h include *without* RTLD_BOOTSTRAP being defined.
     It means that the code within elf_get_dynamic_info() that uses
     RTLD_BOOTSTRAP is in fact unused.

To fix 1. this patch now includes dynamic-link.h only once with
RTLD_BOOTSTRAP defined.  The ELF_DYNAMIC_RELOCATE call will now have
the relocation fnctions with the expected semantics for the loader.

And to fix 2. part of 4af6982e4c is reverted (the check argument
elf_get_dynamic_info() is not required) and the RTLD_BOOTSTRAP
pieces are removed.

To reorganize the includes the static TLS definition is moved to
its own header to avoid a circular dependency (it is defined on
dynamic-link.h and dl-machine.h requires it at same time other
dynamic-link.h definition requires dl-machine.h defitions).

Also ELF_MACHINE_NO_REL, ELF_MACHINE_NO_RELA, and ELF_MACHINE_PLT_REL
are moved to its own header.  Only ancient ABIs need special values
(arm, i386, and mips), so a generic one is used as default.

The powerpc Elf64_FuncDesc is also moved to its own header, since
csu code required its definition (which would require either include
elf/ folder or add a full path with elf/).

Checked on x86_64, i686, aarch64, armhf, powerpc64, powerpc32,
and powerpc64le.

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

Resolved conflicts:
elf/rtld.c

3 years agoelf: Fix elf_get_dynamic_info definition
Adhemerval Zanella [Mon, 11 Oct 2021 19:01:49 +0000 (16:01 -0300)] 
elf: Fix elf_get_dynamic_info definition

Before to 490e6c62aa31a8a ('elf: Avoid nested functions in the loader
[BZ #27220]'), elf_get_dynamic_info() was defined twice on rtld.c: on
the first dynamic-link.h include and later within _dl_start().  The
former definition did not define DONT_USE_BOOTSTRAP_MAP and it is used
on setup_vdso() (since it is a global definition), while the former does
define DONT_USE_BOOTSTRAP_MAP and it is used on loader self-relocation.

With the commit change, the function is now included and defined once
instead of defined as a nested function.  So rtld.c defines without
defining RTLD_BOOTSTRAP and it brokes at least powerpc32.

This patch fixes by moving the get-dynamic-info.h include out of
dynamic-link.h, which then the caller can corirectly set the expected
semantic by defining STATIC_PIE_BOOTSTRAP, RTLD_BOOTSTRAP, and/or
RESOLVE_MAP.

It also required to enable some asserts only for the loader bootstrap
to avoid issues when called from setup_vdso().

As a side note, this is another issues with nested functions: it is
not clear from pre-processed output (-E -dD) how the function will
be build and its semantic (since nested function will be local and
extra C defines may change it).

I checked on x86_64-linux-gnu (w/o --enable-static-pie),
i686-linux-gnu, powerpc64-linux-gnu, powerpc-linux-gnu-power4,
aarch64-linux-gnu, arm-linux-gnu, sparc64-linux-gnu, and
s390x-linux-gnu.

Reviewed-by: Fangrui Song <maskray@google.com>
(cherry picked from commit 4af6982e4c9fc465ffb7a54b794aaaa134241f05)

Resolved conflicts:
elf/rtld.c

3 years agoelf: Avoid nested functions in the loader [BZ #27220]
Fangrui Song [Thu, 7 Oct 2021 18:55:02 +0000 (11:55 -0700)] 
elf: Avoid nested functions in the loader [BZ #27220]

dynamic-link.h is included more than once in some elf/ files (rtld.c,
dl-conflict.c, dl-reloc.c, dl-reloc-static-pie.c) and uses GCC nested
functions. This harms readability and the nested functions usage
is the biggest obstacle prevents Clang build (Clang doesn't support GCC
nested functions).

The key idea for unnesting is to add extra parameters (struct link_map
*and struct r_scope_elm *[]) to RESOLVE_MAP,
ELF_MACHINE_BEFORE_RTLD_RELOC, ELF_DYNAMIC_RELOCATE, elf_machine_rel[a],
elf_machine_lazy_rel, and elf_machine_runtime_setup. (This is inspired
by Stan Shebs' ppc64/x86-64 implementation in the
google/grte/v5-2.27/master which uses mixed extra parameters and static
variables.)

Future simplification:
* If mips elf_machine_runtime_setup no longer needs RESOLVE_GOTSYM,
  elf_machine_runtime_setup can drop the `scope` parameter.
* If TLSDESC no longer need to be in elf_machine_lazy_rel,
  elf_machine_lazy_rel can drop the `scope` parameter.

Tested on aarch64, i386, x86-64, powerpc64le, powerpc64, powerpc32,
sparc64, sparcv9, s390x, s390, hppa, ia64, armhf, alpha, and mips64.
In addition, tested build-many-glibcs.py with {arc,csky,microblaze,nios2}-linux-gnu
and riscv64-linux-gnu-rv64imafdc-lp64d.

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

3 years agohppa: Use END instead of PSEUDO_END in swapcontext.S
John David Anglin [Tue, 15 Mar 2022 23:04:39 +0000 (23:04 +0000)] 
hppa: Use END instead of PSEUDO_END in swapcontext.S

(cherry picked from commit 7a5c440102d4ec7fafd9bbd98eca9bd90ecaaafd)

3 years agohppa: Implement swapcontext in assembler (bug 28960)
John David Anglin [Tue, 15 Mar 2022 23:12:37 +0000 (23:12 +0000)] 
hppa: Implement swapcontext in assembler (bug 28960)

When swapcontext.c is compiled without -g, the following error occurs:
Error: CFI instruction used without previous .cfi_startproc

Fix by converting swapcontext routine to assembler.

3 years agodebug: Synchronize feature guards in fortified functions [BZ #28746]
Siddhesh Poyarekar [Wed, 12 Jan 2022 18:04:48 +0000 (23:34 +0530)] 
debug: Synchronize feature guards in fortified functions [BZ #28746]

Some functions (e.g. stpcpy, pread64, etc.) had moved to POSIX in the
main headers as they got incorporated into the standard, but their
fortified variants remained under __USE_GNU.  As a result, these
functions did not get fortified when _GNU_SOURCE was not defined.

Add test wrappers that check all functions tested in tst-chk0 at all
levels with _GNU_SOURCE undefined and then use the failures to (1)
exclude checks for _GNU_SOURCE functions in these tests and (2) Fix
feature macro guards in the fortified function headers so that they're
the same as the ones in the main headers.

This fixes BZ #28746.

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

3 years agodebug: Autogenerate _FORTIFY_SOURCE tests
Siddhesh Poyarekar [Wed, 12 Jan 2022 18:04:23 +0000 (23:34 +0530)] 
debug: Autogenerate _FORTIFY_SOURCE tests

Rename debug/tst-chk1.c to debug/tst-fortify.c and add make hackery to
autogenerate tests with different macros enabled to build and run the
same test with different configurations as well as different
fortification levels.

The change also ends up expanding the -lfs tests to include
_FORTIFY_SOURCE=3.

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

3 years agoEnable _FORTIFY_SOURCE=3 for gcc 12 and above
Siddhesh Poyarekar [Wed, 12 Jan 2022 13:16:28 +0000 (18:46 +0530)] 
Enable _FORTIFY_SOURCE=3 for gcc 12 and above

gcc 12 now has support for the __builtin_dynamic_object_size builtin.
Adapt the macro checks to enable _FORTIFY_SOURCE=3 on gcc 12 and above.

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

3 years agofortify: Fix spurious warning with realpath
Siddhesh Poyarekar [Fri, 17 Dec 2021 13:05:44 +0000 (18:35 +0530)] 
fortify: Fix spurious warning with realpath

The length and object size arguments were swapped around for realpath.
Also add a smoke test so that any changes in this area get caught in
future.

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

3 years ago__glibc_unsafe_len: Fix comment
Siddhesh Poyarekar [Thu, 16 Dec 2021 01:49:14 +0000 (07:19 +0530)] 
__glibc_unsafe_len: Fix comment

We know that the length is *unsafe*.

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

3 years agodebug: Add tests for _FORTIFY_SOURCE=3
Siddhesh Poyarekar [Wed, 20 Oct 2021 12:43:05 +0000 (18:13 +0530)] 
debug: Add tests for _FORTIFY_SOURCE=3

Add some testing coverage for _FORTIFY_SOURCE=3.

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

3 years agoMake sure that the fortified function conditionals are constant
Siddhesh Poyarekar [Wed, 20 Oct 2021 12:42:41 +0000 (18:12 +0530)] 
Make sure that the fortified function conditionals are constant

In _FORTIFY_SOURCE=3, the size expression may be non-constant,
resulting in branches in the inline functions remaining intact and
causing a tiny overhead.  Clang (and in future, gcc) make sure that
the -1 case is always safe, i.e. any comparison of the generated
expression with (size_t)-1 is always false so that bit is taken care
of.  The rest is avoidable since we want the _chk variant whenever we
have a size expression and it's not -1.

Rework the conditionals in a uniform way to clearly indicate two
conditions at compile time:

- Either the size is unknown (-1) or we know at compile time that the
  operation length is less than the object size.  We can call the
  original function in this case.  It could be that either the length,
  object size or both are non-constant, but the compiler, through
  range analysis, is able to fold the *comparison* to a constant.

- The size and length are known and the compiler can see at compile
  time that operation length > object size.  This is valid grounds for
  a warning at compile time, followed by emitting the _chk variant.

For everything else, emit the _chk variant.

This simplifies most of the fortified function implementations and at
the same time, ensures that only one call from _chk or the regular
function is emitted.

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

3 years agoDon't add access size hints to fortifiable functions
Siddhesh Poyarekar [Tue, 12 Oct 2021 06:59:13 +0000 (12:29 +0530)] 
Don't add access size hints to fortifiable functions

In the context of a function definition, the size hints imply that the
size of an object pointed to by one parameter is another parameter.
This doesn't make sense for the fortified versions of the functions
since that's the bit it's trying to validate.

This is harmless with __builtin_object_size since it has fairly simple
semantics when it comes to objects passed as function parameters.
With __builtin_dynamic_object_size we could (as my patchset for gcc[1]
already does) use the access attribute to determine the object size in
the general case but it misleads the fortified functions.

Basically the problem occurs when access attributes are present on
regular functions that have inline fortified definitions to generate
_chk variants; the attributes get inherited by these definitions,
causing problems when analyzing them.  For example with poll(fds, nfds,
timeout), nfds is hinted using the __attr_access as being the size of
fds.

Now, when analyzing the inline function definition in bits/poll2.h, the
compiler sees that nfds is the size of fds and tries to use that
information in the function body.  In _FORTIFY_SOURCE=3 case, where the
object size could be a non-constant expression, this information results
in the conclusion that nfds is the size of fds, which defeats the
purpose of the implementation because we're trying to check here if nfds
does indeed represent the size of fds.  Hence for this case, it is best
to not have the access attribute.

With the attributes gone, the expression evaluation should get delayed
until the function is actually inlined into its destinations.

Disable the access attribute for fortified function inline functions
when building at _FORTIFY_SOURCE=3 to make this work better.  The
access attributes remain for the _chk variants since they can be used
by the compiler to warn when the caller is passing invalid arguments.

[1] https://gcc.gnu.org/pipermail/gcc-patches/2021-October/581125.html

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

3 years agonss: Protect against errno changes in function lookup (bug 28953)
Florian Weimer [Fri, 11 Mar 2022 07:23:56 +0000 (08:23 +0100)] 
nss: Protect against errno changes in function lookup (bug 28953)

dlopen may clobber errno.  The nss_test_errno module uses an ELF
constructor to achieve that, but there could be internal errors
during dlopen that cause this, too.  Therefore, the NSS framework
has to guard against such errno clobbers.

__nss_module_get_function is currently the only function that calls
__nss_module_load, so it is sufficient to save and restore errno
around this call.

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

3 years agonss: Do not mention NSS test modules in <gnu/lib-names.h>
Florian Weimer [Fri, 11 Mar 2022 07:23:56 +0000 (08:23 +0100)] 
nss: Do not mention NSS test modules in <gnu/lib-names.h>

They are not actually installed.  Use the nss_files version instead
in nss/Makefile, similar to how __nss_shlib_revision is derived
from LIBNSS_FILES_SO.

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

3 years agoio: Add fsync call in tst-stat
Florian Weimer [Mon, 28 Feb 2022 10:50:41 +0000 (11:50 +0100)] 
io: Add fsync call in tst-stat

io/tst-stat and io/tst-stat-lfs fail sporadically on the Fedora
builders, and this change hopefully helps to avoid the issue.

(cherry picked from commit ae132284092edc5885315b44cd17d5ea91177e49)

3 years agohppa: Fix warnings from _dl_lookup_address
John David Anglin [Sun, 6 Mar 2022 16:04:32 +0000 (16:04 +0000)] 
hppa: Fix warnings from _dl_lookup_address

This change fixes two warnings from _dl_lookup_address.

The first warning comes from dropping the volatile keyword from
desc in the call to _dl_read_access_allowed.  We now have a full
atomic barrier between loading desc[0] and the access check, so
desc no longer needs to be declared as volatile.

The second warning comes from the implicit declaration of
_dl_fix_reloc_arg.  This is fixed by including dl-runtime.h and
declaring _dl_fix_reloc_arg in dl-runtime.h.

3 years agonptl: Fix cleanups for stack grows up [BZ# 28899]
John David Anglin [Mon, 28 Feb 2022 15:47:38 +0000 (15:47 +0000)] 
nptl: Fix cleanups for stack grows up [BZ# 28899]

_STACK_GROWS_DOWN is defined to 0 when the stack grows up.  The
code in unwind.c used `#ifdef _STACK_GROWS_DOWN' to selct the
stack grows down define for FRAME_LEFT.  As a result, the
_STACK_GROWS_DOWN define was always selected and cleanups were
incorrectly sequenced when the stack grows up.

(cherry picked from commit 2bbc694df279020a6620096d31c1e05c93966f9b)

3 years agohppa: Revise gettext trampoline design
John David Anglin [Tue, 22 Feb 2022 17:28:46 +0000 (17:28 +0000)] 
hppa: Revise gettext trampoline design

The current getcontext return trampoline is overly complex and it
unnecessarily clobbers several registers.  By saving the context
pointer (r26) in the context, __getcontext_ret can restore any
registers not restored by setcontext.  This allows getcontext to
save and restore the entire register context present when getcontext
is entered.  We use the unused oR0 context slot for the return
from __getcontext_ret.

While this is not directly useful in C, it can be exploited in
assembly code.  Registers r20, r23, r24 and r25 are not clobbered
in the call path to getcontext.  This allows a small simplification
of swapcontext.

It also allows saving and restoring the 6-bit SAR register in the
LSB of the oSAR context slot.  The getcontext flag value can be
stored in the MSB of the oSAR slot.

(cherry picked from commit 9e7e5fda38471e00d1190479ea91d7b08ae3e304)

3 years agohppa: Fix swapcontext
John David Anglin [Fri, 18 Feb 2022 20:38:25 +0000 (20:38 +0000)] 
hppa: Fix swapcontext

This change fixes the failure of stdlib/tst-setcontext2 and
stdlib/tst-setcontext7 on hppa.  The implementation of swapcontext
in C is broken.  C saves the return pointer (rp) and any non
call-clobbered registers (in this case r3, r4 and r5) on the
stack.  However, the setcontext call in swapcontext pops the
stack and subsequent calls clobber the saved registers.  When
the context in oucp is restored, both tests fault.

Here we rewrite swapcontext in assembly code to avoid using
the stack for register values that need to be used after
restoration.  The getcontext and setcontext routines are
revised to save and restore register ret1 for normal returns.
We copy the oucp pointer to ret1.  This allows access to
the old context after calling getcontext and setcontext.

(cherry picked from commit 71b108d7eb33b2bf3e61d5e92d2a47f74c1f7d96)

3 years agoFix elf/tst-audit2 on hppa
John David Anglin [Sun, 6 Mar 2022 15:56:57 +0000 (15:56 +0000)] 
Fix elf/tst-audit2 on hppa

The test elf/tst-audit2 fails on hppa with a segmentation fault in the
long branch stub used to call malloc from calloc.  This occurs because
the test is not a PIC executable and calloc is called from the dynamic
linker before the dp register is initialized in _dl_start_user.

The fix is to move the dp register initialization into
elf_machine_runtime_setup.  Since the address of $global$ can't be
loaded directly, we continue to use the DT_PLTGOT value from the
the main_map to initialize dp.  Since l_main_map is not available
in v2.34 and earlier, we use a new function, elf_machine_main_map,
to find the main map.

3 years agolocaledef: Handle symbolic links when generating locale-archive
Arjun Shankar [Thu, 24 Feb 2022 20:43:09 +0000 (21:43 +0100)] 
localedef: Handle symbolic links when generating locale-archive

Whenever locale data for any locale included symbolic links, localedef
would throw the error "incomplete set of locale files" and exclude it
from the generated locale archive.  This commit fixes that.

Co-authored-by: Florian Weimer <fweimer@redhat.com>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
(cherry picked from commit ea89d5bbd9e5e514b606045d909e6ab87d851c88)

3 years agoNEWS: Add a bug fix entry for BZ #28896
H.J. Lu [Sat, 19 Feb 2022 03:09:03 +0000 (19:09 -0800)] 
NEWS: Add a bug fix entry for BZ #28896

3 years agox86: Fix TEST_NAME to make it a string in tst-strncmp-rtm.c
Noah Goldstein [Fri, 18 Feb 2022 23:00:25 +0000 (17:00 -0600)] 
x86: Fix TEST_NAME to make it a string in tst-strncmp-rtm.c

Previously TEST_NAME was passing a function pointer. This didn't fail
because of the -Wno-error flag (to allow for overflow sizes passed
to strncmp/wcsncmp)

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

3 years agox86: Test wcscmp RTM in the wcsncmp overflow case [BZ #28896]
Noah Goldstein [Fri, 18 Feb 2022 20:19:15 +0000 (14:19 -0600)] 
x86: Test wcscmp RTM in the wcsncmp overflow case [BZ #28896]

In the overflow fallback strncmp-avx2-rtm and wcsncmp-avx2-rtm would
call strcmp-avx2 and wcscmp-avx2 respectively. This would have
not checks around vzeroupper and would trigger spurious
aborts. This commit fixes that.

test-strcmp, test-strncmp, test-wcscmp, and test-wcsncmp all pass on
AVX2 machines with and without RTM.
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
(cherry picked from commit 7835d611af0854e69a0c71e3806f8fe379282d6f)

3 years agox86: Fallback {str|wcs}cmp RTM in the ncmp overflow case [BZ #28896]
Noah Goldstein [Tue, 15 Feb 2022 14:18:15 +0000 (08:18 -0600)] 
x86: Fallback {str|wcs}cmp RTM in the ncmp overflow case [BZ #28896]

In the overflow fallback strncmp-avx2-rtm and wcsncmp-avx2-rtm would
call strcmp-avx2 and wcscmp-avx2 respectively. This would have
not checks around vzeroupper and would trigger spurious
aborts. This commit fixes that.

test-strcmp, test-strncmp, test-wcscmp, and test-wcsncmp all pass on
AVX2 machines with and without RTM.

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

3 years agostring: Add a testcase for wcsncmp with SIZE_MAX [BZ #28755]
H.J. Lu [Thu, 17 Feb 2022 16:10:35 +0000 (08:10 -0800)] 
string: Add a testcase for wcsncmp with SIZE_MAX [BZ #28755]

Verify that wcsncmp (L("abc"), L("abd"), SIZE_MAX) == 0.  The new test
fails without

commit ddf0992cf57a93200e0c782e2a94d0733a5a0b87
Author: Noah Goldstein <goldstein.w.n@gmail.com>
Date:   Sun Jan 9 16:02:21 2022 -0600

    x86: Fix __wcsncmp_avx2 in strcmp-avx2.S [BZ# 28755]

and

commit 7e08db3359c86c94918feb33a1182cd0ff3bb10b
Author: Noah Goldstein <goldstein.w.n@gmail.com>
Date:   Sun Jan 9 16:02:28 2022 -0600

    x86: Fix __wcsncmp_evex in strcmp-evex.S [BZ# 28755]

This is for BZ #28755.

Reviewed-by: Sunil K Pandey <skpgkp2@gmail.com>
(cherry picked from commit aa5a720056d37cf24924c138a3dbe6dace98e97c)

3 years agolinux: fix accuracy of get_nprocs and get_nprocs_conf [BZ #28865]
Dmitry V. Levin [Sat, 5 Feb 2022 08:00:00 +0000 (08:00 +0000)] 
linux: fix accuracy of get_nprocs and get_nprocs_conf [BZ #28865]

get_nprocs() and get_nprocs_conf() use various methods to obtain an
accurate number of processors.  Re-introduce __get_nprocs_sched() as
a source of information, and fix the order in which these methods are
used to return the most accurate information.  The primary source of
information used in both functions remains unchanged.

This also changes __get_nprocs_sched() error return value from 2 to 0,
but all its users are already prepared to handle that.

Old fallback order:
  get_nprocs:
    /sys/devices/system/cpu/online -> /proc/stat -> 2
  get_nprocs_conf:
    /sys/devices/system/cpu/ -> /proc/stat -> 2

New fallback order:
  get_nprocs:
    /sys/devices/system/cpu/online -> /proc/stat -> sched_getaffinity -> 2
  get_nprocs_conf:
    /sys/devices/system/cpu/ -> /proc/stat -> sched_getaffinity -> 2

Fixes: 342298278e ("linux: Revert the use of sched_getaffinity on get_nproc")
Closes: BZ #28865
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
(cherry picked from commit e1d32b836410767270a3adf1f82b1a47e6e4cd51)

3 years agoAdd reference to BZ#28860 on NEWS
Adhemerval Zanella [Thu, 3 Feb 2022 20:48:46 +0000 (17:48 -0300)] 
Add reference to BZ#28860 on NEWS

3 years agolinux: Fix missing __convert_scm_timestamps (BZ #28860)
Adhemerval Zanella [Thu, 3 Feb 2022 19:52:52 +0000 (16:52 -0300)] 
linux: Fix missing __convert_scm_timestamps (BZ #28860)

Commit 948ce73b31 made recvmsg/recvmmsg to always call
__convert_scm_timestamps for 64 bit time_t symbol, so adjust it to
always build it for __TIMESIZE != 64.

It fixes build for architecture with 32 bit time_t support when
configured with minimum kernel of 5.1.

(cherry-picked from 798d716df71fb23dc89d1d5dba1fc26a1b5c0024)

3 years agosocket: Do not use AF_NETLINK in __opensock
Florian Weimer [Mon, 22 Nov 2021 13:41:14 +0000 (14:41 +0100)] 
socket: Do not use AF_NETLINK in __opensock

It is not possible to use interface ioctls with netlink sockets
on all Linux kernels.

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

3 years agohurd if_index: Explicitly use AF_INET for if index discovery
Samuel Thibault [Sun, 17 Oct 2021 23:39:02 +0000 (01:39 +0200)] 
hurd if_index: Explicitly use AF_INET for if index discovery

5bf07e1b3a74 ("Linux: Simplify __opensock and fix race condition [BZ #28353]")
made __opensock try NETLINK then UNIX then INET. On the Hurd, only INET
knows about network interfaces, so better actually specify that in
if_index.

(cherry picked from commit 1d3decee997ba2fc24af81803299b2f4f3c47063)

3 years agoLinux: Simplify __opensock and fix race condition [BZ #28353]
Florian Weimer [Tue, 28 Sep 2021 16:55:49 +0000 (18:55 +0200)] 
Linux: Simplify __opensock and fix race condition [BZ #28353]

AF_NETLINK support is not quite optional on modern Linux systems
anymore, so it is likely that the first attempt will always succeed.
Consequently, there is no need to cache the result.  Keep AF_UNIX
and the Internet address families as a fallback, for the rare case
that AF_NETLINK is missing.  The other address families previously
probed are totally obsolete be now, so remove them.

Use this simplified version as the generic implementation, disabling
Netlink support as needed.

(cherry picked from commit 5bf07e1b3a74232bfb8332275110be1a5da50f83)

3 years agolinux: __get_nprocs_sched: do not feed CPU_COUNT_S with garbage [BZ #28850]
Gleb Fotengauer-Malinovskiy [Tue, 1 Feb 2022 22:39:02 +0000 (22:39 +0000)] 
linux: __get_nprocs_sched: do not feed CPU_COUNT_S with garbage [BZ #28850]

Pass the actual number of bytes returned by the kernel.

Fixes: 33099d72e41c ("linux: Simplify get_nprocs")
Reviewed-by: Dmitry V. Levin <ldv@altlinux.org>
(cherry picked from commit 97ba273b505763325efd802dc3a9562dbba79579)

3 years agotst-socket-timestamp-compat.c: Check __TIMESIZE [BZ #28837]
H.J. Lu [Sat, 29 Jan 2022 13:22:31 +0000 (05:22 -0800)] 
tst-socket-timestamp-compat.c: Check __TIMESIZE [BZ #28837]

time_t size is defined by __TIMESIZE, not __WORDSIZE.  Check __TIMESIZE,
instead of __WORDSIZE, for time_t size.  This fixes BZ #28837.

(cherry pick from commit 77a602ebb0769e7ccc5f9f8e06f7fffe66f69dfc)

3 years agoLinux: Only generate 64 bit timestamps for 64 bit time_t recvmsg/recvmmsg
Adhemerval Zanella [Thu, 27 Jan 2022 19:45:18 +0000 (16:45 -0300)] 
Linux: Only generate 64 bit timestamps for 64 bit time_t recvmsg/recvmmsg

The timestamps created by __convert_scm_timestamps only make sense for
64 bit time_t programs, 32 bit time_t programs will ignore 64 bit time_t
timestamps since SO_TIMESTAMP will be defined to old values (either by
glibc or kernel headers).

Worse, if the buffer is not suffice MSG_CTRUNC is set to indicate it
(which breaks some programs [1]).

This patch makes only 64 bit time_t recvmsg and recvmmsg to call
__convert_scm_timestamps.  Also, the assumption to called it is changed
from __ASSUME_TIME64_SYSCALLS to __TIMESIZE != 64 since the setsockopt
might be called by libraries built without __TIME_BITS=64.  The
MSG_CTRUNC is only set for the 64 bit symbols, it should happen only
if 64 bit time_t programs run older kernels.

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

[1] https://github.com/systemd/systemd/pull/20567

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

3 years agolinux: Fix ancillary 64-bit time timestamp conversion (BZ #28349, BZ#28350)
Adhemerval Zanella [Mon, 24 Jan 2022 11:55:53 +0000 (08:55 -0300)] 
linux: Fix ancillary 64-bit time timestamp conversion (BZ #28349, BZ#28350)

The __convert_scm_timestamps only updates the control message last
pointer for SOL_SOCKET type, so if the message control buffer contains
multiple ancillary message types the converted timestamp one might
overwrite a valid message.

The test checks if the extra ancillary space is correctly handled
by recvmsg/recvmmsg, where if there is no extra space for the 64-bit
time_t converted message the control buffer should be marked with
MSG_TRUNC.  It also check if recvmsg/recvmmsg handle correctly multiple
ancillary data.

Checked on x86_64-linux and on i686-linux-gnu on both 5.11 and
4.15 kernel.

Co-authored-by: Fabian Vogt <fvogt@suse.de>
Reviewed-by: Florian Weimer <fweimer@redhat.com>
(cherry picked from commit 8fba672472ae0055387e9315fc2eddfa6775ca79)

3 years agosupport: Add support_socket_so_timestamp_time64
Adhemerval Zanella [Mon, 13 Dec 2021 14:36:42 +0000 (11:36 -0300)] 
support: Add support_socket_so_timestamp_time64

Check if the socket support 64-bit network packages timestamps
(SO_TIMESTAMP and SO_TIMESTAMPNS).  This will be used on recvmsg
and recvmmsg tests to check if the timestamp should be generated.

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

3 years agox86: Use CHECK_FEATURE_PRESENT to check HLE [BZ #27398]
H.J. Lu [Tue, 25 Jan 2022 03:33:43 +0000 (19:33 -0800)] 
x86: Use CHECK_FEATURE_PRESENT to check HLE [BZ #27398]

HLE is disabled on blacklisted CPUs.  Use CHECK_FEATURE_PRESENT, instead
of CHECK_FEATURE_ACTIVE, to check HLE.

(cherry picked from commit 501246c5e2dfcc278f0ebbdb72345cdd239521c7)

3 years agox86: Black list more Intel CPUs for TSX [BZ #27398]
H.J. Lu [Fri, 14 Jan 2022 22:48:01 +0000 (14:48 -0800)] 
x86: Black list more Intel CPUs for TSX [BZ #27398]

Disable TSX and enable RTM_ALWAYS_ABORT for Intel CPUs listed in:

https://www.intel.com/content/www/us/en/support/articles/000059422/processors.html

This fixes BZ #27398.

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

3 years agoFix glibc 2.34 ABI omission (missing GLIBC_2.34 in dynamic loader)
Florian Weimer [Thu, 27 Jan 2022 15:03:58 +0000 (16:03 +0100)] 
Fix glibc 2.34 ABI omission (missing GLIBC_2.34 in dynamic loader)

The glibc 2.34 release really should have added a GLIBC_2.34
symbol to the dynamic loader. With it, we could move functions such
as dlopen or pthread_key_create that work on process-global state
into the dynamic loader (once we have fixed a longstanding issue
with static linking).  Without the GLIBC_2.34 symbol, yet another
new symbol version would be needed because old glibc will fail to
load binaries due to the missing symbol version in ld.so that newly
linked programs will require.

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

3 years agoelf/Makefile: Reflow and sort most variable assignments
Florian Weimer [Fri, 14 Jan 2022 19:16:05 +0000 (20:16 +0100)] 
elf/Makefile: Reflow and sort most variable assignments

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

3 years agoelf: Add a comment after trailing backslashes
H.J. Lu [Tue, 4 Jan 2022 14:58:34 +0000 (06:58 -0800)] 
elf: Add a comment after trailing backslashes

(cherry picked from commit f4f70c2895e3d325188a42c10eb7bb4335be6773)

3 years agoelf: Sort tests and modules-names
H.J. Lu [Mon, 13 Dec 2021 17:43:52 +0000 (09:43 -0800)] 
elf: Sort tests and modules-names

Sort tests and modules-names to reduce future conflicts.

(cherry picked from commit 28713c06129f8f64f88c423266e6ff2880216509)

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

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

Fixes [BZ# 28755] for wcsncmp by redirecting length >= 2^56 to
__wcscmp_evex. 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 7e08db3359c86c94918feb33a1182cd0ff3bb10b)

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)

3 years agoNEWS: add bug entry for BZ #28769 and BZ #28770
Aurelien Jarno [Mon, 24 Jan 2022 22:45:03 +0000 (23:45 +0100)] 
NEWS: add bug entry for BZ #28769 and BZ #28770

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 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 agostdlib: Fix formatting of tests list in Makefile
Siddhesh Poyarekar [Thu, 13 Jan 2022 13:20:55 +0000 (18:50 +0530)] 
stdlib: Fix formatting of tests list in Makefile

Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Reviewed-by: Florian Weimer <fweimer@redhat.com>
(cherry picked from commit f9dab1b5f23d0fb008a56c7c6c8919adb49d3611)

3 years agostdlib: Sort tests in Makefile
Siddhesh Poyarekar [Thu, 13 Jan 2022 05:04:37 +0000 (10:34 +0530)] 
stdlib: Sort tests in Makefile

Put one test per line and sort them.

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

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 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 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 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 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 agoDisable debuginfod in printer tests [BZ #28757]
H.J. Lu [Sun, 9 Jan 2022 17:06:15 +0000 (09:06 -0800)] 
Disable debuginfod in printer tests [BZ #28757]

With gdb-11.1-6.fc35.x86_64, I got

FAIL: nptl/test-cond-printers
FAIL: nptl/test-condattr-printers
FAIL: nptl/test-mutex-printers
FAIL: nptl/test-mutexattr-printers
FAIL: nptl/test-rwlock-printers
FAIL: nptl/test-rwlockattr-printers

$ cat nptl/test-condattr-printers.out
Error: Response does not match the expected pattern.
Command: start
Expected pattern: main
Response:  Temporary breakpoint 1 at 0x11d5: file test-condattr-printers.c, line 43.
Starting program: /export/build/gnu/tools-build/glibc-cet-gitlab/build-x86_64-linux/nptl/test-condattr-printers

This GDB supports auto-downloading debuginfo from the following URLs:
https://debuginfod.fedoraproject.org/
Enable debuginfod for this session? (y or [n])

Disable debuginfod to avoid GDB messages.  This fixes BZ #28757.

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

3 years agoUpdate syscall lists for Linux 5.16
Joseph Myers [Thu, 13 Jan 2022 22:18:13 +0000 (22:18 +0000)] 
Update syscall lists for Linux 5.16

Linux 5.16 has one new syscall, futex_waitv.  Update
syscall-names.list and regenerate the arch-syscall.h headers with
build-many-glibcs.py update-syscalls.

Tested with build-many-glibcs.py.

(cherry picked from commit 4997a533ae4b51ef66a6b68862b7578a7acb82df)

3 years agoi386: Remove broken CAN_USE_REGISTER_ASM_EBP (bug 28771)
Florian Weimer [Thu, 13 Jan 2022 13:59:29 +0000 (14:59 +0100)] 
i386: Remove broken CAN_USE_REGISTER_ASM_EBP (bug 28771)

The configure check for CAN_USE_REGISTER_ASM_EBP tried to compile a
simple function that uses %ebp as an inline assembly operand.  If
compilation failed, CAN_USE_REGISTER_ASM_EBP was set 0, which
eventually had these consequences:

(1) %ebx was avoided as an inline assembly operand, with an
    assembler macro hack to avoid unnecessary register moves.
(2) %ebp was avoided as an inline assembly operand, using an
    out-of-line syscall function for 6-argument system calls.

(1) is no longer needed for any GCC version that is supported for
building glibc.  %ebx can be used directly as a register operand.
Therefore, this commit removes the %ebx avoidance completely.  This
avoids the assembler macro hack, which turns out to be incompatible
with the current Systemtap probe macros (which switch to .altmacro
unconditionally).

(2) is still needed in many build configurations.  The existing
configure check cannot really capture that because the simple function
succeeds to compile, while the full glibc build still fails.
Therefore, this commit removes the check, the CAN_USE_REGISTER_ASM_EBP
macro, and uses the out-of-line syscall function for 6-argument system
calls unconditionally.

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

3 years agoUpdate syscall lists for Linux 5.15
Joseph Myers [Wed, 10 Nov 2021 15:21:19 +0000 (15:21 +0000)] 
Update syscall lists for Linux 5.15

Linux 5.15 has one new syscall, process_mrelease (and also enables the
clone3 syscall for RV32).  It also has a macro __NR_SYSCALL_MASK for
Arm, which is not a syscall but matches the pattern used for syscall
macro names.

Add __NR_SYSCALL_MASK to the names filtered out in the code dealing
with syscall lists, update syscall-names.list for the new syscall and
regenerate the arch-syscall.h headers with build-many-glibcs.py
update-syscalls.

Tested with build-many-glibcs.py.

(cherry picked from commit 3387c40a8bbad5faf85b1feb56429cb20feaa640)

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 agotimezone: test-case for BZ #28707
Hans-Peter Nilsson [Fri, 17 Dec 2021 20:45:54 +0000 (21:45 +0100)] 
timezone: test-case for BZ #28707

This test-case is the tzfile for Asuncion generated by
tzlib-2021e as follows, using the tzlib-2021e zic: "zic -d
DEST -r @1546300800 -L /dev/null -b slim
SOURCE/southamerica".  Note that in its type 2 header, it
has two entries in its "time-types" array (types), but only
one entry in its "transition types" array (type_idxs).

* timezone/Makefile, timezone/tst-pr28707.c,
timezone/testdata/gen-XT5.sh: New test.

Co-authored-by: Christopher Wong <Christopher.Wong@axis.com>
(cherry picked from commit ebe899af0dc3215159a9c896ac6f35b72a18cb6e)

3 years agotimezone: handle truncated timezones from tzcode-2021d and later (BZ #28707)
Hans-Peter Nilsson [Fri, 17 Dec 2021 20:38:00 +0000 (21:38 +0100)] 
timezone: handle truncated timezones from tzcode-2021d and later (BZ #28707)

When using a timezone file with a truncated starting time,
generated by the zic in IANA tzcode-2021d a.k.a. tzlib-2021d
(also in tzlib-2021e; current as of this writing), glibc
asserts in __tzfile_read (on e.g. tzset() for this file) and
you may find lines matching "tzfile.c:435: __tzfile_read:
Assertion `num_types == 1' failed" in your syslog.

One example of such a file is the tzfile for Asuncion
generated by tzlib-2021e as follows, using the tzlib-2021e zic:
"zic -d DEST -r @1546300800 -L /dev/null -b slim
SOURCE/southamerica".  Note that in its type 2 header, it has
two entries in its "time-types" array (types), but only one
entry in its "transition types" array (type_idxs).

This is valid and expected already in the published RFC8536, and
not even frowned upon: "Local time for timestamps before the
first transition is specified by the first time type (time type
0)" ... "every nonzero local time type index SHOULD appear at
least once in the transition type array".  Note the "nonzero ...
index".  Until the 2021d zic, index 0 has been shared by the
first valid transition but with 2021d it's separate, set apart
as a placeholder and only "implicitly" indexed.  (A draft update
of the RFC mandates that the entry at index 0 is a placeholder
in this case, hence can no longer be shared.)

* time/tzfile.c (__tzfile_read): Don't assert when no transitions
are found.

Co-authored-by: Christopher Wong <Christopher.Wong@axis.com>
(cherry picked from commit c36f64aa6dff13b12a1e03a185e75a50fa9f6a4c)

3 years agoFix subscript error with odd TZif file [BZ #28338]
Paul Eggert [Tue, 14 Sep 2021 05:49:45 +0000 (22:49 -0700)] 
Fix subscript error with odd TZif file [BZ #28338]

* time/tzfile.c (__tzfile_compute): Fix unlikely off-by-one bug
that accessed before start of an array when an oddball-but-valid
TZif file was queried with an unusual time_t value.

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

3 years agoAArch64: Check for SVE in ifuncs [BZ #28744]
Wilco Dijkstra [Thu, 6 Jan 2022 14:36:28 +0000 (14:36 +0000)] 
AArch64: Check for SVE in ifuncs [BZ #28744]

Add a check for SVE in the A64FX ifuncs for memcpy, memset and memmove.
This fixes BZ #28744.

(cherry picked from commit e5fa62b8db546f8792ec9e5c61e6419f4f8e3f4d)

3 years agointl/plural.y: Avoid conflicting declarations of yyerror and yylex
Andrea Monaco [Sun, 12 Dec 2021 09:24:28 +0000 (10:24 +0100)] 
intl/plural.y: Avoid conflicting declarations of yyerror and yylex

bison-3.8 includes these lines in the generated intl/plural.c:

  #if !defined __gettexterror && !defined YYERROR_IS_DECLARED
  void __gettexterror (struct parse_args *arg, const char *msg);
  #endif
  #if !defined __gettextlex && !defined YYLEX_IS_DECLARED
  int __gettextlex (YYSTYPE *yylvalp, struct parse_args *arg);
  #endif

Those default prototypes provided by bison conflict with the
declarations later on in plural.y.  This patch solves the issue.

Reviewed-by: Arjun Shankar <arjun@redhat.com>
(cherry picked from commit c6d7d6312c21bbcfb236d48bb7c11cedb234389f)

3 years agoLinux: Fix 32-bit vDSO for clock_gettime on powerpc32
maminjie [Mon, 20 Dec 2021 11:36:32 +0000 (19:36 +0800)] 
Linux: Fix 32-bit vDSO for clock_gettime on powerpc32

When the clock_id is CLOCK_PROCESS_CPUTIME_ID or CLOCK_THREAD_CPUTIME_ID,
on the 5.10 kernel powerpc 32-bit, the 32-bit vDSO is executed successfully (
because the __kernel_clock_gettime in arch/powerpc/kernel/vdso32/gettimeofday.S
does not support these two IDs, the 32-bit time_t syscall will be used),
but tp32.tv_sec is equal to 0, causing the 64-bit time_t syscall to continue to be used,
resulting in two system calls.

Fix commit 72e84d1db22203e01a43268de71ea8669eca2863.

Signed-off-by: maminjie <maminjie2@huawei.com>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
(cherry picked from commit e0fc721ce600038dd390e77cfe52440707ef574d)

3 years agolinux: Add sparck brk implementation
Adhemerval Zanella [Wed, 4 Aug 2021 18:34:12 +0000 (21:34 +0300)] 
linux: Add sparck brk implementation

It turned that the generic implementation of brk() does not work
for sparc, since on failure kernel will just return the previous
input value without setting the conditional register.

This patches adds back a sparc32 and sparc64 implementation removed
by 720480934ab9107.

Checked on sparc64-linux-gnu and sparcv9-linux-gnu.

(cherry picked from commit 5b86241a032c50462988bdd1439e078384690d34)

3 years agoUpdate sparc libm-test-ulps
Adhemerval Zanella [Wed, 4 Aug 2021 18:40:32 +0000 (21:40 +0300)] 
Update sparc libm-test-ulps

(cherry picked from commit c52eb066bc634a79e4194457362384abe5b43b3a)

3 years agoUpdate hppa libm-test-ulps
John David Anglin [Mon, 6 Sep 2021 17:37:29 +0000 (17:37 +0000)] 
Update hppa libm-test-ulps

(cherry picked from commit d8cf84ac7e504663dfeb2bb45d8d48ae81effe05)

3 years agoriscv: align stack before calling _dl_init [BZ #28703]
Aurelien Jarno [Wed, 15 Dec 2021 23:06:28 +0000 (00:06 +0100)] 
riscv: align stack before calling _dl_init [BZ #28703]

Align the stack pointer to 128 bits during the call to _dl_init() as
specified by the RISC-V ABI [1]. This fixes the elf/tst-align2 test.

Fixes bug 28703.

[1] https://github.com/riscv-non-isa/riscv-elf-psabi-doc

(cherry picked from commit 225da459cebef1037dcd78b56471edc0721e1c41)

3 years agoriscv: align stack in clone [BZ #28702]
Aurelien Jarno [Tue, 14 Dec 2021 21:44:35 +0000 (22:44 +0100)] 
riscv: align stack in clone [BZ #28702]

The RISC-V ABI [1] mandates that "the stack pointer shall be aligned to
a 128-bit boundary upon procedure entry". This as not the case in clone.

This fixes the misc/tst-misalign-clone-internal and
misc/tst-misalign-clone tests.

Fixes bug 28702.

[1] https://github.com/riscv-non-isa/riscv-elf-psabi-doc

(cherry picked from commit d2e594d71509faf36cf851a69370db34a4f5fa65)

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 agoelf: Fix tst-cpu-features-cpuinfo for KVM guests on some AMD systems [BZ #28704]
Aurelien Jarno [Wed, 15 Dec 2021 22:46:19 +0000 (23:46 +0100)] 
elf: Fix tst-cpu-features-cpuinfo for KVM guests on some AMD systems [BZ #28704]

On KVM guests running on some AMD systems, the IBRS feature is reported
as a synthetic feature using the Intel feature, while the cpuinfo entry
keeps the same. Handle that by first checking the presence of the Intel
feature on AMD systems.

Fixes bug 28704.

(cherry picked from commit 94058f6cde8b887178885954740ac6c866d25eab)

3 years agonss: Use "files dns" as the default for the hosts database (bug 28700)
Florian Weimer [Fri, 17 Dec 2021 11:01:20 +0000 (12:01 +0100)] 
nss: Use "files dns" as the default for the hosts database (bug 28700)

This matches what is currently in nss/nsswitch.conf.  The new ordering
matches what most distributions use in their installed configuration
files.

It is common to add localhost to /etc/hosts because the name does not
exist in the DNS, but is commonly used as a host name.

With the built-in "dns [!UNAVAIL=return] files" default, dns is
searched first and provides an answer for "localhost" (NXDOMAIN).
We never look at the files database as a result, so the contents of
/etc/hosts is ignored.  This means that "getent hosts localhost"
fail without a /etc/nsswitch.conf file, even though the host name
is listed in /etc/hosts.

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