]> git.ipfire.org Git - thirdparty/glibc.git/log
thirdparty/glibc.git
6 years agox86: Fix Haswell CPU string flags (BZ#23709)
Adhemerval Zanella [Fri, 2 Nov 2018 10:14:05 +0000 (11:14 +0100)] 
x86: Fix Haswell CPU string flags (BZ#23709)

Th commit 'Disable TSX on some Haswell processors.' (2702856bf4) changed the
default flags for Haswell models.  Previously, new models were handled by the
default switch path, which assumed a Core i3/i5/i7 if AVX is available. After
the patch, Haswell models (0x3f, 0x3c, 0x45, 0x46) do not set the flags
Fast_Rep_String, Fast_Unaligned_Load, Fast_Unaligned_Copy, and
Prefer_PMINUB_for_stringop (only the TSX one).

This patch fixes it by disentangle the TSX flag handling from the memory
optimization ones.  The strstr case cited on patch now selects the
__strstr_sse2_unaligned as expected for the Haswell cpu.

Checked on x86_64-linux-gnu.

[BZ #23709]
* sysdeps/x86/cpu-features.c (init_cpu_features): Set TSX bits
independently of other flags.

(cherry picked from commit c3d8dc45c9df199b8334599a6cbd98c9950dba62)

6 years agoDisable -Wrestrict for two nptl/tst-attr3.c tests.
Joseph Myers [Mon, 18 Dec 2017 22:55:28 +0000 (22:55 +0000)] 
Disable -Wrestrict for two nptl/tst-attr3.c tests.

nptl/tst-attr3 fails to build with GCC mainline because of
(deliberate) aliasing between the second (attributes) and fourth
(argument to thread start routine) arguments to pthread_create.

Although both those arguments are restrict-qualified in POSIX,
pthread_create does not actually dereference its fourth argument; it's
an opaque pointer passed to the thread start routine.  Thus, the
aliasing is actually valid in this case, and it's deliberate in the
test.  So this patch makes the test disable -Wrestrict for the two
pthread_create calls in question.  (-Wrestrict was added in GCC 7,
hence the __GNUC_PREREQ conditions, but the particular warning in
question is new in GCC 8.)

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

* nptl/tst-attr3.c: Include <libc-diag.h>.
(do_test) [__GNUC_PREREQ (7, 0)]: Ignore -Wrestrict for two tests.

(cherry picked from commit 40c4162df6766fb1e8ede875ca8df25d8075d3a5)

6 years agoFix string/bug-strncat1.c build with GCC 8.
Joseph Myers [Tue, 14 Nov 2017 17:50:36 +0000 (17:50 +0000)] 
Fix string/bug-strncat1.c build with GCC 8.

GCC 8 warns about strncat calls with truncated output.
string/bug-strncat1.c tests such a call; this patch disables the
warning for it.

Tested (compilation) with GCC 8 for x86_64-linux-gnu with
build-many-glibcs.py (in conjunction with Martin's patch to allow
glibc to build).

* string/bug-strncat1.c: Include <libc-diag.h>.
(main): Disable -Wstringop-truncation for strncat call for GCC 8.

(cherry picked from commit ec72135e5f1d061cb5cf7cd1b855fd6290be10d9)

6 years agoIgnore -Wrestrict for one strncat test.
Joseph Myers [Thu, 14 Jun 2018 14:20:00 +0000 (14:20 +0000)] 
Ignore -Wrestrict for one strncat test.

With current GCC mainline, one strncat test involving a size close to
SIZE_MAX results in a -Wrestrict warning that that buffer size would
imply that the two buffers must overlap.  This patch fixes the build
by adding disabling of -Wrestrict (for GCC versions supporting that
option) to the already-present disabling of -Wstringop-overflow= and
-Warray-bounds for this test.

Tested with build-many-glibcs.py that this restores the testsuite
build with GCC mainline for aarch64-linux-gnu.

* string/tester.c (test_strncat) [__GNUC_PREREQ (7, 0)]: Also
ignore -Wrestrict for one test.

(cherry picked from commit 35ebb6b0c48bc671d9c54e089884f9bf6fca540e)

6 years agoDisable strncat test array-bounds warnings for GCC 8.
Joseph Myers [Mon, 18 Dec 2017 22:52:41 +0000 (22:52 +0000)] 
Disable strncat test array-bounds warnings for GCC 8.

Some strncat tests fail to build with GCC 8 because of -Warray-bounds
warnings.  These tests are deliberately test over-large size arguments
passed to strncat, and already disable -Wstringop-overflow warnings,
but now the warnings for these tests come under -Warray-bounds so that
option needs disabling for them as well, which this patch does (with
an update on the comments; the DIAG_IGNORE_NEEDS_COMMENT call for
-Warray-bounds doesn't need to be conditional itself, because that
option is supported by all versions of GCC that can build glibc).

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

* string/tester.c (test_strncat): Also disable -Warray-bounds
warnings for two tests.

(cherry picked from commit 1421f39b7eadd3b5fbd2a3f2da1fc006b69fbc42)

6 years agoFix string/tester.c build with GCC 8.
Joseph Myers [Tue, 14 Nov 2017 17:52:26 +0000 (17:52 +0000)] 
Fix string/tester.c build with GCC 8.

GCC 8 warns about more cases of string functions truncating their
output or not copying a trailing NUL byte.

This patch fixes testsuite build failures caused by such warnings in
string/tester.c.  In general, the warnings are disabled around the
relevant calls using DIAG_* macros, since the relevant cases are being
deliberately tested.  In one case, the warning is with
-Wstringop-overflow= instead of -Wstringop-truncation; in that case,
the conditional is __GNUC_PREREQ (7, 0) (being the version where
-Wstringop-overflow= was introduced), to allow the conditional to be
removed sooner, since it's harmless to disable the warning for a
GCC version where it doesn't actually occur.  In the case of warnings
for strncpy calls in test_memcmp, the calls in question are changed to
use memcpy, as they don't copy a trailing NUL and the point of that
code is to test memcmp rather than strncpy.

Tested (compilation) with GCC 8 for x86_64-linux-gnu with
build-many-glibcs.py (in conjunction with Martin's patch to allow
glibc to build).

* string/tester.c (test_stpncpy): Disable -Wstringop-truncation
for stpncpy calls for GCC 8.
(test_strncat): Disable -Wstringop-truncation warning for strncat
calls for GCC 8.  Disable -Wstringop-overflow= warning for one
strncat call for GCC 7.
(test_strncpy): Disable -Wstringop-truncation warning for strncpy
calls for GCC 8.
(test_memcmp): Use memcpy instead of strncpy for calls not copying
trailing NUL.

(cherry picked from commit 2e64ec9c9eac3aeb70f7cfa2392846c87c28068e)

6 years agoFix nscd readlink argument aliasing (bug 22446).
Joseph Myers [Mon, 22 Oct 2018 12:08:12 +0000 (14:08 +0200)] 
Fix nscd readlink argument aliasing (bug 22446).

Current GCC mainline detects that nscd calls readlink with the same
buffer for both input and output, which is not valid (those arguments
are both restrict-qualified in POSIX).  This patch makes it use a
separate buffer for readlink's input (with a size that is sufficient
to avoid truncation, so there should be no problems with warnings
about possible truncation, though not strictly minimal, but much
smaller than the buffer for output) to avoid this problem.

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

[BZ #22446]
* nscd/connections.c (handle_request) [SO_PEERCRED]: Use separate
buffers for readlink input and output.

(cherry picked from commit 49b036bce9f021ae994a85aee8b410d20b29c8b7)

6 years agoIncrease buffer size due to warning from ToT GCC
Steve Ellcey [Fri, 15 Dec 2017 17:08:23 +0000 (09:08 -0800)] 
Increase buffer size due to warning from ToT GCC

* nscd/dbg_log.c (dbg_log): Increase msg buffer size.

(cherry picked from commit a7e3edf4f252fb72afeb8ecca946a2d8294bb577)

6 years agoFix p_secstodate overflow handling (bug 22463).
Joseph Myers [Mon, 22 Oct 2018 11:58:06 +0000 (13:58 +0200)] 
Fix p_secstodate overflow handling (bug 22463).

The resolv/res_debug.c function p_secstodate (which is a public
function exported from libresolv, taking an unsigned long argument)
does:

        struct tm timebuf;
        time = __gmtime_r(&clock, &timebuf);
        time->tm_year += 1900;
        time->tm_mon += 1;
        sprintf(output, "%04d%02d%02d%02d%02d%02d",
                time->tm_year, time->tm_mon, time->tm_mday,
                time->tm_hour, time->tm_min, time->tm_sec);

If __gmtime_r returns NULL (because the year overflows the range of
int), this will dereference a null pointer.  Otherwise, if the
computed year does not fit in four characters, this will cause a
buffer overrun of the fixed-size 15-byte buffer.  With current GCC
mainline, there is a compilation failure because of the possible
buffer overrun.

I couldn't find a specification for how this function is meant to
behave, but Paul pointed to RFC 4034 as relevant to the cases where
this function is called from within glibc.  The function's interface
is inherently problematic when dates beyond Y2038 might be involved,
because of the ambiguity in how to interpret 32-bit timestamps as such
dates (the RFC suggests interpreting times as being within 68 years of
the present date, which would mean some kind of interface whose
behavior depends on the present date).

This patch works on the basis of making a minimal fix in preparation
for obsoleting the function.  The function is made to handle times in
the interval [0, 0x7fffffff] only, on all platforms, with <overflow>
used as the output string in other cases (and errno set to EOVERFLOW
in such cases).  This seems to be a reasonable state for the function
to be in when made a compat symbol by a future patch, being compatible
with any existing uses for existing timestamps without trying to work
for later timestamps.  Results independent of the range of time_t also
simplify the testcase.

I couldn't persuade GCC to recognize the ranges of the struct tm
fields by adding explicit range checks with a call to
__builtin_unreachable if outside the range (this looks similar to
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80776>), so having added
a range check on the input, this patch then disables the
-Wformat-overflow= warning for the sprintf call (I prefer that to the
use of strftime, as being more transparently correct without knowing
what each of %m and %M etc. is).

I do not know why this build failure should be new with mainline GCC
(that is, I don't know what GCC change might have introduced it, when
the basic functionality for such warnings was already in GCC 7).

I do not know if this is a security issue (that is, if there are
plausible ways in which a date before -999 or after 9999 from an
untrusted source might end up in this function).  The system clock is
arguably an untrusted source (in that e.g. NTP is insecure), but
probably not to that extent (NTP can't communicate such wild
timestamps), and uses from within glibc are limited to 32-bit inputs.

Tested with build-many-glibcs.py that this restores the build for arm
with yesterday's mainline GCC.  Also tested for x86_64 and x86.

[BZ #22463]
* resolv/res_debug.c: Include <libc-diag.h>.
(p_secstodate): Assert time_t at least as wide as u_long.  On
overflow, use integer seconds since the epoch as output, or use
"<overflow>" as output and set errno to EOVERFLOW if integer
seconds since the epoch would be 14 or more characters.
(p_secstodate) [__GNUC_PREREQ (7, 0)]: Disable -Wformat-overflow=
for sprintf call.
* resolv/tst-p_secstodate.c: New file.
* resolv/Makefile (tests): Add tst-p_secstodate.
($(objpfx)tst-p_secstodate): Depend on $(objpfx)libresolv.so.

(cherry picked from commit f120cda6072d830df92656dad0c89967547b97dc)

6 years agotimezone: pacify GCC -Wstringop-truncation
Paul Eggert [Mon, 13 Nov 2017 06:00:28 +0000 (22:00 -0800)] 
timezone: pacify GCC -Wstringop-truncation

Problem reported by Martin Sebor in:
https://sourceware.org/ml/libc-alpha/2017-11/msg00336.html
* timezone/zic.c (writezone): Use memcpy, not strncpy.

(cherry picked from commit e69897bf202e18034cbef26f363bae64de70a196)

6 years agoutmp: Avoid -Wstringop-truncation warning
Martin Sebor [Thu, 16 Nov 2017 00:39:59 +0000 (17:39 -0700)] 
utmp: Avoid -Wstringop-truncation warning

The -Wstringop-truncation option new in GCC 8 detects common misuses
of the strncat and strncpy function that may result in truncating
the copied string before the terminating NUL.  To avoid false positive
warnings for correct code that intentionally creates sequences of
characters that aren't guaranteed to be NUL-terminated, arrays that
are intended to store such sequences should be decorated with a new
nonstring attribute.  This change add this attribute to Glibc and
uses it to suppress such false positives.

ChangeLog:
* misc/sys/cdefs.h (__attribute_nonstring__): New macro.
* sysdeps/gnu/bits/utmp.h (struct utmp): Use it.
* sysdeps/unix/sysv/linux/s390/bits/utmp.h (struct utmp): Same.

(cherry picked from commit 7532837d7b03b3ca5b9a63d77a5bd81dd23f3d9c)

6 years agoAvoid use of strlen in getlogin_r (bug 22447).
Joseph Myers [Wed, 22 Nov 2017 18:44:23 +0000 (18:44 +0000)] 
Avoid use of strlen in getlogin_r (bug 22447).

Building glibc with current mainline GCC fails, among other reasons,
because of an error for use of strlen on the nonstring ut_user field.
This patch changes the problem code in getlogin_r to use __strnlen
instead.  It also needs to set the trailing NUL byte of the result
explicitly, because of the case where ut_user does not have such a
trailing NUL byte (but the result should always have one).

Tested for x86_64.  Also tested that, in conjunction with
<https://sourceware.org/ml/libc-alpha/2017-11/msg00797.html>, it fixes
the build for arm with mainline GCC.

[BZ #22447]
* sysdeps/unix/getlogin_r.c (__getlogin_r): Use __strnlen not
strlen to compute length of ut_user and set trailing NUL byte of
result explicitly.

(cherry picked from commit 4bae615022cb5a5da79ccda83cc6c9ba9f2d479c)

6 years agosignal: Use correct type for si_band in siginfo_t [BZ #23562]
Ilya Yu. Malakhov [Mon, 22 Oct 2018 11:43:59 +0000 (13:43 +0200)] 
signal: Use correct type for si_band in siginfo_t [BZ #23562]

(cherry picked from commit f997b4be18f7e57d757d39e42f7715db26528aa0)

6 years agoFix misreported errno on preadv2/pwritev2 (BZ#23579)
Adhemerval Zanella [Wed, 29 Aug 2018 19:36:44 +0000 (16:36 -0300)] 
Fix misreported errno on preadv2/pwritev2 (BZ#23579)

The fallback code of Linux wrapper for preadv2/pwritev2 executes
regardless of the errno code for preadv2, instead of the case where
the syscall is not supported.

This fixes it by calling the fallback code iff errno is ENOSYS. The
patch also adds tests for both invalid file descriptor and invalid
iov_len and vector count.

The only discrepancy between preadv2 and fallback code regarding
error reporting is when an invalid flags are used.  The fallback code
bails out earlier with ENOTSUP instead of EINVAL/EBADF when the syscall
is used.

Checked on x86_64-linux-gnu on a 4.4.0 and 4.15.0 kernel.

[BZ #23579]
* misc/tst-preadvwritev2-common.c (do_test_with_invalid_fd): New
test.
* misc/tst-preadvwritev2.c, misc/tst-preadvwritev64v2.c (do_test):
Call do_test_with_invalid_fd.
* sysdeps/unix/sysv/linux/preadv2.c (preadv2): Use fallback code iff
errno is ENOSYS.
* sysdeps/unix/sysv/linux/preadv64v2.c (preadv64v2): Likewise.
* sysdeps/unix/sysv/linux/pwritev2.c (pwritev2): Likewise.
* sysdeps/unix/sysv/linux/pwritev64v2.c (pwritev64v2): Likewise.

(cherry picked from commit 7a16bdbb9ff4122af0a28dc20996c95352011fdd)

6 years agopreadv2/pwritev2: Handle offset == -1 [BZ #22753]
Florian Weimer [Fri, 2 Feb 2018 09:46:26 +0000 (10:46 +0100)] 
preadv2/pwritev2: Handle offset == -1 [BZ #22753]

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

6 years agoFix segfault in maybe_script_execute.
Stefan Liebler [Thu, 6 Sep 2018 12:27:03 +0000 (14:27 +0200)] 
Fix segfault in maybe_script_execute.

If glibc is built with gcc 8 and -march=z900,
the testcase posix/tst-spawn4-compat crashes with a segfault.

In function maybe_script_execute, the new_argv array is dynamically
initialized on stack with (argc + 1) elements.
The function wants to add _PATH_BSHELL as the first argument
and writes out of bounds of new_argv.
There is an off-by-one because maybe_script_execute fails to count
the terminating NULL when sizing new_argv.

ChangeLog:

* sysdeps/unix/sysv/linux/spawni.c (maybe_script_execute):
Increment size of new_argv by one.

(cherry picked from commit 28669f86f6780a18daca264f32d66b1428c9c6f1)

6 years agopthread_cond_broadcast: Fix waiters-after-spinning case [BZ #23538]
Martin Kuchta [Mon, 27 Aug 2018 16:54:46 +0000 (18:54 +0200)] 
pthread_cond_broadcast: Fix waiters-after-spinning case [BZ #23538]

(cherry picked from commit 99ea93ca31795469d2a1f1570f17a5c39c2eb7e2)

7 years agox86: Populate COMMON_CPUID_INDEX_80000001 for Intel CPUs [BZ #23459]
H.J. Lu [Sun, 29 Jul 2018 13:08:59 +0000 (06:08 -0700)] 
x86: Populate COMMON_CPUID_INDEX_80000001 for Intel CPUs [BZ #23459]

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
[BZ #23459]
* sysdeps/x86/cpu-features.c (get_extended_indices): New
function.
(init_cpu_features): Call get_extended_indices for both Intel
and AMD CPUs.
* sysdeps/x86/cpu-features.h (COMMON_CPUID_INDEX_80000001):
Remove "for AMD" comment.

(cherry picked from commit be525a69a6630abc83144c0a96474f2e26da7443)

7 years agox86: Correct index_cpu_LZCNT [BZ #23456]
H.J. Lu [Sun, 29 Jul 2018 13:08:59 +0000 (06:08 -0700)] 
x86: Correct index_cpu_LZCNT [BZ #23456]

cpu-features.h has

 #define bit_cpu_LZCNT (1 << 5)
 #define index_cpu_LZCNT COMMON_CPUID_INDEX_1
 #define reg_LZCNT

But the LZCNT feature bit is in COMMON_CPUID_INDEX_80000001:

Initial EAX Value: 80000001H
ECX Extended Processor Signature and Feature Bits:
Bit 05: LZCNT available

index_cpu_LZCNT should be COMMON_CPUID_INDEX_80000001, not
COMMON_CPUID_INDEX_1.  The VMX feature bit is in COMMON_CPUID_INDEX_1:

Initial EAX Value: 01H
Feature Information Returned in the ECX Register:
5 VMX

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
[BZ #23456]
* sysdeps/x86/cpu-features.h (index_cpu_LZCNT): Set to
COMMON_CPUID_INDEX_80000001.

(cherry picked from commit 65d87ade1ee6f3ac099105e3511bd09bdc24cf3f)

7 years agoconform/conformtest.pl: Escape literal braces in regular expressions
Florian Weimer [Fri, 6 Jul 2018 14:31:24 +0000 (16:31 +0200)] 
conform/conformtest.pl: Escape literal braces in regular expressions

This suppresses Perl warnings like these:

Unescaped left brace in regex is deprecated here (and will be fatal in
Perl 5.32), passed through in regex; marked by <-- HERE in m/^element
*({ <-- HERE ([^}]*)}|([^{ ]*)) *({([^}]*)}|([^{ ]*)) *([A-Za-z0-9_]*)
*(.*)/ at conformtest.pl line 370.

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

7 years agostdio-common/tst-printf.c: Remove part under a non-free license [BZ #23363]
Florian Weimer [Tue, 3 Jul 2018 16:34:26 +0000 (18:34 +0200)] 
stdio-common/tst-printf.c: Remove part under a non-free license [BZ #23363]

The license does not allow modification.

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

7 years agolibio: Add tst-vtables, tst-vtables-interposed
Florian Weimer [Tue, 3 Jul 2018 15:57:14 +0000 (17:57 +0200)] 
libio: Add tst-vtables, tst-vtables-interposed

(cherry picked from commit 29055464a03c72762969a2e8734d0d05d4d70e58)

Some adjustments were needed for a tricky multi-inclusion issue related
to libioP.h.

7 years agoSynchronize support/ infrastructure with master
Florian Weimer [Tue, 3 Jul 2018 16:13:05 +0000 (18:13 +0200)] 
Synchronize support/ infrastructure with master

This commit updates the support/ subdirectory to
commit 5c0202af4b3d588c04bcec7baf05706b21cd7416
on the master branch.

7 years agoNEWS: Reorder out-of-order bugs
Florian Weimer [Tue, 3 Jul 2018 13:58:48 +0000 (15:58 +0200)] 
NEWS: Reorder out-of-order bugs

7 years agolibio: Disable vtable validation in case of interposition [BZ #23313]
Florian Weimer [Tue, 26 Jun 2018 08:24:52 +0000 (10:24 +0200)] 
libio: Disable vtable validation in case of interposition [BZ #23313]

(cherry picked from commit c402355dfa7807b8e0adb27c009135a7e2b9f1b0)

7 years agoCheck length of ifname before copying it into to ifreq structure.
Steve Ellcey [Fri, 29 Jun 2018 15:32:23 +0000 (17:32 +0200)] 
Check length of ifname before copying it into to ifreq structure.

[BZ #22442]
* sysdeps/unix/sysv/linux/if_index.c (__if_nametoindex):
Check if ifname is too long.

(cherry picked from commit 2180fee114b778515b3f560e5ff1e795282e60b0)

7 years agogetifaddrs: Don't return ifa entries with NULL names [BZ #21812]
Daniel Alvarez [Fri, 29 Jun 2018 15:23:13 +0000 (17:23 +0200)] 
getifaddrs: Don't return ifa entries with NULL names [BZ #21812]

A lookup operation in map_newlink could turn into an insert because of
holes in the interface part of the map.  This leads to incorrectly set
the name of the interface to NULL when the interface is not present
for the address being processed (most likely because the interface was
added between the RTM_GETLINK and RTM_GETADDR calls to the kernel).
When such changes are detected by the kernel, it'll mark the dump as
"inconsistent" by setting NLM_F_DUMP_INTR flag on the next netlink
message.

This patch checks this condition and retries the whole operation.
Hopes are that next time the interface corresponding to the address
entry is present in the list and correct name is returned.

(cherry picked from commit c1f86a33ca32e26a9d6e29fc961e5ecb5e2e5eb4)

7 years agoUse _STRUCT_TIMESPEC as guard in <bits/types/struct_timespec.h> [BZ #23349]
Florian Weimer [Thu, 28 Jun 2018 11:22:34 +0000 (13:22 +0200)] 
Use _STRUCT_TIMESPEC as guard in <bits/types/struct_timespec.h> [BZ #23349]

After commit d76d3703551a362b472c866b5b6089f66f8daa8e ("Fix missing
timespec definition for sys/stat.h (BZ #21371)") in combination with
kernel UAPI changes, GCC sanitizer builds start to fail due to a
conflicting definition of struct timespec in <linux/time.h>.  Use
_STRUCT_TIMESPEC as the header file inclusion guard, which is already
checked in the kernel header, to support including <linux/time.h> and
<sys/stat.h> in the same translation unit.

(cherry picked from commit c1c2848b572ea7f92b7fa81dd5b1b9ef7c69b83b)

7 years agoFix parameter type in C++ version of iseqsig (bug 23171)
Gabriel F. T. Gomes [Mon, 14 May 2018 12:04:28 +0000 (09:04 -0300)] 
Fix parameter type in C++ version of iseqsig (bug 23171)

The commit

  commit c85e54ac6cef0faed7b7ffc722f52523dec59bf5
  Author: Gabriel F. T. Gomes <gabriel@inconstante.eti.br>
  Date:   Fri Nov 3 10:44:36 2017 -0200

      Provide a C++ version of iseqsig (bug 22377)

mistakenly used double parameters in the long double version of iseqsig,
thus causing spurious conversions to double, as reported on bug 23171.

Tested for powerpc64le and x86_64.

(cherry picked from commit fb0e10b8eb1ebb68c57d4551f7a95118f3c54837)

7 years agolibio: Avoid _allocate_buffer, _free_buffer function pointers [BZ #23236]
Florian Weimer [Fri, 1 Jun 2018 09:24:58 +0000 (11:24 +0200)] 
libio: Avoid _allocate_buffer, _free_buffer function pointers [BZ #23236]

These unmangled function pointers reside on the heap and could
be targeted by exploit writers, effectively bypassing libio vtable
validation.  Instead, we ignore these pointers and always call
malloc or free.

In theory, this is a backwards-incompatible change, but using the
global heap instead of the user-supplied callback functions should
have little application impact.  (The old libstdc++ implementation
exposed this functionality via a public, undocumented constructor
in its strstreambuf class.)

(cherry picked from commit 4e8a6346cd3da2d88bbad745a1769260d36f2783)

7 years agoAdd NEWS entry for CVE-2018-11236
Florian Weimer [Thu, 24 May 2018 14:27:38 +0000 (16:27 +0200)] 
Add NEWS entry for CVE-2018-11236

7 years agoAdd references to CVE-2018-11236, CVE-2017-18269
Florian Weimer [Thu, 24 May 2018 12:41:57 +0000 (14:41 +0200)] 
Add references to CVE-2018-11236, CVE-2017-18269

7 years agoAdd a test case for [BZ #23196]
H.J. Lu [Wed, 23 May 2018 10:59:56 +0000 (03:59 -0700)] 
Add a test case for [BZ #23196]

[BZ #23196]
* string/test-memcpy.c (do_test1): New function.
(test_main): Call it.

(cherry picked from commit ed983107bbc62245b06b99f02e69acf36a0baa3e)

7 years agoDon't write beyond destination in __mempcpy_avx512_no_vzeroupper (bug 23196)
Andreas Schwab [Thu, 24 May 2018 12:39:18 +0000 (14:39 +0200)] 
Don't write beyond destination in __mempcpy_avx512_no_vzeroupper (bug 23196)

When compiled as mempcpy, the return value is the end of the destination
buffer, thus it cannot be used to refer to the start of it.

(cherry picked from commit 9aaaab7c6e4176e61c59b0a63c6ba906d875dc0e)

7 years agoFix path length overflow in realpath [BZ #22786]
Paul Pluzhnikov [Wed, 9 May 2018 01:12:41 +0000 (18:12 -0700)] 
Fix path length overflow in realpath [BZ #22786]

Integer addition overflow may cause stack buffer overflow
when realpath() input length is close to SSIZE_MAX.

2018-05-09  Paul Pluzhnikov  <ppluzhnikov@google.com>

[BZ #22786]
* stdlib/canonicalize.c (__realpath): Fix overflow in path length
computation.
* stdlib/Makefile (test-bz22786): New test.
* stdlib/test-bz22786.c: New test.

(cherry picked from commit 5460617d1567657621107d895ee2dd83bc1f88f2)

7 years agoFix stack overflow with huge PT_NOTE segment [BZ #20419]
Paul Pluzhnikov [Sun, 6 May 2018 01:08:27 +0000 (18:08 -0700)] 
Fix stack overflow with huge PT_NOTE segment [BZ #20419]

A PT_NOTE in a binary could be arbitratily large, so using alloca
for it may cause stack overflow.  If the note is larger than
__MAX_ALLOCA_CUTOFF, use dynamically allocated memory to read it in.

2018-05-05  Paul Pluzhnikov  <ppluzhnikov@google.com>

[BZ #20419]
* elf/dl-load.c (open_verify): Fix stack overflow.
* elf/Makefile (tst-big-note): New test.
* elf/tst-big-note-lib.S: New.
* elf/tst-big-note.c: New.

(cherry picked from commit 0065aaaaae51cd60210ec3a7e13dddd8e01ffe2c)

7 years agoFix blocking pthread_join. [BZ #23137]
Stefan Liebler [Thu, 17 May 2018 12:05:51 +0000 (14:05 +0200)] 
Fix blocking pthread_join. [BZ #23137]

On s390 (31bit) if glibc is build with -Os, pthread_join sometimes
blocks indefinitely. This is e.g. observable with
testcase intl/tst-gettext6.

pthread_join is calling lll_wait_tid(tid), which performs the futex-wait
syscall in a loop as long as tid != 0 (thread is alive).

On s390 (and build with -Os), tid is loaded from memory before
comparing against zero and then the tid is loaded a second time
in order to pass it to the futex-wait-syscall.
If the thread exits in between, then the futex-wait-syscall is
called with the value zero and it waits until a futex-wake occurs.
As the thread is already exited, there won't be a futex-wake.

In lll_wait_tid, the tid is stored to the local variable __tid,
which is then used as argument for the futex-wait-syscall.
But unfortunately the compiler is allowed to reload the value
from memory.

With this patch, the tid is loaded with atomic_load_acquire.
Then the compiler is not allowed to reload the value for __tid from memory.

ChangeLog:

[BZ #23137]
* sysdeps/nptl/lowlevellock.h (lll_wait_tid):
Use atomic_load_acquire to load __tid.

(cherry picked from commit 1660901840dfc9fde6c5720a32f901af6f08f00a)

7 years agoFix signed integer overflow in random_r (bug 17343).
Joseph Myers [Thu, 17 May 2018 12:04:58 +0000 (14:04 +0200)] 
Fix signed integer overflow in random_r (bug 17343).

Bug 17343 reports that stdlib/random_r.c has code with undefined
behavior because of signed integer overflow on int32_t.  This patch
changes the code so that the possibly overflowing computations use
unsigned arithmetic instead.

Note that the bug report refers to "Most code" in that file.  The
places changed in this patch are the only ones I found where I think
such overflow can occur.

Tested for x86_64 and x86.

[BZ #17343]
* stdlib/random_r.c (__random_r): Use unsigned arithmetic for
possibly overflowing computations.

(cherry picked from commit 8a07b0c43c46a480da070efd53a2720195e2256f)

7 years agoi386: Fix i386 sigaction sa_restorer initialization (BZ#21269)
Adhemerval Zanella [Fri, 17 Nov 2017 18:04:29 +0000 (16:04 -0200)] 
i386: Fix i386 sigaction sa_restorer initialization (BZ#21269)

This patch fixes the i386 sa_restorer field initialization for sigaction
syscall for kernel with vDSO.  As described in bug report, i386 Linux
(and compat on x86_64) interprets SA_RESTORER clear with nonzero
sa_restorer as a request for stack switching if the SS segment is 'funny'.
This means that anything that tries to mix glibc's signal handling with
segmentation (for instance through modify_ldt syscall) is randomly broken
depending on what values lands in sa_restorer.

The testcase added  is based on Linux test tools/testing/selftests/x86/ldt_gdt.c,
more specifically in do_multicpu_tests function.  The main changes are:

  - C11 atomics instead of plain access.

  - Remove x86_64 support which simplifies the syscall handling and fallbacks.

  - Replicate only the test required to trigger the issue.

Checked on i686-linux-gnu.

[BZ #21269]
* sysdeps/unix/sysv/linux/i386/Makefile (tests): Add tst-bz21269.
* sysdeps/unix/sysv/linux/i386/sigaction.c (SET_SA_RESTORER): Clear
sa_restorer for vDSO case.
* sysdeps/unix/sysv/linux/i386/tst-bz21269.c: New file.

(cherry picked from commit 68448be208ee06e76665918b37b0a57e3e00c8b4)

7 years ago[BZ #22342] Fix netgroup cache keys.
DJ Delorie [Fri, 2 Mar 2018 04:20:45 +0000 (23:20 -0500)] 
[BZ #22342] Fix netgroup cache keys.

Unlike other nscd caches, the netgroup cache contains two types of
records - those for "iterate through a netgroup" (i.e. setnetgrent())
and those for "is this user in this netgroup" (i.e. innetgr()),
i.e. full and partial records.  The timeout code assumes these records
have the same key for the group name, so that the collection of records
that is "this netgroup" can be expired as a unit.

However, the keys are not the same, as the in-netgroup key is generated
by nscd rather than being passed to it from elsewhere, and is generated
without the trailing NUL.  All other keys have the trailing NUL, and as
noted in the linked BZ, debug statements confirm that two keys for the
same netgroup are added to the cache with two different lengths.

The result of this is that as records in the cache expire, the purge
code only cleans out one of the two types of entries, resulting in
stale, possibly incorrect, and possibly inconsistent cache data.

The patch simply includes the existing NUL in the computation for the
key length ('key' points to the char after the NUL, and 'group' to the
first char of the group, so 'key-group' includes the first char to the
NUL, inclusive).

[BZ #22342]
* nscd/netgroupcache.c (addinnetgrX): Include trailing NUL in
key value.

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

7 years agoFix i386 memmove issue (bug 22644).
Andrew Senkevich [Thu, 17 May 2018 11:58:21 +0000 (13:58 +0200)] 
Fix i386 memmove issue (bug 22644).

[BZ #22644]
* sysdeps/i386/i686/multiarch/memcpy-sse2-unaligned.S: Fixed
branch conditions.
* string/test-memmove.c (do_test2): New testcase.

(cherry picked from commit cd66c0e584c6d692bc8347b5e72723d02b8a8ada)

7 years agoFix crash in resolver on memory allocation failure (bug 23005)
Andreas Schwab [Thu, 17 May 2018 11:57:29 +0000 (13:57 +0200)] 
Fix crash in resolver on memory allocation failure (bug 23005)

(cherry picked from commit f178e59fa5eefbbd37fde040ae8334aa5c857ee1)

7 years agogetlogin_r: return early when linux sentinel value is set
Jesse Hathaway [Thu, 17 May 2018 11:56:33 +0000 (13:56 +0200)] 
getlogin_r: return early when linux sentinel value is set

When there is no login uid Linux sets /proc/self/loginid to the sentinel
value of, (uid_t) -1. If this is set we can return early and avoid
needlessly looking up the sentinel value in any configured nss
databases.

Checked on aarch64-linux-gnu.

* sysdeps/unix/sysv/linux/getlogin_r.c (__getlogin_r_loginuid): Return
early when linux sentinel value is set.

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

7 years agoresolv: Fully initialize struct mmsghdr in send_dg [BZ #23037]
Florian Weimer [Thu, 17 May 2018 11:54:45 +0000 (13:54 +0200)] 
resolv: Fully initialize struct mmsghdr in send_dg [BZ #23037]

(cherry picked from commit 583a27d525ae189bdfaa6784021b92a9a1dae12e)

7 years agoUpdate NEWS for bug 22343 and bug 22774
Arjun Shankar [Thu, 8 Feb 2018 16:04:17 +0000 (17:04 +0100)] 
Update NEWS for bug 22343 and bug 22774

7 years agoFix integer overflows in internal memalign and malloc [BZ #22343] [BZ #22774]
Arjun Shankar [Thu, 18 Jan 2018 16:47:06 +0000 (16:47 +0000)] 
Fix integer overflows in internal memalign and malloc [BZ #22343] [BZ #22774]

When posix_memalign is called with an alignment less than MALLOC_ALIGNMENT
and a requested size close to SIZE_MAX, it falls back to malloc code
(because the alignment of a block returned by malloc is sufficient to
satisfy the call).  In this case, an integer overflow in _int_malloc leads
to posix_memalign incorrectly returning successfully.

Upon fixing this and writing a somewhat thorough regression test, it was
discovered that when posix_memalign is called with an alignment larger than
MALLOC_ALIGNMENT (so it uses _int_memalign instead) and a requested size
close to SIZE_MAX, a different integer overflow in _int_memalign leads to
posix_memalign incorrectly returning successfully.

Both integer overflows affect other memory allocation functions that use
_int_malloc (one affected malloc in x86) or _int_memalign as well.

This commit fixes both integer overflows.  In addition to this, it adds a
regression test to guard against false successful allocations by the
following memory allocation functions when called with too-large allocation
sizes and, where relevant, various valid alignments:
malloc, realloc, calloc, reallocarray, memalign, posix_memalign,
aligned_alloc, valloc, and pvalloc.

(cherry picked from commit 8e448310d74b283c5cd02b9ed7fb997b47bf9b22)

7 years agopowerpc: Fix syscalls during early process initialization [BZ #22685]
Tulio Magno Quites Machado Filho [Fri, 12 Jan 2018 20:50:33 +0000 (18:50 -0200)] 
powerpc: Fix syscalls during early process initialization [BZ #22685]

The tunables framework needs to execute syscall early in process
initialization, before the TCB is available for consumption.  This
behavior conflicts with powerpc{|64|64le}'s lock elision code, that
checks the TCB before trying to abort transactions immediately before
executing a syscall.

This patch adds a powerpc-specific implementation of __access_noerrno
that does not abort transactions before the executing syscall.

Tested on powerpc{|64|64le}.

[BZ #22685]
* sysdeps/powerpc/powerpc32/sysdep.h (ABORT_TRANSACTION_IMPL): Renamed
from ABORT_TRANSACTION.
(ABORT_TRANSACTION): Redirect to ABORT_TRANSACTION_IMPL.
* sysdeps/powerpc/powerpc64/sysdep.h (ABORT_TRANSACTION,
ABORT_TRANSACTION_IMPL): Likewise.
* sysdeps/unix/sysv/linux/powerpc/not-errno.h: New file.  Reuse
Linux code, but remove the code that aborts transactions.

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

7 years agoProvide a C++ version of iseqsig (bug 22377)
Gabriel F. T. Gomes [Fri, 3 Nov 2017 12:44:36 +0000 (10:44 -0200)] 
Provide a C++ version of iseqsig (bug 22377)

In C++ mode, __MATH_TG cannot be used for defining iseqsig, because
__MATH_TG relies on __builtin_types_compatible_p, which is a C-only
builtin.  This is true when float128 is provided as an ABI-distinct type
from long double.

Moreover, the comparison macros from ISO C take two floating-point
arguments, which need not have the same type.  Choosing what underlying
function to call requires evaluating the formats of the arguments, then
selecting which is wider.  The macro __MATH_EVAL_FMT2 provides this
information, however, only the type of the macro expansion is relevant
(actually evaluating the expression would be incorrect).

This patch provides a C++ version of iseqsig, in which only the type of
__MATH_EVAL_FMT2 (__typeof or decltype) is used as a template parameter
for __iseqsig_type.  This function calls the appropriate underlying
function.

Tested for powerpc64le and x86_64.

[BZ #22377]
* math/Makefile [C++] (tests): Add test for iseqsig.
* math/math.h [C++] (iseqsig): New implementation, which does
not rely on __MATH_TG/__builtin_types_compatible_p.
* math/test-math-iseqsig.cc: New file.
* sysdeps/powerpc/powerpc64le/Makefile
(CFLAGS-test-math-iseqsig.cc): New variable.

(cherry picked from commit c85e54ac6cef0faed7b7ffc722f52523dec59bf5)

7 years ago[AARCH64] Rewrite elf_machine_load_address using _DYNAMIC symbol
Szabolcs Nagy [Wed, 18 Oct 2017 16:26:23 +0000 (17:26 +0100)] 
[AARCH64] Rewrite elf_machine_load_address using _DYNAMIC symbol

This patch rewrites aarch64 elf_machine_load_address to use special _DYNAMIC
symbol instead of _dl_start.

The static address of _DYNAMIC symbol is stored in the first GOT entry.
Here is the change which makes this solution work (part of binutils 2.24):
https://sourceware.org/ml/binutils/2013-06/msg00248.html

i386, x86_64 targets use the same method to do this as well.

The original implementation relies on a trick that R_AARCH64_ABS32 relocation
being resolved at link time and the static address fits in the 32bits.
However, in LP64, normally, the address is defined to be 64 bit.

Here is the C version one which should be portable in all cases.

* sysdeps/aarch64/dl-machine.h (elf_machine_load_address): Use
_DYNAMIC symbol to calculate load address.

(cherry picked from commit a68ba2f3cd3cbe32c1f31e13c20ed13487727b32)

7 years agoNEWS: Add an entry for [BZ #22715]
H.J. Lu [Fri, 19 Jan 2018 17:46:16 +0000 (09:46 -0800)] 
NEWS: Add an entry for [BZ #22715]

7 years agox86-64: Properly align La_x86_64_retval to VEC_SIZE [BZ #22715]
H.J. Lu [Fri, 19 Jan 2018 17:41:12 +0000 (09:41 -0800)] 
x86-64: Properly align La_x86_64_retval to VEC_SIZE [BZ #22715]

_dl_runtime_profile calls _dl_call_pltexit, passing a pointer to
La_x86_64_retval which is allocated on stack.  The lrv_vector0
field in La_x86_64_retval must be aligned to size of vector register.
When allocating stack space for La_x86_64_retval, we need to make sure
that the address of La_x86_64_retval + RV_VECTOR0_OFFSET is aligned to
VEC_SIZE.  This patch checks the alignment of the lrv_vector0 field
and pads the stack space if needed.

Tested with x32 and x86-64 on SSE4, AVX and AVX512 machines.  It fixed

FAIL: elf/tst-audit10
FAIL: elf/tst-audit4
FAIL: elf/tst-audit5
FAIL: elf/tst-audit6
FAIL: elf/tst-audit7

on x32 AVX512 machine.

(cherry picked from commit 207a72e2988c6d6343f50fe0128eb4fc4edfdd15)

[BZ #22715]
* sysdeps/x86_64/dl-trampoline.h (_dl_runtime_profile): Properly
align La_x86_64_retval to VEC_SIZE.

7 years agonptl/tst-thread-exit-clobber: Run with any C++ compiler
Florian Weimer [Tue, 16 Jan 2018 15:46:00 +0000 (16:46 +0100)] 
nptl/tst-thread-exit-clobber: Run with any C++ compiler

We do not need thread_local support in the C++11 comiler, and the
minimum GCC version for glibc has C++11 support (if it has C++ support).

(cherry picked from commit 10d200dbace0ea5198006b313f40c3b884c88724)

7 years agonptl/tst-minstack-throw: Compile in C++11 mode with GNU extensions
Florian Weimer [Tue, 16 Jan 2018 06:19:28 +0000 (07:19 +0100)] 
nptl/tst-minstack-throw: Compile in C++11 mode with GNU extensions

(cherry picked from commit b725132d2b0aeddf970b1ce3e5a24f8637a7b4c2)

7 years agonptl: Add PTHREAD_MIN_STACK C++ throw test [BZ #22636]
Florian Weimer [Mon, 15 Jan 2018 14:30:00 +0000 (15:30 +0100)] 
nptl: Add PTHREAD_MIN_STACK C++ throw test [BZ #22636]

(cherry picked from commit 860b0240a5645edd6490161de3f8d1d1f2786025)

7 years agonptl: Add tst-minstack-cancel, tst-minstack-exit [BZ #22636]
Florian Weimer [Thu, 11 Jan 2018 12:13:14 +0000 (13:13 +0100)] 
nptl: Add tst-minstack-cancel, tst-minstack-exit [BZ #22636]

I verified that without the guard accounting change in commit
630f4cc3aa019ede55976ea561f1a7af2f068639 (Fix stack guard size
accounting) and RTLD_NOW for libgcc_s introduced by commit
f993b8754080ac7572b692870e926d8b493db16c (nptl: Open libgcc.so with
RTLD_NOW during pthread_cancel), the tst-minstack-cancel test fails on
an AVX-512F machine.  tst-minstack-exit still passes, and either of
the mentioned commit by itself frees sufficient stack space to make
tst-minstack-cancel pass, too.

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

7 years agonptl: Open libgcc.so with RTLD_NOW during pthread_cancel [BZ #22636]
Florian Weimer [Mon, 15 Jan 2018 15:05:36 +0000 (16:05 +0100)] 
nptl: Open libgcc.so with RTLD_NOW during pthread_cancel [BZ #22636]

Disabling lazy binding reduces stack usage during unwinding.

Note that RTLD_NOW only makes a difference if libgcc.so has not
already been loaded, so this is only a partial fix.

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

7 years ago[BZ #22637] Fix stack guard size accounting
Szabolcs Nagy [Mon, 15 Jan 2018 15:06:31 +0000 (16:06 +0100)] 
[BZ #22637] Fix stack guard size accounting

Previously if user requested S stack and G guard when creating a
thread, the total mapping was S and the actual available stack was
S - G - static_tls, which is not what the user requested.

This patch fixes the guard size accounting by pretending the user
requested S+G stack.  This way all later logic works out except
when reporting the user requested stack size (pthread_getattr_np)
or when computing the minimal stack size (__pthread_get_minstack).

Normally this will increase thread stack allocations by one page.
TLS accounting is not affected, that will require a separate fix.

[BZ #22637]
* nptl/descr.h (stackblock, stackblock_size): Update comments.
* nptl/allocatestack.c (allocate_stack): Add guardsize to stacksize.
* nptl/nptl-init.c (__pthread_get_minstack): Remove guardsize from
stacksize.
* nptl/pthread_getattr_np.c (pthread_getattr_np): Likewise.

(cherry picked from commit 630f4cc3aa019ede55976ea561f1a7af2f068639)

7 years agonptl: Add test for callee-saved register restore in pthread_exit
Florian Weimer [Mon, 8 Jan 2018 13:57:25 +0000 (14:57 +0100)] 
nptl: Add test for callee-saved register restore in pthread_exit

GCC PR 83641 results in a miscompilation of libpthread, which
causes pthread_exit not to restore callee-saved registers before
running destructors for objects on the stack.  This test detects
this situation:

info: unsigned int, direct pthread_exit call
tst-thread-exit-clobber.cc:80: numeric comparison failure
   left: 4148288912 (0xf741dd90); from: value
  right: 1600833940 (0x5f6ac994); from: magic_values.v2
info: double, direct pthread_exit call
info: unsigned int, indirect pthread_exit call
info: double, indirect pthread_exit call
error: 1 test failures

(cherry picked from commit 579396ee082565ab5f42ff166a264891223b7b82)

7 years agoSynchronize support/ infrastructure with master
Florian Weimer [Mon, 15 Jan 2018 14:23:35 +0000 (15:23 +0100)] 
Synchronize support/ infrastructure with master

This commit updates the support/ subdirectory to
commit 1a51e46e4a87e1cd9528ac5e5656011636e4086b
on the master branch.

7 years agolinux: make getcwd(3) fail if it cannot obtain an absolute path [BZ #22679]
Dmitry V. Levin [Sun, 7 Jan 2018 02:03:41 +0000 (02:03 +0000)] 
linux: make getcwd(3) fail if it cannot obtain an absolute path [BZ #22679]

Currently getcwd(3) can succeed without returning an absolute path
because the underlying getcwd syscall, starting with linux commit
v2.6.36-rc1~96^2~2, may succeed without returning an absolute path.

This is a conformance issue because "The getcwd() function shall
place an absolute pathname of the current working directory
in the array pointed to by buf, and return buf".

This is also a security issue because a non-absolute path returned
by getcwd(3) causes a buffer underflow in realpath(3).

Fix this by checking the path returned by getcwd syscall and falling
back to generic_getcwd if the path is not absolute, effectively making
getcwd(3) fail with ENOENT.  The error code is chosen for consistency
with the case when the current directory is unlinked.

[BZ #22679]
CVE-2018-1000001
* sysdeps/unix/sysv/linux/getcwd.c (__getcwd): Fall back to
generic_getcwd if the path returned by getcwd syscall is not absolute.
* io/tst-getcwd-abspath.c: New test.
* io/Makefile (tests): Add tst-getcwd-abspath.

(cherry picked from commit 52a713fdd0a30e1bd79818e2e3c4ab44ddca1a94)

7 years agoAdd missing reference to bug 20532
Florian Weimer [Fri, 12 Jan 2018 12:32:51 +0000 (13:32 +0100)] 
Add missing reference to bug 20532

7 years agoia64: Fix memchr for large input sizes (BZ #22603)
Adhemerval Zanella [Thu, 14 Dec 2017 11:05:46 +0000 (09:05 -0200)] 
ia64: Fix memchr for large input sizes (BZ #22603)

Current optimized ia64 memchr uses a strategy to check for last address
by adding the input one with expected size.  However it does not take
care for possible overflow.

It was triggered by 3038145ca23 where default rawmemchr now uses memchr
(p, c, (size_t)-1).

This patch fixes it by implement a satured addition where overflows
sets the maximum pointer size to UINTPTR_MAX.

Checked on ia64-linux-gnu where it fixes both stratcliff and
test-rawmemchr failures.

Adhemerval Zanella  <adhemerval.zanella@linaro.org>
James Clarke <jrtc27@jrtc27.com>

[BZ #22603]
* sysdeps/ia64/memchr.S (__memchr): Avoid overflow in pointer
addition.

(cherry picked from commit 3bb1ef58b989012f8199b82af6ec136da2f9fda3)

7 years agotst-ttyname: skip the test when /dev/ptmx is not available
Dmitry V. Levin [Mon, 25 Dec 2017 02:30:32 +0000 (02:30 +0000)] 
tst-ttyname: skip the test when /dev/ptmx is not available

* sysdeps/unix/sysv/linux/tst-ttyname.c (do_in_chroot_1): Skip the
test instead of failing in case of ENOENT returned by posix_openpt.

(cherry picked from commit d7ff3f11b64a28273285d341f795217bbf18ac9c)

7 years agoMention CVE-2017-16997 in ChangeLog
Florian Weimer [Thu, 4 Jan 2018 12:41:27 +0000 (13:41 +0100)] 
Mention CVE-2017-16997 in ChangeLog

7 years agotst-realloc: do not check for errno on success [BZ #22611]
Aurelien Jarno [Fri, 29 Dec 2017 13:44:57 +0000 (14:44 +0100)] 
tst-realloc: do not check for errno on success [BZ #22611]

POSIX explicitly says that applications should check errno only after
failure, so the errno value can be clobbered on success as long as it
is not set to zero.

Changelog:
[BZ #22611]
* malloc/tst-realloc.c (do_test): Remove the test checking that errno
is unchanged on success.
(cherry picked from commit f8aa69be445f65bb36cb3ae9291423600da7d6d2)

7 years agoelf: Check for empty tokens before dynamic string token expansion [BZ #22625]
Aurelien Jarno [Sat, 30 Dec 2017 09:54:23 +0000 (10:54 +0100)] 
elf: Check for empty tokens before dynamic string token expansion [BZ #22625]

The fillin_rpath function in elf/dl-load.c loops over each RPATH or
RUNPATH tokens and interprets empty tokens as the current directory
("./"). In practice the check for empty token is done *after* the
dynamic string token expansion. The expansion process can return an
empty string for the $ORIGIN token if __libc_enable_secure is set
or if the path of the binary can not be determined (/proc not mounted).

Fix that by moving the check for empty tokens before the dynamic string
token expansion. In addition, check for NULL pointer or empty strings
return by expand_dynamic_string_token.

The above changes highlighted a bug in decompose_rpath, an empty array
is represented by the first element being NULL at the fillin_rpath
level, but by using a -1 pointer in decompose_rpath and other functions.

Changelog:
[BZ #22625]
* elf/dl-load.c (fillin_rpath): Check for empty tokens before dynamic
string token expansion. Check for NULL pointer or empty string possibly
returned by expand_dynamic_string_token.
(decompose_rpath): Check for empty path after dynamic string
token expansion.
(cherry picked from commit 3e3c904daef69b8bf7d5cc07f793c9f07c3553ef)

7 years agoelf: do not substitute dst in $LD_LIBRARY_PATH twice [BZ #22627]
Dmitry V. Levin [Sun, 17 Dec 2017 23:49:46 +0000 (23:49 +0000)] 
elf: do not substitute dst in $LD_LIBRARY_PATH twice [BZ #22627]

Starting with commit
glibc-2.18.90-470-g2a939a7e6d81f109d49306bc2e10b4ac9ceed8f9 that
introduced substitution of dynamic string tokens in fillin_rpath,
_dl_init_paths invokes _dl_dst_substitute for $LD_LIBRARY_PATH twice:
the first time it's called directly, the second time the result
is passed on to fillin_rpath which calls expand_dynamic_string_token
which in turn calls _dl_dst_substitute, leading to the following
behaviour:

$ mkdir -p /tmp/'$ORIGIN' && cd /tmp/'$ORIGIN' &&
  echo 'int main(){}' |gcc -xc - &&
  strace -qq -E LD_LIBRARY_PATH='$ORIGIN' -e /open ./a.out
open("/tmp//tmp/$ORIGIN/tls/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/tmp//tmp/$ORIGIN/tls/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/tmp//tmp/$ORIGIN/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/tmp//tmp/$ORIGIN/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
open("/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3

Fix this by removing the direct _dl_dst_substitute invocation.

* elf/dl-load.c (_dl_init_paths): Remove _dl_dst_substitute preparatory
code and invocation.

(cherry picked from commit bb195224acc14724e9fc2dbaa8d0b20b72ace79b)

7 years agotst-ttyname: Fix namespace setup for Fedora
Florian Weimer [Sat, 18 Nov 2017 13:34:46 +0000 (14:34 +0100)] 
tst-ttyname: Fix namespace setup for Fedora

On Fedora, the previous initialization sequence did not work and
resulted in failures like:

info:  entering chroot 1
info:    testcase: basic smoketest
info:      ttyname: PASS {name="/dev/pts/5", errno=0}
info:      ttyname_r: PASS {name="/dev/pts/5", ret=0, errno=0}
error: ../sysdeps/unix/sysv/linux/tst-ttyname.c:122: write (setroups, "deny"): Operation not permitted
info:  entering chroot 2
error: ../sysdeps/unix/sysv/linux/tst-ttyname.c:122: write (setroups, "deny"): Operation not permitted
error: 2 test failures

Reviewed-by: Christian Brauner <christian.brauner@ubuntu.com>
(cherry picked from commit 8db7f48cb74670829df037b2d037df3f36b71ecd)

7 years agolinux ttyname{_r}: Add tests
Luke Shumaker [Wed, 15 Nov 2017 19:39:22 +0000 (20:39 +0100)] 
linux ttyname{_r}: Add tests

Add a new tst-ttyname test that includes several named sub-testcases.

This patch is ordered after the patches with the fixes that it tests for (to
avoid breaking `git bisect`), but for reference, here's how each relevant change
so far affected the testcases in this commit, starting with
15e9a4f378c8607c2ae1aa465436af4321db0e23:

  |                                 | before  |         | make checks | don't |
  |                                 | 15e9a4f | 15e9a4f | consistent  | bail  |
  |---------------------------------+---------+---------+-------------+-------|
  | basic smoketest                 | PASS    | PASS    | PASS        | PASS  |
  | no conflict, no match           | PASS[1] | PASS    | PASS        | PASS  |
  | no conflict, console            | PASS    | FAIL!   | FAIL        | PASS! |
  | conflict, no match              | FAIL    | PASS!   | PASS        | PASS  |
  | conflict, console               | FAIL    | FAIL    | FAIL        | PASS! |
  | with readlink target            | PASS    | PASS    | PASS        | PASS  |
  | with readlink trap; fallback    | FAIL    | FAIL    | FAIL        | PASS! |
  | with readlink trap; no fallback | FAIL    | PASS!   | PASS        | PASS  |
  | with search-path trap           | FAIL    | FAIL    | PASS!       | PASS  |
  |---------------------------------+---------+---------+-------------+-------|
  |                                 | 4/9     | 5/9     | 6/9         | 9/9   |

  [1]: 15e9a4f introduced a semantic that, under certain failure
       conditions, ttyname sets errno=ENODEV, where previously it didn't
       set errno; it's not quite fair to hold "before 15e9a4f" ttyname to
       those new semantics.  This testcase actually fails, but would have
       passed if we tested for the old the semantics.

Each of the failing tests before 15e9a4f are all essentially the same bug: that
it returns a PTY slave with the correct minor device number, but from the wrong
devpts filesystem instance.

15e9a4f sought to fix this, but missed several of the cases that can cause this
to happen, and also broke the case where both the erroneous PTY and the correct
PTY exist.

Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
(cherry picked from commit d9611e308592355718b36fe085b7b61aa52911e5)

7 years agolinux ttyname{_r}: Don't bail prematurely [BZ #22145]
Luke Shumaker [Wed, 15 Nov 2017 19:36:44 +0000 (20:36 +0100)] 
linux ttyname{_r}: Don't bail prematurely [BZ #22145]

Commit 15e9a4f378c8607c2ae1aa465436af4321db0e23 introduced logic for ttyname()
sending back ENODEV to signal that we can't get a name for the TTY because we
inherited it from a different mount namespace.

However, just because we inherited it from a different mount namespace and it
isn't available at its original path, doesn't mean that its name is unknowable;
we can still try to find it by allowing the normal fall back on iterating
through devices.

An example scenario where this happens is with "/dev/console" in containers.
It's a common practice among container managers to allocate a PTY master/slave
pair in the host's mount namespace (the slave having a path like "/dev/pty/$X"),
bind mount the slave to "/dev/console" in the container's mount namespace, and
send the slave FD to a process in the container. Inside of the
container, the slave-end isn't available at its original path ("/dev/pts/$X"),
since the container mount namespace has a separate devpts instance from the host
(that path may or may not exist in the container; if it does exist, it's not the
 same PTY slave device). Currently ttyname{_r} sees that the file at the
original "/dev/pts/$X" path doesn't match the FD passed to it, and fails early
and gives up, even though if it kept searching it would find the TTY at
"/dev/console". Fix that; don't have the ENODEV path force an early return
inhibiting the fall-back search.

This change is based on the previous patch that adds use of is_mytty in
getttyname and getttyname_r. Without that change, this effectively reverts
15e9a4f, which made us disregard the false similarity of file pointed to by
"/proc/self/fd/$Y", because if it doesn't bail prematurely then that file
("/dev/pts/$X") will just come up again anyway in the fall-back search.

Reviewed-by: Christian Brauner <christian.brauner@ubuntu.com>
(cherry picked from commit a09dfc19edcbac3f96d5410529b724db0a583879)

7 years agolinux ttyname{_r}: Make tty checks consistent
Luke Shumaker [Fri, 22 Dec 2017 14:27:57 +0000 (15:27 +0100)] 
linux ttyname{_r}: Make tty checks consistent

In the ttyname and ttyname_r routines on Linux, at several points it needs to
check if a given TTY is the TTY we are looking for. It used to be that this
check was (to see if `maybe` is `mytty`):

       __xstat64(_STAT_VER, maybe_filename, &maybe) == 0
    #ifdef _STATBUF_ST_RDEV
       && S_ISCHR(maybe.st_mode) && maybe.st_rdev == mytty.st_rdev
    #else
       && maybe.st_ino == mytty.st_ino && maybe.st_dev == mytty.st_dev
    #endif

This check appears in several places.

Then, one of the changes made in commit 15e9a4f378c8607c2ae1aa465436af4321db0e23
was to change that check to:

       __xstat64(_STAT_VER, maybe_filename, &maybe) == 0
    #ifdef _STATBUF_ST_RDEV
       && S_ISCHR(maybe.st_mode) && maybe.st_rdev == mytty.st_rdev
    #endif
       && maybe.st_ino == mytty.st_ino && maybe.st_dev == mytty.st_dev

That is, it made the st_ino and st_dev parts of the check happen even if we have
the st_rdev member. This is an important change, because the kernel allows
multiple devpts filesystem instances to be created; a device file in one devpts
instance may share the same st_rdev with a file in another devpts instance, but
they aren't the same file.

This check appears twice in each file (ttyname.c and ttyname_r.c), once (in
ttyname and __ttyname_r) to check if a candidate file found by inspecting /proc
is the desired TTY, and once (in getttyname and getttyname_r) to check if a
candidate file found by searching /dev is the desired TTY. However, 15e9a4f
only updated the checks for files found via /proc; but the concern about
collisions between devpts instances is just as valid for files found via /dev.

So, update all 4 occurrences the check to be consistent with the version of the
check introduced in 15e9a4f. Make it easy to keep all 4 occurrences of the
check consistent by pulling it in to a static inline function, is_mytty.

Reviewed-by: Christian Brauner <christian.brauner@ubuntu.com>
(cherry picked from commit 2fbce9c2031e70b6bd67876accfc34b0ec492878)

7 years agolinux ttyname: Change return type of is_pty from int to bool
Luke Shumaker [Wed, 15 Nov 2017 19:33:11 +0000 (20:33 +0100)] 
linux ttyname: Change return type of is_pty from int to bool

is_pty returning a bool is fine since there's no possible outcome other than
true or false, and bool is used throughout the codebase.

Reviewed-by: Christian Brauner <christian.brauner@ubuntu.com>
(cherry picked from commit d10d6cab168ffa26ef6a506655ee5dc8537c8ed7)

7 years agolinux ttyname: Update a reference to kernel docs for kernel 4.10
Luke Shumaker [Wed, 15 Nov 2017 19:31:32 +0000 (20:31 +0100)] 
linux ttyname: Update a reference to kernel docs for kernel 4.10

Linux 4.10 moved many of the documentation files around.

4.10 came out between the time the patch adding the comment (commit
15e9a4f378c8607c2ae1aa465436af4321db0e23) was submitted and the time
it was applied (in February, January, and March 2017; respectively).

Reviewed-by: Christian Brauner <christian.brauner@ubuntu.com>
(cherry picked from commit 9b5a87502d048905c383b65c51768f4a1db8c685)

7 years agomanual: Update to mention ENODEV for ttyname and ttyname_r
Luke Shumaker [Wed, 15 Nov 2017 19:28:40 +0000 (20:28 +0100)] 
manual: Update to mention ENODEV for ttyname and ttyname_r

Commit 15e9a4f378c8607c2ae1aa465436af4321db0e23 introduced ENODEV as a possible
error condition for ttyname and ttyname_r. Update the manual to mention this GNU
extension.

Reviewed-by: Christian Brauner <christian.brauner@ubuntu.com>
(cherry picked from commit 495a56fdeb05d20a88304ff5da577d23a8e81ae1)

7 years agoSynchronize support/ infrastructure with master
Florian Weimer [Fri, 22 Dec 2017 14:22:17 +0000 (15:22 +0100)] 
Synchronize support/ infrastructure with master

This commit updates the support/ subdirectory to
commit bad7a0c81f501fbbcc79af9eaa4b8254441c4a1f
on the master branch.

7 years agoelf: Count components of the expanded path in _dl_init_path [BZ #22607]
Florian Weimer [Thu, 14 Dec 2017 14:05:57 +0000 (15:05 +0100)] 
elf: Count components of the expanded path in _dl_init_path [BZ #22607]

(cherry picked from commit 3ff3dfa5af313a6ea33f3393916f30eece4f0171)

7 years agoelf: Compute correct array size in _dl_init_paths [BZ #22606]
Florian Weimer [Thu, 14 Dec 2017 14:18:38 +0000 (15:18 +0100)] 
elf: Compute correct array size in _dl_init_paths [BZ #22606]

(cherry picked from commit 8a0b17e48b83e933960dfeb8fa08b259f03f310e)

7 years ago<array_length.h>: New array_length and array_end macros
Florian Weimer [Thu, 2 Nov 2017 11:14:01 +0000 (12:14 +0100)] 
<array_length.h>: New array_length and array_end macros

(cherry picked from commit c94a5688fb1228a862b2d4a3f1239cdc0e3349e5)

7 years agoi386: Regenerate libm-test-ulps for for gcc 7
H.J. Lu [Fri, 27 Oct 2017 21:09:01 +0000 (14:09 -0700)] 
i386: Regenerate libm-test-ulps for for gcc 7

Regenerate libm-test-ulps for gcc 7 with "-m32 -O2 -march=i586".

* sysdeps/i386/fpu/libm-test-ulps: Regenerated for GCC 7 with
"-O2 -march=i586".

(cherry picked from commit 63d3b468c1b63d04c067eab8d86f0be6bd15bc87)

7 years agoUpdate IA64 libm-test-ulps
Adhemerval Zanella [Wed, 13 Dec 2017 10:42:27 +0000 (11:42 +0100)] 
Update IA64 libm-test-ulps

Ran on Itanium Processor 9020, GCC 7.2.1.

* sysdeps/ia64/fpu/libm-test-ulps: Update.

Signed-off-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
7 years agoia64: Fix thread stack allocation permission set (BZ #21672)
Adhemerval Zanella [Mon, 28 Aug 2017 14:24:35 +0000 (11:24 -0300)] 
ia64: Fix thread stack allocation permission set (BZ #21672)

This patch fixes ia64 failures on thread exit by madvise the required
area taking in consideration its disjoing stacks
(NEED_SEPARATE_REGISTER_STACK).  Also the snippet that setup the
madvise call to advertise kernel the area won't be used anymore in
near future is reallocated in allocatestack.c (for consistency to
put all stack management function in one place).

Checked on x86_64-linux-gnu and i686-linux-gnu for sanity (since
it is not expected code changes for architecture that do not
define NEED_SEPARATE_REGISTER_STACK) and also got a report that
it fixes ia64-linux-gnu failures from Sergei Trofimovich
<slyfox@gentoo.org>.

[BZ #21672]
* nptl/allocatestack.c [_STACK_GROWS_DOWN] (setup_stack_prot):
Set to use !NEED_SEPARATE_REGISTER_STACK as well.
(advise_stack_range): New function.
* nptl/pthread_create.c (START_THREAD_DEFN): Move logic to mark
stack non required to advise_stack_range at allocatestack.c

(cherry pick from commit 01b87c656f670863ce437421b8e9278200965d38)

7 years agoposix: Fix mmap for m68k and ia64 (BZ#21908)
Adhemerval Zanella [Tue, 12 Dec 2017 20:16:53 +0000 (21:16 +0100)] 
posix: Fix mmap for m68k and ia64 (BZ#21908)

Default semantic for mmap2 syscall is to take the offset in 4096-byte
units.  However m68k and ia64 mmap2 implementation take in the
configured pageunit units and for both architecture it can be
different values.

This patch fixes the m68k runtime discover of mmap2 offset unit
and adds the ia64 definition to find it at runtime.

Checked the basic tst-mmap and tst-mmap-offset on m68k (the system
is configured with 4k, so current code is already passing on this
system) and a sanity check on x86_64-linux-gnu (which should not be
affected by this change).  Sergei also states that ia64 loader now
work correctly with this change.

Adhemerval Zanella  <adhemerval.zanella@linaro.org>
Sergei Trofimovich  <slyfox@inbox.ru>

* sysdeps/unix/sysv/linux/m68k/mmap_internal.h (MMAP2_PAGE_SHIFT):
Rename to MMAP2_PAGE_UNIT.
* sysdeps/unix/sysv/linux/mmap.c: Include mmap_internal iff
__OFF_T_MATCHES_OFF64_T is not defined.
* sysdeps/unix/sysv/linux/mmap_internal.h (page_unit): Declare as
uint64_t.
(MMAP2_PAGE_UNIT) [MMAP2_PAGE_UNIT == -1]: Redefine to page_unit.
(page_unit) [MMAP2_PAGE_UNIT != -1]: Remove definition.

(cherry picked from commit 1f14d0c3ddce47f7021bbc0862fdb207891345dc)

7 years agoia64: Add ipc_priv.h header to set __IPC_64 to zero
James Clarke [Tue, 12 Dec 2017 14:17:10 +0000 (12:17 -0200)] 
ia64: Add ipc_priv.h header to set __IPC_64 to zero

When running strace, IPC_64 was set in the command, but ia64 is
an architecture where CONFIG_ARCH_WANT_IPC_PARSE_VERSION *isn't* set
in the kernel, so ipc_parse_version just returns IPC_64 without
clearing the IPC_64 bit in the command.

* sysdeps/unix/sysv/linux/ia64/ipc_priv.h: New file defining
__IPC_64 to 0 to avoid IPC_64 being set.

Signed-off-by: James Clarke <jrtc27@jrtc27.com>
(cherry picked from commit 89bd8016b30e504829bea48c4cd556769abfcf3a)

7 years agoSilence -O3 -Wall warning in malloc/hooks.c with GCC 7 [BZ #22052]
H.J. Lu [Wed, 6 Dec 2017 15:15:47 +0000 (16:15 +0100)] 
Silence -O3 -Wall warning in malloc/hooks.c with GCC 7 [BZ #22052]

realloc_check has

  unsigned char *magic_p;
...
  __libc_lock_lock (main_arena.mutex);
  const mchunkptr oldp = mem2chunk_check (oldmem, &magic_p);
  __libc_lock_unlock (main_arena.mutex);
  if (!oldp)
    malloc_printerr ("realloc(): invalid pointer");
...
  if (newmem == NULL)
    *magic_p ^= 0xFF;

with

static void malloc_printerr(const char *str) __attribute__ ((noreturn));

GCC 7 -O3 warns

hooks.c: In function ‘realloc_check’:
hooks.c:352:14: error: ‘magic_p’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
     *magic_p ^= 0xFF;

due to the GCC bug:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82090

This patch silences GCC 7 by using DIAG_IGNORE_NEEDS_COMMENT.

[BZ #22052]
* malloc/hooks.c (realloc_check): Use DIAG_IGNORE_NEEDS_COMMENT
to silence -O3 -Wall warning with GCC 7.

(cherry picked from commit 8e57c9432a2b68c8a1e7f4df28f0e8c7acc04753)

7 years agoFix integer overflow in malloc when tcache is enabled [BZ #22375]
Arjun Shankar [Thu, 30 Nov 2017 12:31:45 +0000 (13:31 +0100)] 
Fix integer overflow in malloc when tcache is enabled [BZ #22375]

When the per-thread cache is enabled, __libc_malloc uses request2size (which
does not perform an overflow check) to calculate the chunk size from the
requested allocation size. This leads to an integer overflow causing malloc
to incorrectly return the last successfully allocated block when called with
a very large size argument (close to SIZE_MAX).

This commit uses checked_request2size instead, removing the overflow.

(cherry picked from commit 34697694e8a93b325b18f25f7dcded55d6baeaf6)

7 years agoUpdate NEWS to add CVE-2017-15804 entry
Aurelien Jarno [Fri, 1 Dec 2017 20:53:51 +0000 (21:53 +0100)] 
Update NEWS to add CVE-2017-15804 entry

(cherry picked from commit 15e84c63c05e0652047ba5e738c54d79d62ba74b)

7 years agoposix/tst-glob-tilde.c: Add test for bug 22332
Florian Weimer [Thu, 2 Nov 2017 10:06:45 +0000 (11:06 +0100)] 
posix/tst-glob-tilde.c: Add test for bug 22332

(cherry picked from commit 2fac6a6cd50c22ac28c97d0864306594807ade3e)

7 years agoglob: Fix buffer overflow during GLOB_TILDE unescaping [BZ #22332]
Paul Eggert [Sun, 22 Oct 2017 08:00:57 +0000 (10:00 +0200)] 
glob: Fix buffer overflow during GLOB_TILDE unescaping [BZ #22332]

(cherry picked from commit a159b53fa059947cc2548e3b0d5bdcf7b9630ba8)

7 years agoUpdate NEWS and ChangeLog for CVE-2017-15671
Florian Weimer [Sun, 22 Oct 2017 07:29:52 +0000 (09:29 +0200)] 
Update NEWS and ChangeLog for CVE-2017-15671

(cherry picked from commit 914c9994d27b80bc3b71c483e801a4f04e269ba6)

7 years agoAdd single-threaded path to _int_malloc
Wilco Dijkstra [Tue, 28 Nov 2017 13:46:19 +0000 (19:16 +0530)] 
Add single-threaded path to _int_malloc

This patch adds single-threaded fast paths to _int_malloc.

* malloc/malloc.c (_int_malloc): Add SINGLE_THREAD_P path.

(cherry-picked 905a7725e9157ea522d8ab97b4c8b96aeb23df54)

7 years agoAdd single-threaded path to malloc/realloc/calloc/memalloc
Wilco Dijkstra [Tue, 24 Oct 2017 11:39:24 +0000 (12:39 +0100)] 
Add single-threaded path to malloc/realloc/calloc/memalloc

This patch adds a single-threaded fast path to malloc, realloc,
calloc and memalloc.  When we're single-threaded, we can bypass
arena_get (which always locks the arena it returns) and just use
the main arena.  Also avoid retrying a different arena since
there is just the main arena.

* malloc/malloc.c (__libc_malloc): Add SINGLE_THREAD_P path.
(__libc_realloc): Likewise.
(_mid_memalign): Likewise.
(__libc_calloc): Likewise.

(cherry-picked 3f6bb8a32e5f5efd78ac08c41e623651cc242a89)

7 years agoFix build issue with SINGLE_THREAD_P
Wilco Dijkstra [Tue, 28 Nov 2017 13:45:13 +0000 (19:15 +0530)] 
Fix build issue with SINGLE_THREAD_P

Add sysdep-cancel.h include.

* malloc/malloc.c (sysdep-cancel.h): Add include.

(cherry-picked 6d43de4b85b11d26a19bebe4f55f31be16e3d419)

7 years agoAdd single-threaded path to _int_free
Wilco Dijkstra [Fri, 20 Oct 2017 16:27:53 +0000 (17:27 +0100)] 
Add single-threaded path to _int_free

This patch adds single-threaded fast paths to _int_free.
Bypass the explicit locking for larger allocations.

* malloc/malloc.c (_int_free): Add SINGLE_THREAD_P fast paths.

(cherry-picked from a15d53e2de4c7d83bda251469d92a3c7b49a90db)

7 years agoFix deadlock in _int_free consistency check
Wilco Dijkstra [Thu, 19 Oct 2017 17:19:55 +0000 (18:19 +0100)] 
Fix deadlock in _int_free consistency check

This patch fixes a deadlock in the fastbin consistency check.
If we fail the fast check due to concurrent modifications to
the next chunk or system_mem, we should not lock if we already
have the arena lock.  Simplify the check to make it obviously
correct.

* malloc/malloc.c (_int_free): Fix deadlock bug in consistency check.

(cherry-pick d74e6f6c0de55fc588b1ac09c88eb0fb8b8600af)

7 years agomalloc: Resolve compilation failure in NDEBUG mode
Florian Weimer [Thu, 31 Aug 2017 12:55:11 +0000 (14:55 +0200)] 
malloc: Resolve compilation failure in NDEBUG mode

In _int_free, the locked variable is not used if NDEBUG is defined.

(cherry-picked from 24cffce7366c4070d8f823702a4fcec2cb732595)

7 years agomalloc: Change top_check return type to void
Florian Weimer [Thu, 31 Aug 2017 10:02:59 +0000 (12:02 +0200)] 
malloc: Change top_check return type to void

After commit ec2c1fcefb200c6cb7e09553f3c6af8815013d83,
(malloc: Abort on heap corruption, without a backtrace), the function
always returns 0.

(cherry-picked from 5129873a8e913e207e5f7b4b521c72f41a1bbf6d)

7 years agomalloc: Remove corrupt arena flag
Florian Weimer [Tue, 28 Nov 2017 13:40:16 +0000 (19:10 +0530)] 
malloc: Remove corrupt arena flag

This is no longer needed because we now abort immediately
once heap corruption is detected.

(cherry-picked from a9da0bb2667ab20f1dbcd0a9ae6846db02fbc96a)

7 years agomalloc: Remove check_action variable [BZ #21754]
Florian Weimer [Wed, 30 Aug 2017 17:29:38 +0000 (19:29 +0200)] 
malloc: Remove check_action variable [BZ #21754]

Clean up calls to malloc_printerr and trim its argument list.

This also removes a few bits of work done before calling
malloc_printerr (such as unlocking operations).

The tunable/environment variable still enables the lightweight
additional malloc checking, but mallopt (M_CHECK_ACTION)
no longer has any effect.

(cherry-picked from ac3ed168d0c0b2b702319ac0db72c9b475a8c72e)

7 years agomalloc: Abort on heap corruption, without a backtrace [BZ #21754]
Florian Weimer [Wed, 30 Aug 2017 14:39:41 +0000 (16:39 +0200)] 
malloc: Abort on heap corruption, without a backtrace [BZ #21754]

The stack trace printing caused deadlocks and has been itself been
targeted by code execution exploits.

(cherry-picked from ec2c1fcefb200c6cb7e09553f3c6af8815013d83)

7 years agopowerpc: Update AT_HWCAP2 bits
Tulio Magno Quites Machado Filho [Fri, 24 Nov 2017 20:29:21 +0000 (18:29 -0200)] 
powerpc: Update AT_HWCAP2 bits

Linux commit ID cba6ac4869e45cc93ac5497024d1d49576e82666 reserved a new
bit for a scenario where transactional memory is available, but the
suspended state is disabled.

* sysdeps/powerpc/bits/hwcap.h (PPC_FEATURE2_HTM_NO_SUSPEND): New
macro.

(cherry picked from commit df0c40ee3a893238ac11f4c0d876a0c3b49d198d)

Signed-off-by: Tulio Magno Quites Machado Filho <tuliom@linux.vnet.ibm.com>