]> git.ipfire.org Git - thirdparty/glibc.git/log
thirdparty/glibc.git
7 days agoposix: Fix double-free after allocation failure in regcomp (bug 33185) release/2.34/master
Florian Weimer [Mon, 21 Jul 2025 19:43:49 +0000 (21:43 +0200)] 
posix: Fix double-free after allocation failure in regcomp (bug 33185)

If a memory allocation failure occurs during bracket expression
parsing in regcomp, a double-free error may result.

Reported-by: Anastasia Belova <abelova@astralinux.ru>
Co-authored-by: Paul Eggert <eggert@cs.ucla.edu>
Reviewed-by: Andreas K. Huettel <dilfridge@gentoo.org>
(cherry picked from commit 7ea06e994093fa0bcca0d0ee2c1db271d8d7885d)

5 weeks agoFix error reporting (false negatives) in SGID tests
Florian Weimer [Thu, 22 May 2025 12:36:37 +0000 (14:36 +0200)] 
Fix error reporting (false negatives) in SGID tests

And simplify the interface of support_capture_subprogram_self_sgid.

Use the existing framework for temporary directories (now with
mode 0700) and directory/file deletion.  Handle all execution
errors within support_capture_subprogram_self_sgid.  In particular,
this includes test failures because the invoked program did not
exit with exit status zero.  Existing tests that expect exit
status 42 are adjusted to use zero instead.

In addition, fix callers not to call exit (0) with test failures
pending (which may mask them, especially when running with --direct).

Fixes commit 35fc356fa3b4f485bd3ba3114c9f774e5df7d3c2
("elf: Fix subprocess status handling for tst-dlopen-sgid (bug 32987)").

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

5 weeks agosupport: Pick group in support_capture_subprogram_self_sgid if UID == 0
Florian Weimer [Wed, 21 May 2025 14:47:34 +0000 (16:47 +0200)] 
support: Pick group in support_capture_subprogram_self_sgid if UID == 0

When running as root, it is likely that we can run under any group.
Pick a harmless group from /etc/group in this case.

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

5 weeks agosupport: Don't fail on fchown when spawning sgid processes
Siddhesh Poyarekar [Thu, 1 Jun 2023 11:23:15 +0000 (07:23 -0400)] 
support: Don't fail on fchown when spawning sgid processes

In some cases (e.g. when podman creates user containers), the only other
group assigned to the executing user is nobody and fchown fails with it
because the group is not mapped.  Do not fail the test in this case,
instead exit as unsupported.

Reported-by: Frédéric Bérat <fberat@redhat.com>
Tested-by: Frédéric Bérat <fberat@redhat.com>
Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
(cherry picked from commit 6286cca2cb8389dcffec39238a8bf15ffea96396)

8 weeks agoelf: Ignore LD_LIBRARY_PATH and debug env var for setuid for static
Adhemerval Zanella [Mon, 6 Nov 2023 20:25:49 +0000 (17:25 -0300)] 
elf: Ignore LD_LIBRARY_PATH and debug env var for setuid for static

It mimics the ld.so behavior.

Checked on x86_64-linux-gnu.
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
(cherry picked from commit 5451fa962cd0a90a0e2ec1d8910a559ace02bba0)

Changes:
Keep EXTRA_UNSECURE_ENVVARS support.
Use __rawmemchr instead of strchr.
Keep LD_PROFILE_OUTPUT support.
Make tunables support optional via HAVE_TUNABLES.

8 weeks agoRevert "elf: Ignore LD_LIBRARY_PATH and debug env var for setuid for static"
Florian Weimer [Tue, 3 Jun 2025 12:10:15 +0000 (14:10 +0200)] 
Revert "elf: Ignore LD_LIBRARY_PATH and debug env var for setuid for static"

This reverts commit a4a1752edb10c136863cc617cf4f49574c24fcd5.

Reason for revert: Accidentally drops EXTRA_UNSECURE_ENVVARS support.

2 months agoelf: Fix subprocess status handling for tst-dlopen-sgid (bug 32987)
Florian Weimer [Wed, 21 May 2025 06:43:32 +0000 (08:43 +0200)] 
elf: Fix subprocess status handling for tst-dlopen-sgid (bug 32987)

This should really move into support_capture_subprogram_self_sgid.

Reviewed-by: Sam James <sam@gentoo.org>
(cherry picked from commit 35fc356fa3b4f485bd3ba3114c9f774e5df7d3c2)

2 months agoelf: Test case for bug 32976 (CVE-2025-4802)
Florian Weimer [Tue, 20 May 2025 17:45:06 +0000 (19:45 +0200)] 
elf: Test case for bug 32976 (CVE-2025-4802)

Check that LD_LIBRARY_PATH is ignored for AT_SECURE statically
linked binaries, using support_capture_subprogram_self_sgid.

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

2 months agosupport: Add support_record_failure_barrier
Florian Weimer [Mon, 23 Dec 2024 12:57:55 +0000 (13:57 +0100)] 
support: Add support_record_failure_barrier

This can be used to stop execution after a TEST_COMPARE_BLOB
failure, for example.

(cherry picked from commit d0b8aa6de4529231fadfe604ac2c434e559c2d9e)

2 months agosupport: Use const char * argument in support_capture_subprogram_self_sgid
Florian Weimer [Tue, 20 May 2025 17:36:02 +0000 (19:36 +0200)] 
support: Use const char * argument in support_capture_subprogram_self_sgid

The function does not modify the passed-in string, so make this clear
via the prototype.

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

2 months agoelf: Ignore LD_LIBRARY_PATH and debug env var for setuid for static
Adhemerval Zanella [Mon, 6 Nov 2023 20:25:49 +0000 (17:25 -0300)] 
elf: Ignore LD_LIBRARY_PATH and debug env var for setuid for static

It mimics the ld.so behavior.

Checked on x86_64-linux-gnu.
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
(cherry picked from commit 5451fa962cd0a90a0e2ec1d8910a559ace02bba0)

Changes:

git/elf/dl-support.c
  (missing commit 55f41ef8de4a4d0c5762d78659e11202d3c765d4
   ("elf: Remove LD_PROFILE for static binaries"),
   missing removal of tunables support)

5 months agomath: Improve layout of exp/exp10 data
Wilco Dijkstra [Fri, 13 Dec 2024 15:43:07 +0000 (15:43 +0000)] 
math: Improve layout of exp/exp10 data

GCC aligns global data to 16 bytes if their size is >= 16 bytes.  This patch
changes the exp_data struct slightly so that the fields are better aligned
and without gaps.  As a result on targets that support them, more load-pair
instructions are used in exp.

The exp benchmark improves 2.5%, "144bits" by 7.2%, "768bits" by 12.7% on
Neoverse V2.

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

5 months agoAArch64: Use prefer_sve_ifuncs for SVE memset
Wilco Dijkstra [Thu, 27 Feb 2025 16:28:52 +0000 (16:28 +0000)] 
AArch64: Use prefer_sve_ifuncs for SVE memset

Use prefer_sve_ifuncs for SVE memset just like memcpy.

Reviewed-by: Yury Khrustalev <yury.khrustalev@arm.com>
(cherry picked from commit 0f044be1dae5169d0e57f8d487b427863aeadab4)

5 months agoAArch64: Add SVE memset
Wilco Dijkstra [Tue, 24 Dec 2024 18:01:59 +0000 (18:01 +0000)] 
AArch64: Add SVE memset

Add SVE memset based on the generic memset with predicated load for sizes < 16.
Unaligned memsets of 128-1024 are improved by ~20% on average by using aligned
stores for the last 64 bytes.  Performance of random memset benchmark improves
by ~2% on Neoverse V1.

Reviewed-by: Yury Khrustalev <yury.khrustalev@arm.com>
(cherry picked from commit 163b1bbb76caba4d9673c07940c5930a1afa7548)

5 months agomath: Improve layout of expf data
Wilco Dijkstra [Wed, 24 Jul 2024 14:17:47 +0000 (15:17 +0100)] 
math: Improve layout of expf data

GCC aligns global data to 16 bytes if their size is >= 16 bytes.  This patch
changes the exp2f_data struct slightly so that the fields are better aligned.
As a result on targets that support them, load-pair instructions accessing
poly_scaled and invln2_scaled are now 16-byte aligned.

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

5 months agoAArch64: Remove zva_128 from memset
Wilco Dijkstra [Mon, 25 Nov 2024 18:43:08 +0000 (18:43 +0000)] 
AArch64: Remove zva_128 from memset

Remove ZVA 128 support from memset - the new memset no longer
guarantees count >= 256, which can result in underflow and a
crash if ZVA size is 128 ([1]).  Since only one CPU uses a ZVA
size of 128 and its memcpy implementation was removed in commit
e162ab2bf1b82c40f29e1925986582fa07568ce8, remove this special
case too.

[1] https://sourceware.org/pipermail/libc-alpha/2024-November/161626.html

Reviewed-by: Andrew Pinski <quic_apinski@quicinc.com>
(cherry picked from commit a08d9a52f967531a77e1824c23b5368c6434a72d)

5 months agoAArch64: Optimize memset
Wilco Dijkstra [Mon, 9 Sep 2024 14:26:47 +0000 (15:26 +0100)] 
AArch64: Optimize memset

Improve small memsets by avoiding branches and use overlapping stores.
Use DC ZVA for copies over 128 bytes.  Remove unnecessary code for ZVA sizes
other than 64 and 128.  Performance of random memset benchmark improves by 24%
on Neoverse N1.

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

5 months agoAArch64: Improve generic strlen
Wilco Dijkstra [Wed, 7 Aug 2024 13:43:47 +0000 (14:43 +0100)] 
AArch64: Improve generic strlen

Improve performance by handling another 16 bytes before entering the loop.
Use ADDHN in the loop to avoid SHRN+FMOV when it terminates.  Change final
size computation to avoid increasing latency.  On Neoverse V1 performance
of the random strlen benchmark improves by 4.6%.

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

5 months agoassert: Add test for CVE-2025-0395
Siddhesh Poyarekar [Fri, 31 Jan 2025 17:16:30 +0000 (12:16 -0500)] 
assert: Add test for CVE-2025-0395

Use the __progname symbol to override the program name to induce the
failure that CVE-2025-0395 describes.

This is related to BZ #32582

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

5 months agoassert: Reformat Makefile.
Carlos O'Donell [Thu, 18 May 2023 16:56:45 +0000 (12:56 -0400)] 
assert: Reformat Makefile.

Reflow all long lines adding comment terminators.
Sort all reflowed text using scripts/sort-makefile-lines.py.

No code generation changes observed in binary artifacts.
No regressions on x86_64 and i686.

(cherry picked from commit ebd928224a138d4560dc0be3ef162162d62a9e43)

 # Conflicts:
 # assert/Makefile
 (Missing __libc_assert_fail)

6 months agostdlib: Test using setenv with updated environ [BZ #32588]
H.J. Lu [Fri, 24 Jan 2025 10:53:13 +0000 (18:53 +0800)] 
stdlib: Test using setenv with updated environ [BZ #32588]

Add a test for setenv with updated environ.  Verify that BZ #32588 is
fixed.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Florian Weimer <fweimer@redhat.com>
(cherry picked from commit 8ab34497de14e35aff09b607222fe1309ef156da)

6 months agoFix underallocation of abort_msg_s struct (CVE-2025-0395)
Florian Weimer [Wed, 22 Jan 2025 16:22:02 +0000 (17:22 +0100)] 
Fix underallocation of abort_msg_s struct (CVE-2025-0395)

Include the space needed to store the length of the message itself, in
addition to the message string.  This resolves BZ #32582.

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

Conflict in sysdeps/posix/libc_fatal.c due to missing cleanup after
backtrace removal.

6 months agomisc: Add support for Linux uio.h RWF_NOAPPEND flag
Stafford Horne [Wed, 3 Apr 2024 05:40:37 +0000 (06:40 +0100)] 
misc: Add support for Linux uio.h RWF_NOAPPEND flag

In Linux 6.9 a new flag is added to allow for Per-io operations to
disable append mode even if a file was opened with the flag O_APPEND.
This is done with the new RWF_NOAPPEND flag.

This caused two test failures as these tests expected the flag 0x00000020
to be unused.  Adding the flag definition now fixes these tests on Linux
6.9 (v6.9-rc1).

  FAIL: misc/tst-preadvwritev2
  FAIL: misc/tst-preadvwritev64v2

This patch adds the flag, adjusts the test and adds details to
documentation.

Link: https://lore.kernel.org/all/20200831153207.GO3265@brightrain.aerifal.cx/
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
(cherry picked from commit 3db9d208dd5f30b12900989c6d2214782b8e2011)

6 months agoelf: Support recursive use of dynamic TLS in interposed malloc
Florian Weimer [Mon, 1 Jul 2024 15:42:04 +0000 (17:42 +0200)] 
elf: Support recursive use of dynamic TLS in interposed malloc

It turns out that quite a few applications use bundled mallocs that
have been built to use global-dynamic TLS (instead of the recommended
initial-exec TLS).  The previous workaround from
commit afe42e935b3ee97bac9a7064157587777259c60e ("elf: Avoid some
free (NULL) calls in _dl_update_slotinfo") does not fix all
encountered cases unfortunatelly.

This change avoids the TLS generation update for recursive use
of TLS from a malloc that was called during a TLS update.  This
is possible because an interposed malloc has a fixed module ID and
TLS slot.  (It cannot be unloaded.)  If an initially-loaded module ID
is encountered in __tls_get_addr and the dynamic linker is already
in the middle of a TLS update, use the outdated DTV, thus avoiding
another call into malloc.  It's still necessary to update the
DTV to the most recent generation, to get out of the slow path,
which is why the check for recursion is needed.

The bookkeeping is done using a global counter instead of per-thread
flag because TLS access in the dynamic linker is tricky.

All this will go away once the dynamic linker stops using malloc
for TLS, likely as part of a change that pre-allocates all TLS
during pthread_create/dlopen.

Fixes commit d2123d68275acc0f061e73d5f86ca504e0d5a344 ("elf: Fix slow
tls access after dlopen [BZ #19924]").

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

6 months agoelf: Avoid some free (NULL) calls in _dl_update_slotinfo
Florian Weimer [Mon, 3 Jun 2024 08:49:40 +0000 (10:49 +0200)] 
elf: Avoid some free (NULL) calls in _dl_update_slotinfo

This has been confirmed to work around some interposed mallocs.  Here
is a discussion of the impact test ust/libc-wrapper/test_libc-wrapper
in lttng-tools:

  New TLS usage in libgcc_s.so.1, compatibility impact
  <https://inbox.sourceware.org/libc-alpha/8734v1ieke.fsf@oldenburg.str.redhat.com/>

Reportedly, this patch also papers over a similar issue when tcmalloc
2.9.1 is not compiled with -ftls-model=initial-exec.  Of course the
goal really should be to compile mallocs with the initial-exec TLS
model, but this commit appears to be a useful interim workaround.

Fixes commit d2123d68275acc0f061e73d5f86ca504e0d5a344 ("elf: Fix slow
tls access after dlopen [BZ #19924]").

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

6 months agosysdeps/x86/Makefile: Split and sort tests
H.J. Lu [Thu, 7 Dec 2023 17:00:11 +0000 (09:00 -0800)] 
sysdeps/x86/Makefile: Split and sort tests

Put each test on a separate line and sort tests.

(cherry picked from commit 7e03e0de7e7c2de975b5c5e18f5a4b0c75816674)

6 months agox86: Only align destination to 1x VEC_SIZE in memset 4x loop
Noah Goldstein [Wed, 1 Nov 2023 20:30:26 +0000 (15:30 -0500)] 
x86: Only align destination to 1x VEC_SIZE in memset 4x loop

Current code aligns to 2x VEC_SIZE. Aligning to 2x has no affect on
performance other than potentially resulting in an additional
iteration of the loop.
1x maintains aligned stores (the only reason to align in this case)
and doesn't incur any unnecessary loop iterations.
Reviewed-by: Sunil K Pandey <skpgkp2@gmail.com>
(cherry picked from commit 9469261cf1924d350feeec64d2c80cafbbdcdd4d)

6 months agoelf: Fix slow tls access after dlopen [BZ #19924]
Szabolcs Nagy [Tue, 16 Feb 2021 12:55:13 +0000 (12:55 +0000)] 
elf: Fix slow tls access after dlopen [BZ #19924]

In short: __tls_get_addr checks the global generation counter and if
the current dtv is older then _dl_update_slotinfo updates dtv up to the
generation of the accessed module. So if the global generation is newer
than generation of the module then __tls_get_addr keeps hitting the
slow dtv update path. The dtv update path includes a number of checks
to see if any update is needed and this already causes measurable tls
access slow down after dlopen.

It may be possible to detect up-to-date dtv faster.  But if there are
many modules loaded (> TLS_SLOTINFO_SURPLUS) then this requires at
least walking the slotinfo list.

This patch tries to update the dtv to the global generation instead, so
after a dlopen the tls access slow path is only hit once.  The modules
with larger generation than the accessed one were not necessarily
synchronized before, so additional synchronization is needed.

This patch uses acquire/release synchronization when accessing the
generation counter.

Note: in the x86_64 version of dl-tls.c the generation is only loaded
once, since relaxed mo is not faster than acquire mo load.

I have not benchmarked this. Tested by Adhemerval Zanella on aarch64,
powerpc, sparc, x86 who reported that it fixes the performance issue
of bug 19924.

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

6 months agox86: Check the lower byte of EAX of CPUID leaf 2 [BZ #30643]
H.J. Lu [Mon, 28 Aug 2023 19:08:14 +0000 (12:08 -0700)] 
x86: Check the lower byte of EAX of CPUID leaf 2 [BZ #30643]

The old Intel software developer manual specified that the low byte of
EAX of CPUID leaf 2 returned 1 which indicated the number of rounds of
CPUDID leaf 2 was needed to retrieve the complete cache information. The
newer Intel manual has been changed to that it should always return 1
and be ignored.  If the lower byte isn't 1, CPUID leaf 2 can't be used.
In this case, we ignore CPUID leaf 2 and use CPUID leaf 4 instead.  If
CPUID leaf 4 doesn't contain the cache information, cache information
isn't available at all.  This addresses BZ #30643.

(cherry picked from commit 1493622f4f9048ffede3fbedb64695efa49d662a)

6 months agox86_64: Add log1p with FMA
H.J. Lu [Thu, 17 Aug 2023 16:42:29 +0000 (09:42 -0700)] 
x86_64: Add log1p with FMA

On Skylake, it changes log1p bench performance by:

        Before       After     Improvement
max     63.349       58.347       8%
min     4.448        5.651        -30%
mean    12.0674      10.336       14%

The minimum code path is

 if (hx < 0x3FDA827A)                          /* x < 0.41422  */
    {
      if (__glibc_unlikely (ax >= 0x3ff00000))           /* x <= -1.0 */
        {
   ...
        }
      if (__glibc_unlikely (ax < 0x3e200000))           /* |x| < 2**-29 */
        {
          math_force_eval (two54 + x);          /* raise inexact */
          if (ax < 0x3c900000)                  /* |x| < 2**-54 */
            {
      ...
            }
          else
            return x - x * x * 0.5;

FMA and non-FMA code sequences look similar.  Non-FMA version is slightly
faster.  Since log1p is called by asinh and atanh, it improves asinh
performance by:

        Before       After     Improvement
max     75.645       63.135       16%
min     10.074       10.071       0%
mean    15.9483      14.9089      6%

and improves atanh performance by:

        Before       After     Improvement
max     91.768       75.081       18%
min     15.548       13.883       10%
mean    18.3713      16.8011      8%

(cherry picked from commit a8ecb126d4c26c52f4ad828c566afe4043a28155)

6 months agox86_64: Add expm1 with FMA
H.J. Lu [Fri, 11 Aug 2023 15:04:08 +0000 (08:04 -0700)] 
x86_64: Add expm1 with FMA

On Skylake, it improves expm1 bench performance by:

        Before       After     Improvement
max     70.204       68.054       3%
min     20.709       16.2         22%
mean    22.1221      16.7367      24%

NB: Add

extern long double __expm1l (long double);
extern long double __expm1f128 (long double);

for __typeof (__expm1l) and __typeof (__expm1f128) when __expm1 is
defined since __expm1 may be expanded in their declarations which
causes the build failure.

(cherry picked from commit 1b214630ce6f7e0099b8b6f87246246739b079cf)

6 months agox86_64: Add log2 with FMA
H.J. Lu [Thu, 10 Aug 2023 18:24:30 +0000 (11:24 -0700)] 
x86_64: Add log2 with FMA

On Skylake, it improves log2 bench performance by:

        Before       After     Improvement
max     208.779      63.827       69%
min     9.977        6.55         34%
mean    10.366       6.8191       34%

(cherry picked from commit f6b10ed8e9a00de49d0951e760cc2b5288862b47)

6 months agox86_64: Sort fpu/multiarch/Makefile
H.J. Lu [Wed, 9 Aug 2023 18:08:52 +0000 (11:08 -0700)] 
x86_64: Sort fpu/multiarch/Makefile

Sort Makefile variables using scripts/sort-makefile-lines.py.

No code generation changes observed in libm.  No regressions on x86_64.

(cherry picked from commit 881546979d0219c18337e1b4f4d00cfacab13c40)

6 months agonptl: Convert tst-setuid2 to test-driver
Yu Chien Peter Lin [Fri, 30 Sep 2022 12:19:51 +0000 (20:19 +0800)] 
nptl: Convert tst-setuid2 to test-driver

Use <support/test-driver.c> and replace pthread calls to its xpthread
equivalents.

Signed-off-by: Yu Chien Peter Lin <peterlin@andestech.com>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
(cherry picked from commit 365b3af67ecaf176b2e2678afe903bebce598fd7)

6 months agosupport: Add xpthread_cond_signal wrapper
Yu Chien Peter Lin [Fri, 30 Sep 2022 12:19:50 +0000 (20:19 +0800)] 
support: Add xpthread_cond_signal wrapper

Signed-off-by: Yu Chien Peter Lin <peterlin@andestech.com>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
(cherry picked from commit 3bea50ccbc925d4fc5f85ec402b6154cbe770b71)

7 months agox86: Avoid integer truncation with large cache sizes (bug 32470)
Florian Weimer [Tue, 17 Dec 2024 17:12:03 +0000 (18:12 +0100)] 
x86: Avoid integer truncation with large cache sizes (bug 32470)

Some hypervisors report 1 TiB L3 cache size.  This results
in some variables incorrectly getting zeroed, causing crashes
in memcpy/memmove because invariants are violated.

(cherry picked from commit 61c3450db96dce96ad2b24b4f0b548e6a46d68e5)

10 months agolibio: Attempt wide backup free only for non-legacy code
Siddhesh Poyarekar [Tue, 3 Sep 2024 18:58:33 +0000 (14:58 -0400)] 
libio: Attempt wide backup free only for non-legacy code

_wide_data and _mode are not available in legacy code, so do not attempt
to free the wide backup buffer in legacy code.

Resolves: BZ #32137 and BZ #27821

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

11 months agonptl: Use <support/check.h> facilities in tst-setuid3
Maciej W. Rozycki [Fri, 26 Jul 2024 12:21:34 +0000 (13:21 +0100)] 
nptl: Use <support/check.h> facilities in tst-setuid3

Remove local FAIL macro in favor to FAIL_EXIT1 from <support/check.h>,
which provides equivalent reporting, with the name of the file and the
line number within of the failure site additionally included.  Remove
FAIL_ERR altogether and include ": %m" explicitly with the format string
supplied to FAIL_EXIT1 as there seems little value to have a separate
macro just for this.

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

11 months agoposix: Use <support/check.h> facilities in tst-truncate and tst-truncate64
Maciej W. Rozycki [Fri, 26 Jul 2024 12:21:34 +0000 (13:21 +0100)] 
posix: Use <support/check.h> facilities in tst-truncate and tst-truncate64

Remove local FAIL macro in favor to FAIL_RET from <support/check.h>,
which provides equivalent reporting, with the name of the file of the
failure site additionally included, for the tst-truncate-common core
shared between the tst-truncate and tst-truncate64 tests.

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

11 months agoungetc: Fix backup buffer leak on program exit [BZ #27821]
Siddhesh Poyarekar [Wed, 14 Aug 2024 01:08:49 +0000 (21:08 -0400)] 
ungetc: Fix backup buffer leak on program exit [BZ #27821]

If a file descriptor is left unclosed and is cleaned up by _IO_cleanup
on exit, its backup buffer remains unfreed, registering as a leak in
valgrind.  This is not strictly an issue since (1) the program should
ideally be closing the stream once it's not in use and (2) the program
is about to exit anyway, so keeping the backup buffer around a wee bit
longer isn't a real problem.  Free it anyway to keep valgrind happy
when the streams in question are the standard ones, i.e. stdout, stdin
or stderr.

Also, the _IO_have_backup macro checks for _IO_save_base,
which is a roundabout way to check for a backup buffer instead of
directly looking for _IO_backup_base.  The roundabout check breaks when
the main get area has not been used and user pushes a char into the
backup buffer with ungetc.  Fix this to use the _IO_backup_base
directly.

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

11 months agoungetc: Fix uninitialized read when putting into unused streams [BZ #27821]
Siddhesh Poyarekar [Wed, 14 Aug 2024 01:00:06 +0000 (21:00 -0400)] 
ungetc: Fix uninitialized read when putting into unused streams [BZ #27821]

When ungetc is called on an unused stream, the backup buffer is
allocated without the main get area being present.  This results in
every subsequent ungetc (as the stream remains in the backup area)
checking uninitialized memory in the backup buffer when trying to put a
character back into the stream.

Avoid comparing the input character with buffer contents when in backup
to avoid this uninitialized read.  The uninitialized read is harmless in
this context since the location is promptly overwritten with the input
character, thus fulfilling ungetc functionality.

Also adjust wording in the manual to drop the paragraph that says glibc
cannot do multiple ungetc back to back since with this change, ungetc
can actually do this.

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

11 months agoMake tst-ungetc use libsupport
Siddhesh Poyarekar [Wed, 14 Aug 2024 23:20:04 +0000 (19:20 -0400)] 
Make tst-ungetc use libsupport

Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
(cherry picked from commit 3f7df7e757f4efec38e45d4068e5492efcac4856)
(cherry picked from commit 87a1968a72e4b4e5436f3e2be1ed8a8d5a5862c7)

11 months agostdio-common: Add test for vfscanf with matches longer than INT_MAX [BZ #27650]
Maciej W. Rozycki [Fri, 26 Jul 2024 12:21:34 +0000 (13:21 +0100)] 
stdio-common: Add test for vfscanf with matches longer than INT_MAX [BZ #27650]

Complement commit b03e4d7bd25b ("stdio: fix vfscanf with matches longer
than INT_MAX (bug 27650)") and add a test case for the issue, inspired
by the reproducer provided with the bug report.

This has been verified to succeed as from the commit referred and fail
beforehand.

As the test requires 2GiB of data to be passed around its performance
has been evaluated using a choice of systems and the execution time
determined to be respectively in the range of 9s for POWER9@2.166GHz,
24s for FU740@1.2GHz, and 40s for 74Kf@950MHz.  As this is on the verge
of and beyond the default timeout it has been increased by the factor of
8.  Regardless, following recent practice the test has been added to the
standard rather than extended set.

Reviewed-by: DJ Delorie <dj@redhat.com>
(cherry picked from commit 89cddc8a7096f3d9225868304d2bc0a1aaf07d63)
(cherry picked from commit 99ffa84bdcdc3d81e82f448279f0c8278dd30964)

11 months agosupport: Add FAIL test failure helper
Maciej W. Rozycki [Fri, 26 Jul 2024 12:21:34 +0000 (13:21 +0100)] 
support: Add FAIL test failure helper

Add a FAIL test failure helper analogous to FAIL_RET, that does not
cause the current function to return, providing a standardized way to
report a test failure with a message supplied while permitting the
caller to continue executing, for further reporting, cleaning up, etc.

Update existing test cases that provide a conflicting definition of FAIL
by removing the local FAIL definition and then as follows:

- tst-fortify-syslog: provide a meaningful message in addition to the
  file name already added by <support/check.h>; 'support_record_failure'
  is already called by 'support_print_failure_impl' invoked by the new
  FAIL test failure helper.

- tst-ctype: no update to FAIL calls required, with the name of the file
  and the line number within of the failure site additionally included
  by the new FAIL test failure helper, and error counting plus count
  reporting upon test program termination also already provided by
  'support_record_failure' and 'support_report_failure' respectively,
  called by 'support_print_failure_impl' and 'adjust_exit_status' also
  respectively.  However in a number of places 'printf' is called and
  the error count adjusted by hand, so update these places to make use
  of FAIL instead.  And last but not least adjust the final summary just
  to report completion, with any error count following as reported by
  the test driver.

- test-tgmath2: no update to FAIL calls required, with the name of the
  file of the failure site additionally included by the new FAIL test
  failure helper.  Also there is no need to track the return status by
  hand as any call to FAIL will eventually cause the test case to return
  an unsuccesful exit status regardless of the return status from the
  test function, via a call to 'adjust_exit_status' made by the test
  driver.

Reviewed-by: DJ Delorie <dj@redhat.com>
(cherry picked from commit 1b97a9f23bf605ca608162089c94187573fb2a9e)
(cherry picked from commit 28f358bc4209ab0425170cdccf65bb1fe861148f)

11 months agostdio-common: Reformat Makefile.
Carlos O'Donell [Thu, 11 May 2023 18:00:41 +0000 (14:00 -0400)] 
stdio-common: Reformat Makefile.

Reflow Makefile.
Sort using scripts/sort-makefile-lines.py.

Code generation is changed as routines are linked in sorted order
as expected.

No regressions on x86_64 and i686.

(cherry picked from commit c3004417afc98585089a9282d1d4d60cdef5317a)
(cherry picked from commit 5b4e90230b8147e273585bf296bf1a9fb6e2b4c2)

11 months agoFix name space violation in fortify wrappers (bug 32052)
Andreas Schwab [Mon, 5 Aug 2024 08:55:51 +0000 (10:55 +0200)] 
Fix name space violation in fortify wrappers (bug 32052)

Rename the identifier sz to __sz everywhere.

Fixes: a643f60c53 ("Make sure that the fortified function conditionals are constant")
(cherry picked from commit 39ca997ab378990d5ac1aadbaa52aaf1db6d526f)
(redone from scratch because of many conflicts)

11 months agoresolv: Fix tst-resolv-short-response for older GCC (bug 32042)
Florian Weimer [Thu, 1 Aug 2024 08:46:10 +0000 (10:46 +0200)] 
resolv: Fix tst-resolv-short-response for older GCC (bug 32042)

Previous GCC versions do not support the C23 change that
allows labels on declarations.

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

12 months agoresolv: Track single-request fallback via _res._flags (bug 31476)
Florian Weimer [Thu, 13 Jun 2024 16:56:30 +0000 (18:56 +0200)] 
resolv: Track single-request fallback via _res._flags (bug 31476)

This avoids changing _res.options, which inteferes with change
detection as part of automatic reloading of /etc/resolv.conf.

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

12 months agoresolv: Do not wait for non-existing second DNS response after error (bug 30081)
Florian Weimer [Wed, 24 Jul 2024 10:06:47 +0000 (12:06 +0200)] 
resolv: Do not wait for non-existing second DNS response after error (bug 30081)

In single-request mode, there is no second response after an error
because the second query has not been sent yet.  Waiting for it
introduces an unnecessary timeout.

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

12 months agoresolv: Allow short error responses to match any query (bug 31890)
Florian Weimer [Wed, 24 Jul 2024 10:06:47 +0000 (12:06 +0200)] 
resolv: Allow short error responses to match any query (bug 31890)

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

12 months agos390x: Fix segfault in wcsncmp [BZ #31934]
Stefan Liebler [Thu, 11 Jul 2024 09:28:53 +0000 (11:28 +0200)] 
s390x: Fix segfault in wcsncmp [BZ #31934]

The z13/vector-optimized wcsncmp implementation segfaults if n=1
and there is only one character (equal on both strings) before
the page end.  Then it loads and compares one character and misses
to check n again.  The following load fails.

This patch removes the extra load and compare of the first character
and just start with the loop which uses vector-load-to-block-boundary.
This code-path also checks n.

With this patch both tests are passing:
- the simplified one mentioned in the bugzilla 31934
- the full one in Florian Weimer's patch:
"manual: Document a GNU extension for strncmp/wcsncmp"
(https://patchwork.sourceware.org/project/glibc/patch/874j9eml6y.fsf@oldenburg.str.redhat.com/):
On s390x-linux-gnu (z16), the new wcsncmp test fails due to bug 31934.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
(cherry picked from commit 9b7651410375ec8848a1944992d663d514db4ba7)

14 months agoForce DT_RPATH for --enable-hardcoded-path-in-tests
H.J. Lu [Fri, 10 May 2024 03:07:01 +0000 (20:07 -0700)] 
Force DT_RPATH for --enable-hardcoded-path-in-tests

On Fedora 40/x86-64, linker enables --enable-new-dtags by default which
generates DT_RUNPATH instead of DT_RPATH.  Unlike DT_RPATH, DT_RUNPATH
only applies to DT_NEEDED entries in the executable and doesn't applies
to DT_NEEDED entries in shared libraries which are loaded via DT_NEEDED
entries in the executable.  Some glibc tests have libstdc++.so.6 in
DT_NEEDED, which has libm.so.6 in DT_NEEDED.  When DT_RUNPATH is generated,
/lib64/libm.so.6 is loaded for such tests.  If the newly built glibc is
older than glibc 2.36, these tests fail with

assert/tst-assert-c++: /export/build/gnu/tools-build/glibc-gitlab-release/build-x86_64-linux/libc.so.6: version `GLIBC_2.36' not found (required by /lib64/libm.so.6)
assert/tst-assert-c++: /export/build/gnu/tools-build/glibc-gitlab-release/build-x86_64-linux/libc.so.6: version `GLIBC_ABI_DT_RELR' not found (required by /lib64/libm.so.6)

Pass -Wl,--disable-new-dtags to linker when building glibc tests with
--enable-hardcoded-path-in-tests.  This fixes BZ #31719.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
(cherry picked from commit 2dcaf70643710e22f92a351e36e3cff8b48c60dc)

14 months agoelf: Disable some subtests of ifuncmain1, ifuncmain5 for !PIE
Florian Weimer [Fri, 4 Nov 2022 17:37:16 +0000 (18:37 +0100)] 
elf: Disable some subtests of ifuncmain1, ifuncmain5 for !PIE

(cherry picked from commit 9cc9d61ee12f2f8620d8e0ea3c42af02bf07fe1e)

14 months agonscd: Use time_t for return type of addgetnetgrentX
Florian Weimer [Thu, 2 May 2024 15:06:19 +0000 (17:06 +0200)] 
nscd: Use time_t for return type of addgetnetgrentX

Using int may give false results for future dates (timeouts after the
year 2028).

Fixes commit 04a21e050d64a1193a6daab872bca2528bda44b ("CVE-2024-33601,
CVE-2024-33602: nscd: netgroup: Use two buffers in addgetnetgrentX
(bug 31680)").

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

14 months agologin: structs utmp, utmpx, lastlog _TIME_BITS independence (bug 30701)
Florian Weimer [Fri, 19 Apr 2024 12:38:17 +0000 (14:38 +0200)] 
login: structs utmp, utmpx, lastlog _TIME_BITS independence (bug 30701)

These structs describe file formats under /var/log, and should not
depend on the definition of _TIME_BITS.  This is achieved by
defining __WORDSIZE_TIME64_COMPAT32 to 1 on 32-bit ports that
support 32-bit time_t values (where __time_t is 32 bits).

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

14 months agologin: Check default sizes of structs utmp, utmpx, lastlog
Florian Weimer [Fri, 19 Apr 2024 12:38:17 +0000 (14:38 +0200)] 
login: Check default sizes of structs utmp, utmpx, lastlog

The default <utmp-size.h> is for ports with a 64-bit time_t.
Ports with a 32-bit time_t or with __WORDSIZE_TIME64_COMPAT32=1
need to override it.

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

14 months agosparc: Remove 64 bit check on sparc32 wordsize (BZ 27574)
Adhemerval Zanella [Wed, 17 Jan 2024 13:13:06 +0000 (10:13 -0300)] 
sparc: Remove 64 bit check on sparc32 wordsize (BZ 27574)

The sparc32 is always 32 bits.

Checked on sparcv9-linux-gnu.

(cherry picked from commit dd57f5e7b652772499cb220d78157c1038d24f06)

14 months agomalloc: Exit early on test failure in tst-realloc
Florian Weimer [Thu, 10 Mar 2022 07:50:51 +0000 (08:50 +0100)] 
malloc: Exit early on test failure in tst-realloc

This addresses more (correct) use-after-free warnings reported by
GCC 12 on some targets.

Fixes commit c094c232eb3246154265bb035182f92fe1b17ab8 ("Avoid
-Wuse-after-free in tests [BZ #26779].").

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

15 months agoCVE-2024-33601, CVE-2024-33602: nscd: netgroup: Use two buffers in addgetnetgrentX...
Florian Weimer [Thu, 25 Apr 2024 13:01:07 +0000 (15:01 +0200)] 
CVE-2024-33601, CVE-2024-33602: nscd: netgroup: Use two buffers in addgetnetgrentX (bug 31680)

This avoids potential memory corruption when the underlying NSS
callback function does not use the buffer space to store all strings
(e.g., for constant strings).

Instead of custom buffer management, two scratch buffers are used.
This increases stack usage somewhat.

Scratch buffer allocation failure is handled by return -1
(an invalid timeout value) instead of terminating the process.
This fixes bug 31679.

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

15 months agoCVE-2024-33600: nscd: Avoid null pointer crashes after notfound response (bug 31678)
Florian Weimer [Thu, 25 Apr 2024 13:01:07 +0000 (15:01 +0200)] 
CVE-2024-33600: nscd: Avoid null pointer crashes after notfound response (bug 31678)

The addgetnetgrentX call in addinnetgrX may have failed to produce
a result, so the result variable in addinnetgrX can be NULL.
Use db->negtimeout as the fallback value if there is no result data;
the timeout is also overwritten below.

Also avoid sending a second not-found response.  (The client
disconnects after receiving the first response, so the data stream did
not go out of sync even without this fix.)  It is still beneficial to
add the negative response to the mapping, so that the client can get
it from there in the future, instead of going through the socket.

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

15 months agoCVE-2024-33600: nscd: Do not send missing not-found response in addgetnetgrentX ...
Florian Weimer [Thu, 25 Apr 2024 13:01:07 +0000 (15:01 +0200)] 
CVE-2024-33600: nscd: Do not send missing not-found response in addgetnetgrentX (bug 31678)

If we failed to add a not-found response to the cache, the dataset
point can be null, resulting in a null pointer dereference.

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

15 months agoCVE-2024-33599: nscd: Stack-based buffer overflow in netgroup cache (bug 31677)
Florian Weimer [Thu, 25 Apr 2024 13:00:45 +0000 (15:00 +0200)] 
CVE-2024-33599: nscd: Stack-based buffer overflow in netgroup cache (bug 31677)

Using alloca matches what other caches do.  The request length is
bounded by MAXKEYLEN.

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

15 months agoiconv: ISO-2022-CN-EXT: fix out-of-bound writes when writing escape sequence (CVE...
Charles Fol [Thu, 28 Mar 2024 15:25:38 +0000 (12:25 -0300)] 
iconv: ISO-2022-CN-EXT: fix out-of-bound writes when writing escape sequence (CVE-2024-2961)

ISO-2022-CN-EXT uses escape sequences to indicate character set changes
(as specified by RFC 1922).  While the SOdesignation has the expected
bounds checks, neither SS2designation nor SS3designation have its;
allowing a write overflow of 1, 2, or 3 bytes with fixed values:
'$+I', '$+J', '$+K', '$+L', '$+M', or '$*H'.

Checked on aarch64-linux-gnu.

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

15 months agopowerpc: Fix ld.so address determination for PCREL mode (bug 31640)
Florian Weimer [Sun, 14 Apr 2024 06:24:51 +0000 (08:24 +0200)] 
powerpc: Fix ld.so address determination for PCREL mode (bug 31640)

This seems to have stopped working with some GCC 14 versions,
which clobber r2.  With other compilers, the kernel-provided
r2 value is still available at this point.

Reviewed-by: Peter Bergner <bergner@linux.ibm.com>
(cherry picked from commit 14e56bd4ce15ac2d1cc43f762eb2e6b83fec1afe)

15 months agoAArch64: Check kernel version for SVE ifuncs
Wilco Dijkstra [Thu, 21 Mar 2024 16:48:33 +0000 (16:48 +0000)] 
AArch64: Check kernel version for SVE ifuncs

Old Linux kernels disable SVE after every system call.  Calling the
SVE-optimized memcpy afterwards will then cause a trap to reenable SVE.
As a result, applications with a high use of syscalls may run slower with
the SVE memcpy.  This is true for kernels between 4.15.0 and before 6.2.0,
except for 5.14.0 which was patched.  Avoid this by checking the kernel
version and selecting the SVE ifunc on modern kernels.

Parse the kernel version reported by uname() into a 24-bit kernel.major.minor
value without calling any library functions.  If uname() is not supported or
if the version format is not recognized, assume the kernel is modern.

Tested-by: Florian Weimer <fweimer@redhat.com>
Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
(cherry picked from commit 2e94e2f5d2bf2de124c8ad7da85463355e54ccb2)

15 months agoaarch64: fix check for SVE support in assembler
Szabolcs Nagy [Wed, 13 Mar 2024 14:34:14 +0000 (14:34 +0000)] 
aarch64: fix check for SVE support in assembler

Due to GCC bug 110901 -mcpu can override -march setting when compiling
asm code and thus a compiler targetting a specific cpu can fail the
configure check even when binutils gas supports SVE.

The workaround is that explicit .arch directive overrides both -mcpu
and -march, and since that's what the actual SVE memcpy uses the
configure check should use that too even if the GCC issue is fixed
independently.

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

15 months agoaarch64: correct CFI in rawmemchr (bug 31113)
Andreas Schwab [Thu, 23 Nov 2023 17:23:46 +0000 (18:23 +0100)] 
aarch64: correct CFI in rawmemchr (bug 31113)

The .cfi_return_column directive changes the return column for the whole
FDE range.  But the actual intent is to tell the unwinder that the value
in x30 (lr) now resides in x15 after the move, and that is expressed by
the .cfi_register directive.

(cherry picked from commit 3f798427884fa57770e8e2291cf58d5918254bb5)

15 months agoAArch64: Remove Falkor memcpy
Wilco Dijkstra [Thu, 26 Oct 2023 16:30:36 +0000 (17:30 +0100)] 
AArch64: Remove Falkor memcpy

The latest implementations of memcpy are actually faster than the Falkor
implementations [1], so remove the falkor/phecda ifuncs for memcpy and
the now unused IS_FALKOR/IS_PHECDA defines.

[1] https://sourceware.org/pipermail/libc-alpha/2022-December/144227.html

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

15 months agoAArch64: Add memset_zva64
Wilco Dijkstra [Thu, 26 Oct 2023 16:07:21 +0000 (17:07 +0100)] 
AArch64: Add memset_zva64

Add a specialized memset for the common ZVA size of 64 to avoid the
overhead of reading the ZVA size.  Since the code is identical to
__memset_falkor, remove the latter.

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

15 months agoAArch64: Cleanup emag memset
Wilco Dijkstra [Thu, 26 Oct 2023 15:34:47 +0000 (16:34 +0100)] 
AArch64: Cleanup emag memset

Cleanup emag memset - merge the memset_base64.S file, remove
the unused ZVA code (since it is disabled on emag).

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

15 months agoAArch64: Cleanup ifuncs
Wilco Dijkstra [Tue, 24 Oct 2023 12:51:07 +0000 (13:51 +0100)] 
AArch64: Cleanup ifuncs

Cleanup ifuncs.  Remove uses of libc_hidden_builtin_def, use ENTRY rather than
ENTRY_ALIGN, remove unnecessary defines and conditional compilation.  Rename
strlen_mte to strlen_generic.  Remove rtld-memset.

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

15 months agoAArch64: Add support for MOPS memcpy/memmove/memset
Wilco Dijkstra [Tue, 17 Oct 2023 15:54:21 +0000 (16:54 +0100)] 
AArch64: Add support for MOPS memcpy/memmove/memset

Add support for MOPS in cpu_features and INIT_ARCH.  Add ifuncs using MOPS for
memcpy, memmove and memset (use .inst for now so it works with all binutils
versions without needing complex configure and conditional compilation).

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

15 months agoAdd HWCAP2_MOPS from Linux 6.5 to AArch64 bits/hwcap.h
Joseph Myers [Tue, 17 Oct 2023 13:13:27 +0000 (13:13 +0000)] 
Add HWCAP2_MOPS from Linux 6.5 to AArch64 bits/hwcap.h

Linux 6.5 adds a new AArch64 HWCAP2 value, HWCAP2_MOPS.  Add it to
glibc's bits/hwcap.h.

Tested with build-many-glibcs.py for aarch64-linux-gnu.

(cherry picked from commit ff5d2abd18629e0efac41e31699cdff3be0e08fa)

15 months agoAArch64: Improve SVE memcpy and memmove
Wilco Dijkstra [Wed, 1 Feb 2023 18:45:19 +0000 (18:45 +0000)] 
AArch64: Improve SVE memcpy and memmove

Improve SVE memcpy by copying 2 vectors if the size is small enough.
This improves performance of random memcpy by ~9% on Neoverse V1, and
33-64 byte copies are ~16% faster.

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

15 months agoAArch64: Improve strrchr
Wilco Dijkstra [Wed, 11 Jan 2023 13:53:19 +0000 (13:53 +0000)] 
AArch64: Improve strrchr

Use shrn for narrowing the mask which simplifies code and speeds up small
strings.  Unroll the first search loop to improve performance on large
strings.

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

15 months agoAArch64: Optimize strnlen
Wilco Dijkstra [Wed, 11 Jan 2023 13:53:05 +0000 (13:53 +0000)] 
AArch64: Optimize strnlen

Optimize strnlen using the shrn instruction and improve the main loop.
Small strings are around 10% faster, large strings are 40% faster on
modern CPUs.

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

15 months agoAArch64: Optimize strlen
Wilco Dijkstra [Wed, 11 Jan 2023 13:52:53 +0000 (13:52 +0000)] 
AArch64: Optimize strlen

Optimize strlen by unrolling the main loop.  Large strings are 64% faster on
modern CPUs.

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

15 months agoAArch64: Optimize strcpy
Wilco Dijkstra [Wed, 11 Jan 2023 13:52:39 +0000 (13:52 +0000)] 
AArch64: Optimize strcpy

Unroll the main loop.  Large strings are around 20% faster on modern CPUs.

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

15 months agoAArch64: Improve strchrnul
Wilco Dijkstra [Wed, 11 Jan 2023 13:52:23 +0000 (13:52 +0000)] 
AArch64: Improve strchrnul

Unroll the main loop, which improves performance slightly.

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

15 months agoAArch64: Optimize strchr
Wilco Dijkstra [Wed, 11 Jan 2023 13:52:08 +0000 (13:52 +0000)] 
AArch64: Optimize strchr

Simplify calculation of the mask using shrn.  Unroll the main loop.
Small strings are 20% faster on modern CPUs.

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

15 months agoAArch64: Improve strlen_asimd
Wilco Dijkstra [Wed, 11 Jan 2023 13:51:48 +0000 (13:51 +0000)] 
AArch64: Improve strlen_asimd

Use shrn for the mask, merge tst+bne into cbnz, and tweak code alignment.
Performance improves slightly as a result.

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

15 months agoAArch64: Optimize memrchr
Wilco Dijkstra [Wed, 11 Jan 2023 13:51:17 +0000 (13:51 +0000)] 
AArch64: Optimize memrchr

Optimize the main loop - large strings are 43% faster on modern CPUs.

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

15 months agoAArch64: Optimize memchr
Wilco Dijkstra [Wed, 11 Jan 2023 13:50:59 +0000 (13:50 +0000)] 
AArch64: Optimize memchr

Optimize the main loop - large strings are 40% faster on modern CPUs.

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

15 months agoaarch64: Use memcpy_simd as the default memcpy
Wilco Dijkstra [Wed, 26 Oct 2022 13:16:50 +0000 (14:16 +0100)] 
aarch64: Use memcpy_simd as the default memcpy

Since __memcpy_simd is the fastest memcpy on almost all cores, replace
the generic memcpy with it.  If SVE is available, a SVE memcpy will be
used by default (including for Neoverse N2).

(cherry picked from commit e6f3fe362f1aab78b1448d69ecdbd9e3872636d3)

15 months agoaarch64: Cleanup memset ifunc
Wilco Dijkstra [Wed, 26 Oct 2022 13:12:55 +0000 (14:12 +0100)] 
aarch64: Cleanup memset ifunc

Cleanup memset ifunc selectors. The A64FX memset relies on a ZVA size of
256, so add an explicit check.

(cherry picked from commit a8e72913fea0c6e2832c50523c60907ffa3b753b)

15 months agoAArch64: Fix typo in sve configure check (BZ# 29394)
Wilco Dijkstra [Thu, 11 Aug 2022 16:52:00 +0000 (17:52 +0100)] 
AArch64: Fix typo in sve configure check (BZ# 29394)

Fix a typo in the SVE configure check. This fixes [BZ# 29394].

(cherry picked from commit 12182ba18dabda791a4f63a11ee2e9d828f40f9b)

15 months agoaarch64: Optimize string functions with shrn instruction
Danila Kutenin [Mon, 27 Jun 2022 16:12:13 +0000 (16:12 +0000)] 
aarch64: Optimize string functions with shrn instruction

We found that string functions were using AND+ADDP
to find the nibble/syndrome mask but there is an easier
opportunity through `SHRN dst.8b, src.8h, 4` (shift
right every 2 bytes by 4 and narrow to 1 byte) and has
same latency on all SIMD ARMv8 targets as ADDP. There
are also possible gaps for memcmp but that's for
another patch.

We see 10-20% savings for small-mid size cases (<=128)
which are primary cases for general workloads.

(cherry picked from commit 3c9980698988ef64072f1fac339b180f52792faf)

15 months agoAArch64: Sort makefile entries
Wilco Dijkstra [Tue, 7 Jun 2022 15:45:46 +0000 (16:45 +0100)] 
AArch64: Sort makefile entries

Sort makefile entries to reduce conflicts.

(cherry picked from commit eea282d9c665392d6959f6d7112ba4bef27701c9)

15 months agoAArch64: Add SVE memcpy
Wilco Dijkstra [Tue, 7 Jun 2022 15:44:35 +0000 (16:44 +0100)] 
AArch64: Add SVE memcpy

Add an initial SVE memcpy implementation.  Copies up to 32 bytes use SVE
vectors which improves the random memcpy benchmark significantly.
Cleanup the memcpy and memmove ifunc selectors.

(cherry picked from commit 9f298bfe1f183804bb54b54ff9071afc0494906c)

15 months agoAArch64: Optimize memcmp
Wilco Dijkstra [Thu, 2 Dec 2021 18:30:55 +0000 (18:30 +0000)] 
AArch64: Optimize memcmp

Rewrite memcmp to improve performance. On small and medium inputs performance
is 10-20% better. Large inputs use a SIMD loop processing 64 bytes per
iteration, which is 30-50% faster depending on the size.

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

17 months agoRevert "elf: Fix wrong break removal from 8ee878592c"
Adhemerval Zanella [Mon, 12 Feb 2024 13:46:19 +0000 (10:46 -0300)] 
Revert "elf: Fix wrong break removal from 8ee878592c"

(2.34 does not have 8ee878592c)

This reverts commit 62ac4b09c4ee66c91478212359b8ac44b4f6a9e2.

17 months agomalloc: Use __get_nprocs on arena_get2 (BZ 30945)
Adhemerval Zanella [Wed, 11 Oct 2023 16:43:56 +0000 (13:43 -0300)] 
malloc: Use __get_nprocs on arena_get2 (BZ 30945)

This restore the 2.33 semantic for arena_get2.  It was changed by
11a02b035b46 to avoid arena_get2 call malloc (back when __get_nproc
was refactored to use an scratch_buffer - 903bc7dcc2acafc).  The
__get_nproc was refactored over then and now it also avoid to call
malloc.

The 11a02b035b46 did not take in consideration any performance
implication, which should have been discussed properly.  The
__get_nprocs_sched is still used as a fallback mechanism if procfs
and sysfs is not acessible.

Checked on x86_64-linux-gnu.
Reviewed-by: DJ Delorie <dj@redhat.com>
(cherry picked from commit 472894d2cfee5751b44c0aaa71ed87df81c8e62e)

17 months agoelf: Fix wrong break removal from 8ee878592c
Adhemerval Zanella [Thu, 7 Dec 2023 14:17:35 +0000 (11:17 -0300)] 
elf: Fix wrong break removal from 8ee878592c

Reported-by: Alexander Monakov <amonakov@ispras.ru>
(cherry picked from commit 546a1ba664626603660b595662249d524e429013)

17 months agox86_64: Optimize ffsll function code size.
Sunil K Pandey [Wed, 26 Jul 2023 15:34:05 +0000 (08:34 -0700)] 
x86_64: Optimize ffsll function code size.

Ffsll function randomly regress by ~20%, depending on how code gets
aligned in memory.  Ffsll function code size is 17 bytes.  Since default
function alignment is 16 bytes, it can load on 16, 32, 48 or 64 bytes
aligned memory.  When ffsll function load at 16, 32 or 64 bytes aligned
memory, entire code fits in single 64 bytes cache line.  When ffsll
function load at 48 bytes aligned memory, it splits in two cache line,
hence random regression.

Ffsll function size reduction from 17 bytes to 12 bytes ensures that it
will always fit in single 64 bytes cache line.

This patch fixes ffsll function random performance regression.

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

19 months agoNEWS: Mention bug fixes for 29039/30745/30843
H.J. Lu [Sat, 23 Dec 2023 14:27:50 +0000 (06:27 -0800)] 
NEWS: Mention bug fixes for 29039/30745/30843

19 months agox86-64: Fix the tcb field load for x32 [BZ #31185]
H.J. Lu [Thu, 21 Dec 2023 03:42:12 +0000 (19:42 -0800)] 
x86-64: Fix the tcb field load for x32 [BZ #31185]

_dl_tlsdesc_undefweak and _dl_tlsdesc_dynamic access the thread pointer
via the tcb field in TCB:

_dl_tlsdesc_undefweak:
        _CET_ENDBR
        movq    8(%rax), %rax
        subq    %fs:0, %rax
        ret

_dl_tlsdesc_dynamic:
...
        subq    %fs:0, %rax
        movq    -8(%rsp), %rdi
        ret

Since the tcb field in TCB is a pointer, %fs:0 is a 32-bit location,
not 64-bit. It should use "sub %fs:0, %RAX_LP" instead.  Since
_dl_tlsdesc_undefweak returns ptrdiff_t and _dl_make_tlsdesc_dynamic
returns void *, RAX_LP is appropriate here for x32 and x86-64.  This
fixes BZ #31185.

(cherry picked from commit 81be2a61dafc168327c1639e97b6dae128c7ccf3)

19 months agox86-64: Fix the dtv field load for x32 [BZ #31184]
H.J. Lu [Thu, 21 Dec 2023 00:31:43 +0000 (16:31 -0800)] 
x86-64: Fix the dtv field load for x32 [BZ #31184]

On x32, I got

FAIL: elf/tst-tlsgap

$ gdb elf/tst-tlsgap
...
open tst-tlsgap-mod1.so

Thread 2 "tst-tlsgap" received signal SIGSEGV, Segmentation fault.
[Switching to LWP 2268754]
_dl_tlsdesc_dynamic () at ../sysdeps/x86_64/dl-tlsdesc.S:108
108 movq (%rsi), %rax
(gdb) p/x $rsi
$4 = 0xf7dbf9005655fb18
(gdb)

This is caused by

_dl_tlsdesc_dynamic:
        _CET_ENDBR
        /* Preserve call-clobbered registers that we modify.
           We need two scratch regs anyway.  */
        movq    %rsi, -16(%rsp)
        movq    %fs:DTV_OFFSET, %rsi

Since the dtv field in TCB is a pointer, %fs:DTV_OFFSET is a 32-bit
location, not 64-bit.  Load the dtv field to RSI_LP instead of rsi.
This fixes BZ #31184.

(cherry picked from commit 3502440397bbb840e2f7223734aa5cc2cc0e29b6)

19 months agoelf: Fix TLS modid reuse generation assignment (BZ 29039)
Hector Martin [Tue, 28 Nov 2023 06:23:07 +0000 (15:23 +0900)] 
elf: Fix TLS modid reuse generation assignment (BZ 29039)

_dl_assign_tls_modid() assigns a slotinfo entry for a new module, but
does *not* do anything to the generation counter. The first time this
happens, the generation is zero and map_generation() returns the current
generation to be used during relocation processing. However, if
a slotinfo entry is later reused, it will already have a generation
assigned. If this generation has fallen behind the current global max
generation, then this causes an obsolete generation to be assigned
during relocation processing, as map_generation() returns this
generation if nonzero. _dl_add_to_slotinfo() eventually resets the
generation, but by then it is too late. This causes DTV updates to be
skipped, leading to NULL or broken TLS slot pointers and segfaults.

Fix this by resetting the generation to zero in _dl_assign_tls_modid(),
so it behaves the same as the first time a slot is assigned.
_dl_add_to_slotinfo() will still assign the correct static generation
later during module load, but relocation processing will no longer use
an obsolete generation.

Note that slotinfo entry (aka modid) reuse typically happens after a
dlclose and only TLS access via dynamic tlsdesc is affected. Because
tlsdesc is optimized to use the optional part of static TLS, dynamic
tlsdesc can be avoided by increasing the glibc.rtld.optional_static_tls
tunable to a large enough value, or by LD_PRELOAD-ing the affected
modules.

Fixes bug 29039.

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

21 months agotunables: Terminate if end of input is reached (CVE-2023-4911)
Siddhesh Poyarekar [Tue, 19 Sep 2023 22:39:32 +0000 (18:39 -0400)] 
tunables: Terminate if end of input is reached (CVE-2023-4911)

The string parsing routine may end up writing beyond bounds of tunestr
if the input tunable string is malformed, of the form name=name=val.
This gets processed twice, first as name=name=val and next as name=val,
resulting in tunestr being name=name=val:name=val, thus overflowing
tunestr.

Terminate the parsing loop at the first instance itself so that tunestr
does not overflow.

This also fixes up tst-env-setuid-tunables to actually handle failures
correct and add new tests to validate the fix for this CVE.

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

22 months agoDocument CVE-2023-4806 and CVE-2023-5156 in NEWS
Siddhesh Poyarekar [Tue, 26 Sep 2023 11:38:07 +0000 (07:38 -0400)] 
Document CVE-2023-4806 and CVE-2023-5156 in NEWS

These are tracked in BZ #30884 and BZ #30843.

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