Compare commits

...
Author SHA1 Message Date
Florian Weimer 0d7f1ed309 libio: Disable vtable validation for pre-2.1 interposed handles [BZ #25203]
Commit c402355dfa ("libio: Disable
vtable validation in case of interposition [BZ #23313]") only covered
the interposable glibc 2.1 handles, in libio/stdfiles.c.  The
parallel code in libio/oldstdfiles.c needs similar detection logic.

Fixes (again) commit db3476aff1
("libio: Implement vtable verification [BZ #20191]").

Change-Id: Ief6f9f17e91d1f7263421c56a7dc018f4f595c21
(cherry picked from commit cb61630ed7)
2019-11-28 16:22:07 +01:00
Florian Weimer 1154cb63e7 libio: Disable vtable validation in case of interposition [BZ #23313]
(cherry picked from commit c402355dfa)
2019-11-28 16:22:07 +01:00
Marcin Kościelnicki a7b9e4cb8e rtld: Check __libc_enable_secure before honoring LD_PREFER_MAP_32BIT_EXEC (CVE-2019-19126) [BZ #25204]
The problem was introduced in glibc 2.23, in commit
b9eb92ab05
("Add Prefer_MAP_32BIT_EXEC to map executable pages with MAP_32BIT").

(cherry picked from commit d5dfad4326)
2019-11-22 14:02:12 +01:00
Dragan Mladjenovic 910576119f mips: Force RWX stack for hard-float builds that can run on pre-4.8 kernels
Linux/Mips kernels prior to 4.8 could potentially crash the user
process when doing FPU emulation while running on non-executable
user stack.

Currently, gcc doesn't emit .note.GNU-stack for mips, but that will
change in the future. To ensure that glibc can be used with such
future gcc, without silently resulting in binaries that might crash
in runtime, this patch forces RWX stack for all built objects if
configured to run against minimum kernel version less than 4.8.

	* sysdeps/unix/sysv/linux/mips/Makefile
	(test-xfail-check-execstack):
	Move under mips-has-gnustack != yes.
	(CFLAGS-.o*, ASFLAGS-.o*): New rules.
	Apply -Wa,-execstack if mips-force-execstack == yes.
	* sysdeps/unix/sysv/linux/mips/configure: Regenerated.
	* sysdeps/unix/sysv/linux/mips/configure.ac
	(mips-force-execstack): New var.
	Set to yes for hard-float builds with minimum_kernel < 4.8.0
	or minimum_kernel not set at all.
	(mips-has-gnustack): New var.
	Use value of libc_cv_as_noexecstack
	if mips-force-execstack != yes, otherwise set to no.

(cherry picked from commit 33bc9efd91)
2019-11-05 08:41:37 -03:00
H.J. Lu 9146dc9d73 x86-64 memcmp: Use unsigned Jcc instructions on size [BZ #24155]
Since the size argument is unsigned. we should use unsigned Jcc
instructions, instead of signed, to check size.

Tested on x86-64 and x32, with and without --disable-multi-arch.

	[BZ #24155]
	CVE-2019-7309
	* NEWS: Updated for CVE-2019-7309.
	* sysdeps/x86_64/memcmp.S: Use RDX_LP for size.  Clear the
	upper 32 bits of RDX register for x32.  Use unsigned Jcc
	instructions, instead of signed.
	* sysdeps/x86_64/x32/Makefile (tests): Add tst-size_t-memcmp-2.
	* sysdeps/x86_64/x32/tst-size_t-memcmp-2.c: New test.

(cherry picked from commit 3f635fb433)
2019-02-04 12:27:55 -08:00
H.J. Lu fc4a25e814 x86-64 strnlen/wcsnlen: Properly handle the length parameter [BZ #24097]
On x32, the size_t parameter may be passed in the lower 32 bits of a
64-bit register with the non-zero upper 32 bits.  The string/memory
functions written in assembly can only use the lower 32 bits of a
64-bit register as length or must clear the upper 32 bits before using
the full 64-bit register for length.

This pach fixes strnlen/wcsnlen for x32.  Tested on x86-64 and x32.  On
x86-64, libc.so is the same with and withou the fix.

	[BZ #24097]
	CVE-2019-6488
	* sysdeps/x86_64/strlen.S: Use RSI_LP for length.
	* sysdeps/x86_64/x32/Makefile (tests): Add tst-size_t-strnlen.
	* sysdeps/x86_64/x32/tst-size_t-strnlen.c: New file.

(cherry picked from commit 5165de69c0)
2019-02-02 06:24:09 -08:00
H.J. Lu b17dc7dec9 x86-64 strncpy: Properly handle the length parameter [BZ #24097]
On x32, the size_t parameter may be passed in the lower 32 bits of a
64-bit register with the non-zero upper 32 bits.  The string/memory
functions written in assembly can only use the lower 32 bits of a
64-bit register as length or must clear the upper 32 bits before using
the full 64-bit register for length.

This pach fixes strncpy for x32.  Tested on x86-64 and x32.  On x86-64,
libc.so is the same with and withou the fix.

	[BZ #24097]
	CVE-2019-6488
	* sysdeps/x86_64/multiarch/strcpy-sse2-unaligned.S: Use RDX_LP
	for length.
	* sysdeps/x86_64/multiarch/strcpy-ssse3.S: Likewise.
	* sysdeps/x86_64/x32/Makefile (tests): Add tst-size_t-strncpy.
	* sysdeps/x86_64/x32/tst-size_t-strncpy.c: New file.

(cherry picked from commit c7c54f65b0)
2019-02-02 06:24:06 -08:00
H.J. Lu 2700f1d8b6 x86-64 strncmp family: Properly handle the length parameter [BZ #24097]
On x32, the size_t parameter may be passed in the lower 32 bits of a
64-bit register with the non-zero upper 32 bits.  The string/memory
functions written in assembly can only use the lower 32 bits of a
64-bit register as length or must clear the upper 32 bits before using
the full 64-bit register for length.

This pach fixes the strncmp family for x32.  Tested on x86-64 and x32.
On x86-64, libc.so is the same with and withou the fix.

	[BZ #24097]
	CVE-2019-6488
	* sysdeps/x86_64/multiarch/strcmp-sse42.S: Use RDX_LP for length.
	* sysdeps/x86_64/strcmp.S: Likewise.
	* sysdeps/x86_64/x32/Makefile (tests): Add tst-size_t-strncasecmp,
	tst-size_t-strncmp and tst-size_t-wcsncmp.
	* sysdeps/x86_64/x32/tst-size_t-strncasecmp.c: New file.
	* sysdeps/x86_64/x32/tst-size_t-strncmp.c: Likewise.
	* sysdeps/x86_64/x32/tst-size_t-wcsncmp.c: Likewise.

(cherry picked from commit ee915088a0)
2019-02-02 06:24:02 -08:00
H.J. Lu cfea023b20 x86-64 memset/wmemset: Properly handle the length parameter [BZ #24097]
On x32, the size_t parameter may be passed in the lower 32 bits of a
64-bit register with the non-zero upper 32 bits.  The string/memory
functions written in assembly can only use the lower 32 bits of a
64-bit register as length or must clear the upper 32 bits before using
the full 64-bit register for length.

This pach fixes memset/wmemset for x32.  Tested on x86-64 and x32.  On
x86-64, libc.so is the same with and withou the fix.

	[BZ #24097]
	CVE-2019-6488
	* sysdeps/x86_64/multiarch/memset-avx512-no-vzeroupper.S: Use
	RDX_LP for length.  Clear the upper 32 bits of RDX register.
	* sysdeps/x86_64/multiarch/memset-vec-unaligned-erms.S: Likewise.
	* sysdeps/x86_64/x32/Makefile (tests): Add tst-size_t-memset.
	* sysdeps/x86_64/x32/tst-size_t-memset.c: New file.

(cherry picked from commit 82d0b4a4d7)
2019-02-02 06:23:58 -08:00
H.J. Lu 6f9ce82c1e x86-64 memrchr: Properly handle the length parameter [BZ #24097]
On x32, the size_t parameter may be passed in the lower 32 bits of a
64-bit register with the non-zero upper 32 bits.  The string/memory
functions written in assembly can only use the lower 32 bits of a
64-bit register as length or must clear the upper 32 bits before using
the full 64-bit register for length.

This pach fixes memrchr for x32.  Tested on x86-64 and x32.  On x86-64,
libc.so is the same with and withou the fix.

	[BZ #24097]
	CVE-2019-6488
	* sysdeps/x86_64/memrchr.S: Use RDX_LP for length.
	* sysdeps/x86_64/x32/Makefile (tests): Add tst-size_t-memrchr.
	* sysdeps/x86_64/x32/tst-size_t-memrchr.c: New file.

(cherry picked from commit ecd8b842cf)
2019-02-02 06:23:54 -08:00
H.J. Lu 689ad96885 x86-64 memcpy: Properly handle the length parameter [BZ #24097]
On x32, the size_t parameter may be passed in the lower 32 bits of a
64-bit register with the non-zero upper 32 bits.  The string/memory
functions written in assembly can only use the lower 32 bits of a
64-bit register as length or must clear the upper 32 bits before using
the full 64-bit register for length.

This pach fixes memcpy for x32.  Tested on x86-64 and x32.  On x86-64,
libc.so is the same with and withou the fix.

	[BZ #24097]
	CVE-2019-6488
	* sysdeps/x86_64/multiarch/memcpy-ssse3-back.S: Use RDX_LP for
	length.  Clear the upper 32 bits of RDX register.
	* sysdeps/x86_64/multiarch/memcpy-ssse3.S: Likewise.
	* sysdeps/x86_64/multiarch/memmove-avx512-no-vzeroupper.S:
	Likewise.
	* sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:
	Likewise.
	* sysdeps/x86_64/x32/Makefile (tests): Add tst-size_t-memcpy.
	tst-size_t-wmemchr.
	* sysdeps/x86_64/x32/tst-size_t-memcpy.c: New file.

(cherry picked from commit 231c56760c)
2019-02-02 06:23:50 -08:00
H.J. Lu d057fef28c x86-64 memcmp/wmemcmp: Properly handle the length parameter [BZ #24097]
On x32, the size_t parameter may be passed in the lower 32 bits of a
64-bit register with the non-zero upper 32 bits.  The string/memory
functions written in assembly can only use the lower 32 bits of a
64-bit register as length or must clear the upper 32 bits before using
the full 64-bit register for length.

This pach fixes memcmp/wmemcmp for x32.  Tested on x86-64 and x32.  On
x86-64, libc.so is the same with and withou the fix.

	[BZ #24097]
	CVE-2019-6488
	* sysdeps/x86_64/multiarch/memcmp-sse4.S: Use RDX_LP for length.
	Clear the upper 32 bits of RDX register.
	* sysdeps/x86_64/multiarch/memcmp-ssse3.S: Likewise.
	* sysdeps/x86_64/x32/Makefile (tests): Add tst-size_t-memcmp and
	tst-size_t-wmemcmp.
	* sysdeps/x86_64/x32/tst-size_t-memcmp.c: New file.
	* sysdeps/x86_64/x32/tst-size_t-wmemcmp.c: Likewise.

(cherry picked from commit b304fc201d)
2019-02-02 06:23:09 -08:00
H.J. Lu b085cb9bbf x86-64 memchr/wmemchr: Properly handle the length parameter [BZ #24097]
On x32, the size_t parameter may be passed in the lower 32 bits of a
64-bit register with the non-zero upper 32 bits.  The string/memory
functions written in assembly can only use the lower 32 bits of a
64-bit register as length or must clear the upper 32 bits before using
the full 64-bit register for length.

This pach fixes memchr/wmemchr for x32.  Tested on x86-64 and x32.  On
x86-64, libc.so is the same with and withou the fix.

	[BZ #24097]
	CVE-2019-6488
	* sysdeps/x86_64/memchr.S: Use RDX_LP for length.  Clear the
	upper 32 bits of RDX register.
	* sysdeps/x86_64/x32/Makefile (tests): Add tst-size_t-memchr.
	* sysdeps/x86_64/x32/test-size_t.h: New file.
	* sysdeps/x86_64/x32/tst-size_t-memchr.c: Likewise.

(cherry picked from commit 97700a34f3)
2019-02-02 06:05:28 -08:00
Florian Weimer 22b7478755 malloc: Always call memcpy in _int_realloc [BZ #24027]
This commit removes the custom memcpy implementation from _int_realloc
for small chunk sizes.  The ncopies variable has the wrong type, and
an integer wraparound could cause the existing code to copy too few
elements (leaving the new memory region mostly uninitialized).
Therefore, removing this code fixes bug 24027.

(cherry picked from commit b50dd3bc8c)
2019-01-01 10:32:37 +01:00
Carlos O'Donell fcd316654a Bug 20116: Fix use after free in pthread_create()
The commit documents the ownership rules around 'struct pthread' and
when a thread can read or write to the descriptor. With those ownership
rules in place it becomes obvious that pd->stopped_start should not be
touched in several of the paths during thread startup, particularly so
for detached threads. In the case of detached threads, between the time
the thread is created by the OS kernel and the creating thread checks
pd->stopped_start, the detached thread might have already exited and the
memory for pd unmapped. As a regression test we add a simple test which
exercises this exact case by quickly creating detached threads with
large enough stacks to ensure the thread stack cache is bypassed and the
stacks are unmapped. Before the fix the testcase segfaults, after the
fix it works correctly and completes without issue.

For a detailed discussion see:
https://www.sourceware.org/ml/libc-alpha/2017-01/msg00505.html

(cherry picked from commit f8bf15febc)
2018-12-29 01:35:01 +01:00
Florian Weimer e853f05a57 csu: Update __libgcc_s_init comment
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
(cherry picked from commit 08c6e95234)
2018-12-28 15:13:27 +01:00
Florian Weimer d8d97c0539 nptl/tst-minstack-throw: Compile in C++11 mode with GNU extensions
(cherry picked from commit b725132d2b)
2018-12-28 15:13:25 +01:00
Florian Weimer 9ae4fa0c5b nptl: Add tst-minstack-cancel, tst-minstack-exit [BZ #22636]
I verified that without the guard accounting change in commit
630f4cc3aa (Fix stack guard size
accounting) and RTLD_NOW for libgcc_s introduced by commit
f993b87540 (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 d8b778907e)
2018-12-28 15:03:30 +01:00
Florian Weimer fff112f4c4 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 f993b87540)
2018-12-28 15:03:05 +01:00
Szabolcs Nagy 23758d3539 [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 630f4cc3aa)
2018-12-28 15:03:05 +01:00
Florian Weimer 659b3df5db Add references to CVE-2017-18269, CVE-2018-11236, CVE-2018-11237
(cherry picked from commit 43d4f3d5ad)
2018-12-20 08:14:01 +01:00
Andreas Schwab b501c7b09e 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 9aaaab7c6e)
2018-12-20 08:14:01 +01:00
Paul Pluzhnikov ff52a12250 Fix 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 5460617d15)
2018-12-20 08:14:01 +01:00
Andrew Senkevich 3f949b0347 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 cd66c0e584)
2018-12-20 08:14:01 +01:00
Stefan Liebler 682f24d0f3 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 28669f86f6)
2018-09-10 14:31:19 +02:00
H.J. Lu 17d5d67f4f 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 207a72e298)

	[BZ #22715]
	* sysdeps/x86_64/dl-trampoline.h (_dl_runtime_profile): Properly
	align La_x86_64_retval to VEC_SIZE.
2018-01-19 09:52:15 -08:00
Aurelien Jarno f24c345bf5 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 3e3c904dae)
2017-12-31 13:07:11 +01:00
Dmitry V. Levin 248475457e 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 bb195224ac)
2017-12-31 13:06:18 +01:00
Florian Weimer c5b38f2ece elf: Count components of the expanded path in _dl_init_path [BZ #22607]
(cherry picked from commit 3ff3dfa5af)
2017-12-16 19:22:10 +01:00
Florian Weimer 28aa53341a elf: Compute correct array size in _dl_init_paths [BZ #22606]
(cherry picked from commit 8a0b17e48b)
2017-12-16 19:21:59 +01:00
Florian Weimer a4fc3a0ceb <array_length.h>: New array_length and array_end macros
(cherry picked from commit c94a5688fb)
2017-12-16 19:21:20 +01:00
Aurelien Jarno d81254d2ef Update NEWS to add CVE-2017-15804 entry
(cherry picked from commit 15e84c63c0)
2017-12-02 22:59:06 +01:00
Florian Weimer bddc572881 posix/tst-glob-tilde.c: Add test for bug 22332
(cherry picked from commit 2fac6a6cd5)
2017-12-02 22:58:29 +01:00
Paul Eggert 94825c8924 glob: Fix buffer overflow during GLOB_TILDE unescaping [BZ #22332]
(cherry picked from commit a159b53fa0)
2017-12-02 22:58:11 +01:00
Florian Weimer 1e53b88296 Update NEWS and ChangeLog for CVE-2017-15671
(cherry picked from commit 914c9994d2)
2017-12-02 22:56:28 +01:00
Florian Weimer 5ff2eb52b2 glob: Add new test tst-glob-tilde
The new test checks for memory leaks (see bug 22325) and attempts
to trigger the buffer overflow in bug 22320.

(cherry picked from commit e80fc1fc98)
2017-12-02 22:51:47 +01:00
Paul Eggert 1f523e3c6e CVE-2017-15670: glob: Fix one-byte overflow [BZ #22320]
(cherry picked from commit c369d66e54)
2017-12-02 22:50:14 +01:00
Adhemerval Zanella 832e2ec567 posix: Sync glob with gnulib [BZ #1062]
This patch syncs posix/glob.c implementation with gnulib version
b5ec983 (glob: simplify symlink detection).  The only difference
to gnulib code is

  * DT_UNKNOWN, DT_DIR, and DT_LNK definition in the case there
    were not already defined.  Gnulib code which uses
    HAVE_STRUCT_DIRENT_D_TYPE will redefine them wrongly because
    GLIBC does not define HAVE_STRUCT_DIRENT_D_TYPE.  Instead
    the patch check for each definition instead.

Also, the patch requires additional globfree and globfree64 files
for compatibility version on some architectures.  Also the code
simplification leads to not macro simplification (not need for
NO_GLOB_PATTERN_P anymore).

Checked on x86_64-linux-gnu and on a build using build-many-glibcs.py
for all major architectures.

	[BZ #1062]
	* posix/Makefile (routines): Add globfree, globfree64, and
	glob_pattern_p.
	* posix/flexmember.h: New file.
	* posix/glob_internal.h: Likewise.
	* posix/glob_pattern_p.c: Likewise.
	* posix/globfree.c: Likewise.
	* posix/globfree64.c: Likewise.
	* sysdeps/gnu/globfree64.c: Likewise.
	* sysdeps/unix/sysv/linux/alpha/globfree.c: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/n64/globfree64.c: Likewise.
	* sysdeps/unix/sysv/linux/oldglob.c: Likewise.
	* sysdeps/unix/sysv/linux/wordsize-64/globfree64.c: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/x32/globfree.c: Likewise.
	* sysdeps/wordsize-64/globfree.c: Likewise.
	* sysdeps/wordsize-64/globfree64.c: Likewise.
	* posix/glob.c (HAVE_CONFIG_H): Use !_LIBC instead.
	[NDEBUG): Remove comments.
	(GLOB_ONLY_P, _AMIGA, VMS): Remove define.
	(dirent_type): New type.  Use uint_fast8_t not
	uint8_t, as C99 does not require uint8_t.
	(DT_UNKNOWN, DT_DIR, DT_LNK): New macros.
	(struct readdir_result): Use dirent_type.  Do not define skip_entry
	unless it is needed; this saves a byte on platforms lacking d_ino.
	(readdir_result_type, readdir_result_skip_entry):
	New functions, replacing ...
	(readdir_result_might_be_symlink, readdir_result_might_be_dir):
	 these functions, which were removed.  This makes the callers
	easier to read.  All callers changed.
	(D_INO_TO_RESULT): Now empty if there is no d_ino.
	(size_add_wrapv, glob_use_alloca): New static functions.
	(glob, glob_in_dir): Check for size_t overflow in several places,
	and fix some size_t checks that were not quite right.
	Remove old code using SHELL since Bash no longer
	uses this.
	(glob, prefix_array): Separate MS code better.
	(glob_in_dir): Remove old Amiga and VMS code.
	(globfree, __glob_pattern_type, __glob_pattern_p): Move to
	separate files.
	(glob_in_dir): Do not rely on undefined behavior in accessing
	struct members beyond their bounds.  Use a flexible array member
	instead
	(link_stat): Rename from link_exists2_p and return -1/0 instead of
	0/1.  Caller changed.
	(glob): Fix memory leaks.
	* posix/glob64 (globfree64): Move to separate file.
	* sysdeps/gnu/glob64.c (NO_GLOB_PATTERN_P): Remove define.
	(globfree64): Remove hidden alias.
	* sysdeps/unix/sysv/linux/Makefile (sysdeps_routines): Add
	oldglob.
	* sysdeps/unix/sysv/linux/alpha/glob.c (__new_globfree): Move to
	separate file.
	* sysdeps/unix/sysv/linux/i386/glob64.c (NO_GLOB_PATTERN_P): Remove
	define.
	Move compat code to separate file.
	* sysdeps/wordsize-64/glob.c (globfree): Move definitions to
	separate file.

(cherry picked from commit c66c908230)
2017-12-02 22:42:47 +01:00
H.J. Lu 89bf8ef2db i386: Hide __old_glob64 [BZ #18822]
Hide internal __old_glob64 function to allow direct access within
libc.so and libc.a without using GOT nor PLT.

	[BZ #18822]
	* sysdeps/unix/sysv/linux/i386/glob64.c (__old_glob64): Add
	libc_hidden_proto and libc_hidden_def.

(cherry picked from commit 2585d7b839)
(cherry picked from commit 2b54f16a8a)
2017-12-02 22:42:31 +01:00
H.J. Lu bea3f92405 x86-64: Use fxsave/xsave/xsavec in _dl_runtime_resolve [BZ #21265]
In _dl_runtime_resolve, use fxsave/xsave/xsavec to preserve all vector,
mask and bound registers.  It simplifies _dl_runtime_resolve and supports
different calling conventions.  ld.so code size is reduced by more than
1 KB.  However, use fxsave/xsave/xsavec takes a little bit more cycles
than saving and restoring vector and bound registers individually.

Latency for _dl_runtime_resolve to lookup the function, foo, from one
shared library plus libc.so:

                             Before    After     Change

Westmere (SSE)/fxsave         345      866       151%
IvyBridge (AVX)/xsave         420      643       53%
Haswell (AVX)/xsave           713      1252      75%
Skylake (AVX+MPX)/xsavec      559      719       28%
Skylake (AVX512+MPX)/xsavec   145      272       87%
Ryzen (AVX)/xsavec            280      553       97%

This is the worst case where portion of time spent for saving and
restoring registers is bigger than majority of cases.  With smaller
_dl_runtime_resolve code size, overall performance impact is negligible.

On IvyBridge, differences in build and test time of binutils with lazy
binding GCC and binutils are noises.  On Westmere, differences in
bootstrap and "makc check" time of GCC 7 with lazy binding GCC and
binutils are also noises.

	[BZ #21265]
	* sysdeps/x86/cpu-features-offsets.sym (XSAVE_STATE_SIZE_OFFSET):
	New.
	* sysdeps/x86/cpu-features.c: Include <libc-internal.h>.
	(get_common_indeces): Set xsave_state_size and
	bit_arch_XSAVEC_Usable if needed.
	(init_cpu_features): Remove bit_arch_Use_dl_runtime_resolve_slow
	and bit_arch_Use_dl_runtime_resolve_opt.
	* sysdeps/x86/cpu-features.h (bit_arch_Use_dl_runtime_resolve_opt):
	Removed.
	(bit_arch_Use_dl_runtime_resolve_slow): Likewise.
	(bit_arch_Prefer_No_AVX512): Updated.
	(bit_arch_MathVec_Prefer_No_AVX512): Likewise.
	(bit_arch_XSAVEC_Usable): New.
	(STATE_SAVE_OFFSET): Likewise.
	(STATE_SAVE_MASK): Likewise.
	[__ASSEMBLER__]: Include <cpu-features-offsets.h>.
	(cpu_features): Add xsave_state_size.
	(index_arch_Use_dl_runtime_resolve_opt): Removed.
	(index_arch_Use_dl_runtime_resolve_slow): Likewise.
	(index_arch_XSAVEC_Usable): New.
	* sysdeps/x86_64/dl-machine.h (elf_machine_runtime_setup):
	Replace _dl_runtime_resolve_sse, _dl_runtime_resolve_avx,
	_dl_runtime_resolve_avx_slow, _dl_runtime_resolve_avx_opt,
	_dl_runtime_resolve_avx512 and _dl_runtime_resolve_avx512_opt
	with _dl_runtime_resolve_fxsave, _dl_runtime_resolve_xsave and
	_dl_runtime_resolve_xsavec.
	* sysdeps/x86_64/dl-trampoline.S (DL_RUNTIME_UNALIGNED_VEC_SIZE):
	Removed.
	(DL_RUNTIME_RESOLVE_REALIGN_STACK): Check STATE_SAVE_ALIGNMENT
	instead of VEC_SIZE.
	(REGISTER_SAVE_BND0): Removed.
	(REGISTER_SAVE_BND1): Likewise.
	(REGISTER_SAVE_BND3): Likewise.
	(REGISTER_SAVE_RAX): Always defined to 0.
	(VMOV): Removed.
	(_dl_runtime_resolve_avx): Likewise.
	(_dl_runtime_resolve_avx_slow): Likewise.
	(_dl_runtime_resolve_avx_opt): Likewise.
	(_dl_runtime_resolve_avx512): Likewise.
	(_dl_runtime_resolve_avx512_opt): Likewise.
	(_dl_runtime_resolve_sse): Likewise.
	(_dl_runtime_resolve_sse_vex): Likewise.
	(USE_FXSAVE): New.
	(_dl_runtime_resolve_fxsave): Likewise.
	(USE_XSAVE): Likewise.
	(_dl_runtime_resolve_xsave): Likewise.
	(USE_XSAVEC): Likewise.
	(_dl_runtime_resolve_xsavec): Likewise.
	* sysdeps/x86_64/dl-trampoline.h (_dl_runtime_resolve_avx512):
	Removed.
	(_dl_runtime_resolve_avx512_opt): Likewise.
	(_dl_runtime_resolve_avx): Likewise.
	(_dl_runtime_resolve_avx_opt): Likewise.
	(_dl_runtime_resolve_sse): Likewise.
	(_dl_runtime_resolve_sse_vex): Likewise.
	(_dl_runtime_resolve_fxsave): New.
	(_dl_runtime_resolve_xsave): Likewise.
	(_dl_runtime_resolve_xsavec): Likewise.

(cherry picked from commit b52b0d793d)
2017-10-22 08:24:29 -07:00
H.J. Lu 5084717ffa x86-64: Verify that _dl_runtime_resolve preserves vector registers
On x86-64, _dl_runtime_resolve must preserve the first 8 vector
registers.  Add 3 _dl_runtime_resolve tests to verify that SSE,
AVX and AVX512 registers are preserved.

	* sysdeps/x86_64/Makefile (tests): Add tst-sse, tst-avx and
	tst-avx512.
	(test-extras): Add tst-avx-aux and tst-avx512-aux.
	(extra-test-objs): Add tst-avx-aux.o and tst-avx512-aux.o.
	(modules-names): Add tst-ssemod, tst-avxmod and tst-avx512mod.
	($(objpfx)tst-sse): New rule.
	($(objpfx)tst-avx): Likewise.
	($(objpfx)tst-avx512): Likewise.
	(CFLAGS-tst-avx-aux.c): New.
	(CFLAGS-tst-avxmod.c): Likewise.
	(CFLAGS-tst-avx512-aux.c): Likewise.
	(CFLAGS-tst-avx512mod.c): Likewise.
	* sysdeps/x86_64/tst-avx-aux.c: New file.
	* sysdeps/x86_64/tst-avx.c: Likewise.
	* sysdeps/x86_64/tst-avx512-aux.c: Likewise.
	* sysdeps/x86_64/tst-avx512.c: Likewise.
	* sysdeps/x86_64/tst-avx512mod.c: Likewise.
	* sysdeps/x86_64/tst-avxmod.c: Likewise.
	* sysdeps/x86_64/tst-sse.c: Likewise.
	* sysdeps/x86_64/tst-ssemod.c: Likewise.

(cherry picked from commit 3403a17fea)
2017-10-19 08:53:02 -07:00
H.J. Lu 37f4c94e1f X86-64: Correct CFA in _dl_runtime_resolve
When stack is re-aligned in _dl_runtime_resolve, there is no need to
adjust CFA when allocating register save area on stack.

	* sysdeps/x86_64/dl-trampoline.h (_dl_runtime_resolve): Don't
	adjust CFA when allocating register save area on re-aligned
	stack.

(cherry picked from commit 0ac8ee53e8)
2017-10-19 08:50:28 -07:00
Joseph Myers 79c6f51428 Fix nss_nisplus build with mainline GCC (bug 20978).
glibc build with current mainline GCC fails because
nis/nss_nisplus/nisplus-alias.c contains code

  if (name != NULL)
    {
      *errnop = EINVAL;
      return NSS_STATUS_UNAVAIL;
    }

  char buf[strlen (name) + 9 + tablename_len];

producing an error about strlen being called on a pointer that is
always NULL (and a subsequent use of that pointer with a %s format in
snprintf).

As Andreas noted, the bogus conditional comes from a 1997 change:

-  if (name == NULL || strlen(name) > 8)
-    return NSS_STATUS_NOTFOUND;
-  else
+  if (name != NULL || strlen(name) <= 8)

So the intention is clearly to return an error for NULL name.

This patch duly inverts the sense of the conditional.  It fixes the
build with GCC mainline, and passes usual glibc testsuite testing for
x86_64.  However, I have not tried any actual substantive nisplus
testing, do not have an environment for such testing, and do not know
whether it is possible that strlen (name) or tablename_len might be
large so that the VLA for buf is actually a security issue.  However,
if it is a security issue, there are plenty of other similar instances
in the nisplus code (that haven't been hidden by a bogus comparison
with NULL) - and nis_table.c:__create_ib_request uses strdupa on the
string passed to nis_list, so a local fix in the caller wouldn't
suffice anyway (see bug 20987).  (Calls to strdupa and other such
macros that use alloca must be considered equally questionable
regarding stack overflow issues as direct calls to alloca and VLA
declarations.)

	[BZ #20978]
	* nis/nss_nisplus/nisplus-alias.c (_nss_nisplus_getaliasbyname_r):
	Compare name == NULL, not name != NULL.

(cherry picked from commit f88759ea9b)
2017-10-07 13:44:49 +02:00
Joseph Myers 7fca94796b Fix rpcgen buffer overrun (bug 20790).
Building with GCC 7 produces an error building rpcgen:

rpc_parse.c: In function 'get_prog_declaration':
rpc_parse.c:543:25: error: may write a terminating nul past the end of the destination [-Werror=format-length=]
     sprintf (name, "%s%d", ARGNAME, num); /* default name of argument */
                     ~~~~^
rpc_parse.c:543:5: note: format output between 5 and 14 bytes into a destination of size 10
     sprintf (name, "%s%d", ARGNAME, num); /* default name of argument */
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

That buffer overrun is for the case where the .x file declares a
program with a million arguments.  The strcpy two lines above can
generate a buffer overrun much more simply for a long argument name.

The limit on length of line read by rpcgen (MAXLINESIZE == 1024)
provides a bound on the buffer size needed, so this patch just changes
the buffer size to MAXLINESIZE to avoid both possible buffer
overruns.  A testcase is added that rpcgen does not crash with a
500-character argument name, where it previously crashed.

It would not at all surprise me if there are many other ways of
crashing rpcgen with either valid or invalid input; fuzz testing would
likely find various such bugs, though I don't think they are that
important to fix (rpcgen is not that likely to be used with untrusted
.x files as input).  (As well as fuzz-findable bugs there are probably
also issues when various int variables get overflowed on very large
input.)  The test infrastructure for rpcgen-not-crashing tests would
need extending if tests are to be added for cases where rpcgen should
produce an error, as opposed to cases where it should succeed.

Tested for x86_64 and x86.

	[BZ #20790]
	* sunrpc/rpc_parse.c (get_prog_declaration): Increase buffer size
	to MAXLINESIZE.
	* sunrpc/bug20790.x: New file.
	* sunrpc/Makefile [$(run-built-tests) = yes] (rpcgen-tests): New
	variable.
	[$(run-built-tests) = yes] (tests-special): Add $(rpcgen-tests).
	[$(run-built-tests) = yes] ($(rpcgen-tests)): New rule.

(cherry picked from commit 5874510faa)
2017-10-07 13:42:41 +02:00
steve ellcey-CA Eng-Software b3c498b834 Fix warnings from latest GCC.
* sysdeps/ieee754/dbl-64/e_pow.c (checkint) Make conditions explicitly
	boolean.

(cherry picked from commit e223d1fe72)
2017-10-07 13:39:15 +02:00
DJ Delorie b70f43dcef Fix cast-after-dereference
Original code was dereferencing a char*, then casting the value
to size_t.  Should cast the pointer to size_t* then deference.

(cherry picked from commit f8cef4d07d)
2017-10-07 13:32:01 +02:00
DJ Delorie caa97d7a46 Fix BZ #21654 - grp-merge.c alignment
* grp/grp_merge.c (__copy_grp): Align char** to minimum pointer
alignment not char alignment.
(__merge_grp): Likewise.

(cherry picked from commit 4fa8ae49aa)
2017-10-07 13:30:00 +02:00
H.J. Lu d5a4092c36 x86-64: Use _dl_runtime_resolve_opt only with AVX512F [BZ #21871]
On AVX machines with XGETBV (ECX == 1) like Skylake processors,

(gdb) disass _dl_runtime_resolve_avx_opt
Dump of assembler code for function _dl_runtime_resolve_avx_opt:
   0x0000000000015890 <+0>:	push   %rax
   0x0000000000015891 <+1>:	push   %rcx
   0x0000000000015892 <+2>:	push   %rdx
   0x0000000000015893 <+3>:	mov    $0x1,%ecx
   0x0000000000015898 <+8>:	xgetbv
   0x000000000001589b <+11>:	mov    %eax,%r11d
   0x000000000001589e <+14>:	pop    %rdx
   0x000000000001589f <+15>:	pop    %rcx
   0x00000000000158a0 <+16>:	pop    %rax
   0x00000000000158a1 <+17>:	and    $0x4,%r11d
   0x00000000000158a5 <+21>:	bnd je 0x16200 <_dl_runtime_resolve_sse_vex>
End of assembler dump.

is slower than:

(gdb) disass _dl_runtime_resolve_avx_slow
Dump of assembler code for function _dl_runtime_resolve_avx_slow:
   0x0000000000015850 <+0>:	vorpd  %ymm0,%ymm1,%ymm8
   0x0000000000015854 <+4>:	vorpd  %ymm2,%ymm3,%ymm9
   0x0000000000015858 <+8>:	vorpd  %ymm4,%ymm5,%ymm10
   0x000000000001585c <+12>:	vorpd  %ymm6,%ymm7,%ymm11
   0x0000000000015860 <+16>:	vorpd  %ymm8,%ymm9,%ymm9
   0x0000000000015865 <+21>:	vorpd  %ymm10,%ymm11,%ymm10
   0x000000000001586a <+26>:	vpcmpeqd %xmm8,%xmm8,%xmm8
   0x000000000001586f <+31>:	vorpd  %ymm9,%ymm10,%ymm10
   0x0000000000015874 <+36>:	vptest %ymm10,%ymm8
   0x0000000000015879 <+41>:	bnd jae 0x158b0 <_dl_runtime_resolve_avx>
   0x000000000001587c <+44>:	vzeroupper
   0x000000000001587f <+47>:	bnd jmpq 0x16200 <_dl_runtime_resolve_sse_vex>
End of assembler dump.
(gdb)

since xgetbv takes much more cycles than single cycle operations like
vpord/vvpcmpeq/ptest.  _dl_runtime_resolve_opt should be used only with
AVX512 where AVX512 instructions lead to lower CPU frequency on Skylake
server.

	[BZ #21871]
	* sysdeps/x86/cpu-features.c (init_cpu_features): Set
	bit_arch_Use_dl_runtime_resolve_opt only with AVX512F.

(cherry picked from commit d2cf37c0a2)
2017-08-06 11:55:44 -07:00
Florian Weimer 36f173ab37 sunrpc: Avoid use-after-free read access in clntudp_call [BZ #21115]
After commit bc779a1a5b
(CVE-2016-4429: sunrpc: Do not use alloca in clntudp_call
[BZ #20112]), ancillary data is stored on the heap,
but it is accessed after it has been freed.

The test case must be run under a heap debugger such as valgrind
to observe the invalid access.  A malloc implementation which
immediately calls munmap on free would catch this bug as well.

(cherry picked from commit d42eed4a04)
2017-08-05 02:19:16 +02:00
James Clarke 6aacb5befa Bug 21053: sh: Reduce namespace pollution from sys/ucontext.h
The problem is basically that sys/ucontext.h is defining R0..R15
which happens to conflict with some packages like Firefox when
trying to build on SH.

The very same problem existed on arm back then [1] and it was fixed by
renaming R0..R15 to REG_R0..REG_R15.  This patch imploy a similar
strategy for SH.

Checked on sh4-linux-gnu with run-built-tests=no and I also got reports
that it fixes Firefox build on Debian sh4.

	* sysdeps/unix/sysv/linux/sh/sh3/ucontext_i.sym: Use new REG_R*
	constants instead of the old R* ones.
	* sysdeps/unix/sysv/linux/sh/sh4/ucontext_i.sym: Likewise.
	* sysdeps/unix/sysv/linux/sh/sys/ucontext.h (NGPREG): Rename...
	(NGREG): ... to this, to fit in with other architectures.
	(gpregset_t): Use new NGREG macro.
	[__USE_GNU]: Remove condition; all architectures other than tile
	are unconditional.
	(R*): Rename to REG_R*.

(cherry picked from commit 3e1b518550)
2017-07-31 22:36:13 +02:00
H.J. Lu fd5fade305 Avoid .symver on common symbols [BZ #21666]
The .symver directive on common symbol just creates a new common symbol,
not an alias and the newer assembler with the bug fix for

https://sourceware.org/bugzilla/show_bug.cgi?id=21661

will issue an error.  Before the fix, we got

$ readelf -sW libc.so | grep "loc[12s]"
  5109: 00000000003a0608     8 OBJECT  LOCAL  DEFAULT   36 loc1
  5188: 00000000003a0610     8 OBJECT  LOCAL  DEFAULT   36 loc2
  5455: 00000000003a0618     8 OBJECT  LOCAL  DEFAULT   36 locs
  6575: 00000000003a05f0     8 OBJECT  GLOBAL DEFAULT   36 locs@GLIBC_2.2.5
  7156: 00000000003a05f8     8 OBJECT  GLOBAL DEFAULT   36 loc1@GLIBC_2.2.5
  7312: 00000000003a0600     8 OBJECT  GLOBAL DEFAULT   36 loc2@GLIBC_2.2.5

in libc.so.  The versioned loc1, loc2 and locs have the wrong addresses.
After the fix, we got

$ readelf -sW libc.so | grep "loc[12s]"
  6570: 000000000039e3b8     8 OBJECT  GLOBAL DEFAULT   34 locs@GLIBC_2.2.5
  7151: 000000000039e3c8     8 OBJECT  GLOBAL DEFAULT   34 loc1@GLIBC_2.2.5
  7307: 000000000039e3c0     8 OBJECT  GLOBAL DEFAULT   34 loc2@GLIBC_2.2.5

	[BZ #21666]
	* misc/regexp.c (loc1): Add __attribute__ ((nocommon));
	(loc2): Likewise.
	(locs): Likewise.

(cherry picked from commit 388b4f1a02)
2017-07-26 10:14:08 -07:00
Szabolcs Nagy cc392d6339 [AArch64] Use hidden __GI__dl_argv in rtld startup code
We rely on the symbol being locally defined so using extern symbol
is not correct and the linker may complain about the relocations.
2017-07-12 17:41:57 +01:00
Aurelien Jarno 605e6f9f4a conform tests: call perl with '-I.'
Historically perl includes the current directory in the module search
path. Over the time this has been considered as a security issue and
the recent vulnerabilities [1] made people to reconsider this behaviour.
It is almost sure that this will be removed in the future [2], possibly
for the 5.26 release, although this is not yet firmly decided.

Debian has decided to backport the patches [3], so the perl binary in
unstable do not have '.' in @INC anymore.

This behaviour is used in the conform perl scripts to include the
GlibcConform module. This patch fixes that by calling perl with '-I.'.
This is not a security issue in this case as make ensures that the
current directory is $(srcdir)/conform/ when the scripts are called.
Passing the full path would do exactly the same.

[1] CVE-2016-1238 CVE-2016-6185
[2] https://rt.perl.org/Public/Bug/Display.html?id=127810
[3] https://lists.debian.org/debian-devel-announce/2016/08/msg00013.html

Changelog:
	* conform/Makefile (conformtest-header-tests): Pass -I. to $(PERL).
	(linknamespace-symlists-tests): Likewise.
	(linknamespace-header-tests): Likewise.

(cherry picked from commit 6d5336211d)
2017-07-06 15:14:47 +02:00
H.J. Lu 8c04a73813 x86-64: Align the stack in __tls_get_addr [BZ #21609]
This change forces realignment of the stack pointer in __tls_get_addr, so
that binaries compiled by GCCs older than GCC 4.9:

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

continue to work even if vector instructions are used in glibc which
require the ABI stack realignment.

__tls_get_addr_slow is added to handle the slow paths in the default
implementation of__tls_get_addr in elf/dl-tls.c.  The new __tls_get_addr
calls __tls_get_addr_slow after realigning the stack.  Internal calls
within ld.so go directly to the default implementation of __tls_get_addr
because they do not need stack realignment.

	[BZ #21609]
	* sysdeps/x86_64/Makefile (sysdep-dl-routines): Add tls_get_addr.
	(gen-as-const-headers): Add rtld-offsets.sym.
	* sysdeps/x86_64/dl-tls.c: New file.
	* sysdeps/x86_64/rtld-offsets.sym: Likwise.
	* sysdeps/x86_64/tls_get_addr.S: Likewise.
	* sysdeps/x86_64/dl-tls.h: Add multiple inclusion guards.
	* sysdeps/x86_64/tlsdesc.sym (TI_MODULE_OFFSET): New.
	(TI_OFFSET_OFFSET): Likwise.

(cherry picked from commit 031e519c95)
2017-07-06 15:05:53 +02:00
Florian Weimer 86ac4a78a9 i686: Add missing IS_IN (libc) guards to vectorized strcspn
Since commit d957c4d3fa (i386: Compile
rtld-*.os with -mno-sse -mno-mmx -mfpmath=387), vector intrinsics can
no longer be used in ld.so, even if the compiled code never makes it
into the final ld.so link.  This commit adds the missing IS_IN (libc)
guard to the SSE 4.2 strcspn implementation, so that it can be used from
ld.so in the future.

(cherry picked from commit 69052a3a95)
2017-06-20 06:27:56 +02:00
Siddhesh Poyarekar 0578ef88fd Ignore and remove LD_HWCAP_MASK for AT_SECURE programs (bug #21209)
The LD_HWCAP_MASK environment variable may alter the selection of
function variants for some architectures.  For AT_SECURE process it
means that if an outdated routine has a bug that would otherwise not
affect newer platforms by default, LD_HWCAP_MASK will allow that bug
to be exploited.

To be on the safe side, ignore and disable LD_HWCAP_MASK for setuid
binaries.

	[BZ #21209]
	* elf/rtld.c (process_envvars): Ignore LD_HWCAP_MASK for
	AT_SECURE processes.
	* sysdeps/generic/unsecvars.h: Add LD_HWCAP_MASK.

(cherry picked from commit 1c1243b6fc)
2017-06-20 06:05:02 +02:00
Florian Weimer 2febff860b ld.so: Reject overly long LD_AUDIT path elements
Also only process the last LD_AUDIT entry.

(cherry picked from commit 81b82fb966)
2017-06-19 22:46:18 +02:00
Florian Weimer aab04ca5d3 ld.so: Reject overly long LD_PRELOAD path elements
(cherry picked from commit 6d0ba62289)
2017-06-19 22:46:18 +02:00
Florian Weimer 87bd4186da CVE-2017-1000366: Ignore LD_LIBRARY_PATH for AT_SECURE=1 programs [BZ #21624]
LD_LIBRARY_PATH can only be used to reorder system search paths, which
is not useful functionality.

This makes an exploitable unbounded alloca in _dl_init_paths unreachable
for AT_SECURE=1 programs.

(cherry picked from commit f6110a8fee)
2017-06-19 18:33:26 +02:00
Andreas Schwab 600b10a871 m68k: fix 64bit atomic ops
(cherry picked from commit 64ae9fe456)
2017-06-17 01:27:09 +02:00
Santhosh Thottingal 4e291e7c52 Correct collation rules for Malayalam.
[BZ #19922]
	* locales/iso14651_t1_common: Add collation rules for U+07DA to U+07DF.

	[BZ #19919]
	* locales/iso14651_t1_common: Correct collation of U+0D36 and U+0D37.
2017-06-11 10:28:08 -04:00
Florian Weimer 0505a57d43 fork: Remove bogus parent PID assertions [BZ #21386]
(cherry picked from commit 1d2bc2eae9)
2017-06-09 12:00:48 +02:00
Arjun Shankar 7b60553e36 Use test-driver in sysdeps/unix/sysv/linux/tst-clone2.c
(cherry picked from commit fdc543919a)
2017-06-07 14:19:53 +02:00
Adhemerval Zanella 206e03248c Remove cached PID/TID in clone
This patch remove the PID cache and usage in current GLIBC code.  Current
usage is mainly used a performance optimization to avoid the syscall,
however it adds some issues:

  - The exposed clone syscall will try to set pid/tid to make the new
    thread somewhat compatible with current GLIBC assumptions.  This cause
    a set of issue with new workloads and usecases (such as BZ#17214 and
    [1]) as well for new internal usage of clone to optimize other algorithms
    (such as clone plus CLONE_VM for posix_spawn, BZ#19957).

  - The caching complexity also added some bugs in the past [2] [3] and
    requires more effort of each port to handle such requirements (for
    both clone and vfork implementation).

  - Caching performance gain in mainly on getpid and some specific
    code paths.  The getpid performance leverage is questionable [4],
    either by the idea of getpid being a hotspot as for the getpid
    implementation itself (if it is indeed a justifiable hotspot a
    vDSO symbol could let to a much more simpler solution).

    Other usage is mainly for non usual code paths, such as pthread
    cancellation signal and handling.

For thread creation (on stack allocation) the code simplification in fact
adds some performance gain due the no need of transverse the stack cache
and invalidate each element pid.

Other thread usages will require a direct getpid syscall, such as
cancellation/setxid signal, thread cancellation, thread fail path (at
create_thread), and thread signal (pthread_kill and pthread_sigqueue).
However these are hardly usual hotspots and I think adding a syscall is
justifiable.

It also simplifies both the clone and vfork arch-specific implementation.
And by review each fork implementation there are some discrepancies that
this patch also solves:

  - microblaze clone/vfork does not set/reset the pid/tid field
  - hppa uses the default vfork implementation that fallback to fork.
    Since vfork is deprecated I do not think we should bother with it.

The patch also removes the TID caching in clone. My understanding for
such semantic is try provide some pthread usage after a user program
issue clone directly (as done by thread creation with CLONE_PARENT_SETTID
and pthread tid member).  However, as stated before in multiple discussions
threads, GLIBC provides clone syscalls without further supporting all this
semantics.

I ran a full make check on x86_64, x32, i686, armhf, aarch64, and powerpc64le.
For sparc32, sparc64, and mips I ran the basic fork and vfork tests from
posix/ folder (on a qemu system).  So it would require further testing
on alpha, hppa, ia64, m68k, nios2, s390, sh, and tile (I excluded microblaze
because it is already implementing the patch semantic regarding clone/vfork).

[1] https://codereview.chromium.org/800183004/
[2] https://sourceware.org/ml/libc-alpha/2006-07/msg00123.html
[3] https://sourceware.org/bugzilla/show_bug.cgi?id=15368
[4] http://yarchive.net/comp/linux/getpid_caching.html

	* sysdeps/nptl/fork.c (__libc_fork): Remove pid cache setting.
	* nptl/allocatestack.c (allocate_stack): Likewise.
	(__reclaim_stacks): Likewise.
	(setxid_signal_thread): Obtain pid through syscall.
	* nptl/nptl-init.c (sigcancel_handler): Likewise.
	(sighandle_setxid): Likewise.
	* nptl/pthread_cancel.c (pthread_cancel): Likewise.
	* sysdeps/unix/sysv/linux/pthread_kill.c (__pthread_kill): Likewise.
	* sysdeps/unix/sysv/linux/pthread_sigqueue.c (pthread_sigqueue):
	Likewise.
	* sysdeps/unix/sysv/linux/createthread.c (create_thread): Likewise.
	* sysdeps/unix/sysv/linux/getpid.c: Remove file.
	* nptl/descr.h (struct pthread): Change comment about pid value.
	* nptl/pthread_getattr_np.c (pthread_getattr_np): Remove thread
	pid assert.
	* sysdeps/unix/sysv/linux/pthread-pids.h (__pthread_initialize_pids):
	Do not set pid value.
	* nptl_db/td_ta_thr_iter.c (iterate_thread_list): Remove thread
	pid cache check.
	* nptl_db/td_thr_validate.c (td_thr_validate): Likewise.
	* sysdeps/aarch64/nptl/tcb-offsets.sym: Remove pid offset.
	* sysdeps/alpha/nptl/tcb-offsets.sym: Likewise.
	* sysdeps/arm/nptl/tcb-offsets.sym: Likewise.
	* sysdeps/hppa/nptl/tcb-offsets.sym: Likewise.
	* sysdeps/i386/nptl/tcb-offsets.sym: Likewise.
	* sysdeps/ia64/nptl/tcb-offsets.sym: Likewise.
	* sysdeps/m68k/nptl/tcb-offsets.sym: Likewise.
	* sysdeps/microblaze/nptl/tcb-offsets.sym: Likewise.
	* sysdeps/mips/nptl/tcb-offsets.sym: Likewise.
	* sysdeps/nios2/nptl/tcb-offsets.sym: Likewise.
	* sysdeps/powerpc/nptl/tcb-offsets.sym: Likewise.
	* sysdeps/s390/nptl/tcb-offsets.sym: Likewise.
	* sysdeps/sh/nptl/tcb-offsets.sym: Likewise.
	* sysdeps/sparc/nptl/tcb-offsets.sym: Likewise.
	* sysdeps/tile/nptl/tcb-offsets.sym: Likewise.
	* sysdeps/x86_64/nptl/tcb-offsets.sym: Likewise.
	* sysdeps/unix/sysv/linux/aarch64/clone.S: Remove pid and tid caching.
	* sysdeps/unix/sysv/linux/alpha/clone.S: Likewise.
	* sysdeps/unix/sysv/linux/arm/clone.S: Likewise.
	* sysdeps/unix/sysv/linux/hppa/clone.S: Likewise.
	* sysdeps/unix/sysv/linux/i386/clone.S: Likewise.
	* sysdeps/unix/sysv/linux/ia64/clone2.S: Likewise.
	* sysdeps/unix/sysv/linux/mips/clone.S: Likewise.
	* sysdeps/unix/sysv/linux/nios2/clone.S: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/clone.S: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/clone.S: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/clone.S: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-64/clone.S: Likewise.
	* sysdeps/unix/sysv/linux/sh/clone.S: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/clone.S: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/clone.S: Likewise.
	* sysdeps/unix/sysv/linux/tile/clone.S: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/clone.S: Likewise.
	* sysdeps/unix/sysv/linux/aarch64/vfork.S: Remove pid set and reset.
	* sysdeps/unix/sysv/linux/alpha/vfork.S: Likewise.
	* sysdeps/unix/sysv/linux/arm/vfork.S: Likewise.
	* sysdeps/unix/sysv/linux/i386/vfork.S: Likewise.
	* sysdeps/unix/sysv/linux/ia64/vfork.S: Likewise.
	* sysdeps/unix/sysv/linux/m68k/clone.S: Likewise.
	* sysdeps/unix/sysv/linux/m68k/vfork.S: Likewise.
	* sysdeps/unix/sysv/linux/mips/vfork.S: Likewise.
	* sysdeps/unix/sysv/linux/nios2/vfork.S: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/vfork.S: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/vfork.S: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/vfork.S: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-64/vfork.S: Likewise.
	* sysdeps/unix/sysv/linux/sh/vfork.S: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/vfork.S: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/vfork.S: Likewise.
	* sysdeps/unix/sysv/linux/tile/vfork.S: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/vfork.S: Likewise.
	* sysdeps/unix/sysv/linux/tst-clone2.c (f): Remove direct pthread
	struct access.
	(clone_test): Remove function.
	(do_test): Rewrite to take in consideration pid is not cached anymore.

(cherry picked from commit c579f48edb)
2017-06-07 12:42:53 +02:00
Adhemerval Zanella 8071849934 Add INTERNAL_SYSCALL_CALL
This patch adds two new macros for internal and inline syscall to use
within GLIBC: INTERNAL_SYSCALL_CALL and INLINE_SYSCALL_CALL.  They are
similar to the old INTERNAL_SYSCALL and INLINE_SYSCALL with the difference
the new macros accept a variable argument call and do not require to pass
the expected argument size.

The advantage is it is possible to use variable argument macros like
SYSCALL_LL{64} without the need to also handle the argument size.  So
for an ABI where SYSCALL_LL might split the argument in high and low
parts, instead of:

  INTERNAL_SYSCALL_DECL (err);
 #if ...
  INTERNAL_SYSCALL (syscall, err, 2, SYSCALL_LL (len));
 #else
  INTERNAL_SYSCALL (syscall, err, 1, SYSCALL_LL (len));
 #endif

It will be just:

  INTERNAL_SYSCALL_CALL (syscall, err, SYSCALL_LL (len));

The INLINE_SYSCALL_CALL follows the same semanthic regarding the argument
and is similar to INLINE_SYSCALL regarding setting errno.

Checked with a build for x86_64, i386, aach64, armhf, powerpc64le, powerpc32,
and mips32.  No code generation changed.

	* sysdeps/unix/sysdep.h (__INTERNAL_SYSCALL0): New macro.
	(__INTERNAL_SYSCALL1): Likewise.
	(__INTERNAL_SYSCALL2): Likewise.
	(__INTERNAL_SYSCALL3): Likewise.
	(__INTERNAL_SYSCALL4): Likewise.
	(__INTERNAL_SYSCALL5): Likewise.
	(__INTERNAL_SYSCALL6): Likewise.
	(__INTERNAL_SYSCALL7): Likewise.
	(__INTERNAL_SYSCALL_NARGS_X): Likewise.
	(__INTERNAL_SYSCALL_NARGS): Likewise.
	(__INTERNAL_SYSCALL_DISP): Likewise.
	(INTERNAL_SYSCALL_CALL): Likewise.
	(__SYSCALL0): Rename to __INLINE_SYSCALL0.
	(__SYSCALL1): Rename to __INLINE_SYSCALL1.
	(__SYSCALL2): Rename to __INLINE_SYSCALL2.
	(__SYSCALL3): Rename to __INLINE_SYSCALL3.
	(__SYSCALL4): Rename to __INLINE_SYSCALL4.
	(__SYSCALL5): Rename to __INLINE_SYSCALL5.
	(__SYSCALL6): Rename to __INLINE_SYSCALL6.
	(__SYSCALL7): Rename to __INLINE_SYSCALL7.
	(__SYSCALL_NARGS_X): Rename to __INLINE_SYSCALL_NARGS_X.
	(__SYSCALL_NARGS): Rename to __INLINE_SYSCALL_NARGS.
	(__SYSCALL_DISP): Rename to __INLINE_SYSCALL_DISP.
	(__SYSCALL_CALL): Rename to INLINE_SYSCALL_CALL.
	(SYSCALL_CANCEL): Replace __SYSCALL_CALL with INLINE_SYSCALL_CALL.

(cherry picked from commit e33a23fbe8)
2017-06-07 12:42:44 +02:00
Arjun Shankar 4c5785aa12 Synchronize support/ infrastructure with master
This commit updates the support/ subdirectory to
commit 2714c5f3c9
on the master branch and modifies Makeconfig,
Rules, and extra-lib.mk accordingly.
2017-06-07 12:36:15 +02:00
H.J. Lu a29331702f x86: Use AVX2 memcpy/memset on Skylake server [BZ #21396]
On Skylake server, AVX512 load/store instructions in memcpy/memset may
lead to lower CPU turbo frequency in certain situations.  Use of AVX2
in memcpy/memset has been observed to have improved overall performance
in many workloads due to the higher frequency.

Since AVX512ER is unique to Xeon Phi, this patch sets Prefer_No_AVX512
if AVX512ER isn't available so that AVX2 versions of memcpy/memset are
used on Skylake server.

	[BZ #21396]
	* sysdeps/x86/cpu-features.c (init_cpu_features): Set
	Prefer_No_AVX512 if AVX512ER isn't available.
	* sysdeps/x86/cpu-features.h (bit_arch_Prefer_No_AVX512): New.
	(index_arch_Prefer_No_AVX512): Likewise.
	* sysdeps/x86_64/multiarch/memcpy.S (__new_memcpy): Don't use
	AVX512 version if Prefer_No_AVX512 is set.
	* sysdeps/x86_64/multiarch/memcpy_chk.S (__memcpy_chk):
	Likewise.
	* sysdeps/x86_64/multiarch/memmove.S (__libc_memmove): Likewise.
	* sysdeps/x86_64/multiarch/memmove_chk.S (__memmove_chk):
	Likewise.
	* sysdeps/x86_64/multiarch/mempcpy.S (__mempcpy): Likewise.
	* sysdeps/x86_64/multiarch/mempcpy_chk.S (__mempcpy_chk):
	Likewise.
	* sysdeps/x86_64/multiarch/memset.S (memset): Likewise.
	* sysdeps/x86_64/multiarch/memset_chk.S (__memset_chk):
	Likewise.

(cherry picked from commit 4cb334c4d6)
2017-04-28 10:27:54 -07:00
H.J. Lu 5f85ab2869 x86: Set Prefer_No_VZEROUPPER if AVX512ER is available
AVX512ER won't be implemented in any Xeon processors and will be in
all Xeon Phi processors.  Don't check CPU model number when setting
Prefer_No_VZEROUPPER for Xeon Phi.  Instead, set Prefer_No_VZEROUPPER
if AVX512ER is available.  It works with current and future Xeon Phi
and non-Xeon Phi processors.

	* sysdeps/x86/cpu-features.c (init_cpu_features): Set
	Prefer_No_VZEROUPPER if AVX512ER is available.
	* sysdeps/x86/cpu-features.h
	(bit_cpu_AVX512PF): New.
	(bit_cpu_AVX512ER): Likewise.
	(bit_cpu_AVX512CD): Likewise.
	(bit_cpu_AVX512BW): Likewise.
	(bit_cpu_AVX512VL): Likewise.
	(index_cpu_AVX512PF): Likewise.
	(index_cpu_AVX512ER): Likewise.
	(index_cpu_AVX512CD): Likewise.
	(index_cpu_AVX512BW): Likewise.
	(index_cpu_AVX512VL): Likewise.
	(reg_AVX512PF): Likewise.
	(reg_AVX512ER): Likewise.
	(reg_AVX512CD): Likewise.
	(reg_AVX512BW): Likewise.
	(reg_AVX512VL): Likewise.

(cherry picked from commit 1c53cb49de)
2017-04-28 10:27:42 -07:00
Joseph Myers b2e8c40afc Fix MIPS n64 readahead (bug 21026).
As noted in bug 20126, MIPS n64 uses an incorrect implementation of
readahead intended for 32-bit systems.  This patch adds a
syscalls.list entry to fix this.  An updated version of the
consolidation patch
<https://sourceware.org/ml/libc-alpha/2016-09/msg00527.html> could
remove this syscalls.list entry again.

Tested with compilation (only) for mips64; the nature of the syscall
doesn't allow for a glibc test to detect this issue.

	[BZ #21026]
	* sysdeps/unix/sysv/linux/mips/mips64/n64/syscalls.list
	(readahead): New syscall entry.

(cherry picked from commit 30733525c6)
2017-04-09 19:51:08 +02:00
H.J. Lu 3966298a45 x86-64: Improve branch predication in _dl_runtime_resolve_avx512_opt [BZ #21258]
On Skylake server, _dl_runtime_resolve_avx512_opt is used to preserve
the first 8 vector registers.  The code layout is

  if only %xmm0 - %xmm7 registers are used
     preserve %xmm0 - %xmm7 registers
  if only %ymm0 - %ymm7 registers are used
     preserve %ymm0 - %ymm7 registers
  preserve %zmm0 - %zmm7 registers

Branch predication always executes the fallthrough code path to preserve
%zmm0 - %zmm7 registers speculatively, even though only %xmm0 - %xmm7
registers are used.  This leads to lower CPU frequency on Skylake
server.  This patch changes the fallthrough code path to preserve
%xmm0 - %xmm7 registers instead:

  if whole %zmm0 - %zmm7 registers are used
    preserve %zmm0 - %zmm7 registers
  if only %ymm0 - %ymm7 registers are used
     preserve %ymm0 - %ymm7 registers
  preserve %xmm0 - %xmm7 registers

Tested on Skylake server.

	[BZ #21258]
	* sysdeps/x86_64/dl-trampoline.S (_dl_runtime_resolve_opt):
	Define only if _dl_runtime_resolve is defined to
	_dl_runtime_resolve_sse_vex.
	* sysdeps/x86_64/dl-trampoline.h (_dl_runtime_resolve_opt):
	Fallthrough to _dl_runtime_resolve_sse_vex.

(cherry picked from commit c15f8eb50c)
2017-04-07 10:06:58 -07:00
Mike Frysinger cc5dcd8803 posix_spawn: use a larger min stack for -fstack-check [BZ #21253]
When glibc is built with -fstack-check, trying to use posix_spawn can
lead to segfaults due to gcc internally probing stack memory too far.
The new spawn API will allocate a minimum of 1 page, but the stack
checking logic might probe a couple of pages.  When it tries to walk
them, everything falls apart.

The gcc internal docs [1] state the default interval checking is one
page.  Which means we need two pages (the current one, and the next
probed).  No target currently defines it larger.

Further, it mentions that the default minimum stack size needed to
recover from an overflow is 4/8KiB for sjlj or 8/12KiB for others.
But some Linux targets (like mips and ppc) go up to 16KiB (and some
non-Linux targets go up to 24KiB).

Let's create each child with a minimum of 32KiB slack space to support
them all, and give us future breathing room.

No test is added as existing ones crash.  Even a simple call is
enough to trigger the problem:
	char *argv[] = { "/bin/ls", NULL };
	posix_spawn(NULL, "/bin/ls", NULL, NULL, argv, NULL);

[1] https://gcc.gnu.org/onlinedocs/gcc-6.3.0/gccint/Stack-Checking.html

(cherry picked from commit 21f042c804)
2017-04-03 15:20:45 -04:00
Slava Barinov 8cc2792743 fts: Fix symbol redirect for fts_set [BZ #21289]
In a 32-bit environment with _FILE_OFFSET_BITS=64, the __REDIRECT macro
combined with __THROW generates an invalid C++ declaration.

(cherry picked from commit ce39613205)
2017-03-31 10:02:53 +02:00
Mike Frysinger 7043946c79 posix_spawn: fix stack setup on ia64 [BZ #21275]
The ia64-specific clone2 call expects the base of the stack mapping and
the stack size as sep arguments, not an initial stack value as on other
stack-grows-down architectures.  Reuse the stack-grows-up macro so we
pass in the right stack base.

Reported-by: Matt Turner <mattst88@gentoo.org>
(cherry picked from commit ddc3fb3334)
2017-03-20 10:55:45 -04:00
John David Anglin 658b0abcff hppa: Fix setting of __libc_stack_end
The binutils package was recently changed to fix -z relro support on hppa.
See ld/21000 for details:
https://sourceware.org/bugzilla/show_bug.cgi?id=21000

This exposed a problem with the _dl_start_user function in the RTLD_START
define.  We need to set __libc_stack_end before it is made read only.  For
this, we need to define DL_STACK_END.  The offset of 0x160 gives the same
stack end as the code in _dl_start_user.

A build log with the attached patch is here:
https://buildd.debian.org/status/fetch.php?pkg=glibc&arch=hppa&ver=2.24-9&stamp=1487639205&raw=0

(cherry picked from commit 5d20a49aac)
2017-03-15 14:30:48 -07:00
H.J. Lu 4d393a8831 Add VZEROUPPER to memset-vec-unaligned-erms.S [BZ #21081]
Since memset-vec-unaligned-erms.S has VDUP_TO_VEC0_AND_SET_RETURN at
function entry, memset optimized for AVX2 and AVX512 will always use
ymm/zmm register. VZEROUPPER should be placed before ret in

L(stosb):
        movq    %rdx, %rcx
        movzbl  %sil, %eax
        movq    %rdi, %rdx
        rep stosb
        movq    %rdx, %rax
        ret

since it can be reached from

L(stosb_more_2x_vec):
        cmpq    $REP_STOSB_THRESHOLD, %rdx
        ja      L(stosb)

	[BZ #21081]
	* sysdeps/x86_64/multiarch/memset-vec-unaligned-erms.S
	(L(stosb)): Add VZEROUPPER before ret.

(cherry picked from commit 02b78ff749)
2017-02-24 09:46:15 -08:00
H.J. Lu d012ea8506 X86_64: Don't use PLT nor GOT in static archives [BZ #20750]
There is no need to use PLT nor GOT in static archives to branch to a
function, regardless whether static archives is compiled with PIC or
not.  When static archives are used to create dynamic executable,
PLT/GOT may be used.  The resulting executable still works correctly.

	[BZ #20750]
	* sysdeps/x86_64/sysdep.h (JUMPTARGET): Check SHARED instead
	of PIC.

(cherry picked from commit c9070e6305)
2017-02-09 11:05:18 -05:00
Florian Weimer b3b37f1a55 CVE-2015-5180: resolv: Fix crash with internal QTYPE [BZ #18784]
Also rename T_UNSPEC because an upcoming public header file
update will use that name.

(cherry picked from commit fc82b0a2df)
2017-02-09 00:24:02 -05:00
Siddhesh Poyarekar 537a06fbde Drop GLIBC_TUNABLES in setxid processes
Drop the GLIBC_TUNABLES environment variable from the environment of
setxid processes to avoid passing it on to non-setxid children.  This
prevents potentially insecure tunables in the GLIBC_TUNABLES envvar
from crossing over into a child that may use a libc that has tunables
support.

	* sysdeps/generic/unsecvars.h: Add GLIBC_TUNABLES.
2017-02-02 16:15:45 +05:30
Tulio Magno Quites Machado Filho 2762a7145b powerpc: Fix write-after-destroy in lock elision [BZ #20822]
The update of *adapt_count after the release of the lock causes a race
condition when thread A unlocks, thread B continues and destroys the
mutex, and thread A writes to *adapt_count.

(cherry picked from commit e9a96ea1ac)
(with changes from commit eb1321f291)
2017-01-23 14:39:47 -02:00
Mike Frysinger 7e4405c50f localedata: bs_BA: fix yesexpr/noexpr [BZ #20974]
Both regexes end with a "*." which means the previous match can be
omitted, and then the . allows them to match any input at all.

This means tools like coreutils' `rm -i` will always delete things
when prompted because the yesexpr regex matches all inputs (even
the negative ones).

(cherry picked from commit a035eb6928)
2016-12-30 01:50:33 -05:00
Carlos O'Donell e9e69e4680 Bug 11941: ld.so: Improper assert map->l_init_called in dlclose
There is at least one use case where during exit a library destructor
might call dlclose() on a valid handle and have it fail with an
assertion. We must allow this case, it is a valid handle, and dlclose()
should not fail with an assert. In the future we might be able to return
an error that the dlclose() could not be completed because the opened
library has already been unloaded and destructors have run as part of
exit processing.

For more details see:
https://www.sourceware.org/ml/libc-alpha/2016-12/msg00859.html

(cherry picked from commit 57707b7fcc)
2016-12-23 15:41:57 -05:00
Aurelien Jarno e6eab16cc3 alpha: fix trunc for big input values
The alpha specific version of trunc and truncf always add and subtract
0x1.0p23 or 0x1.0p52 even for big values. This causes this kind of
errors in the testsuite:

  Failure: Test: trunc_towardzero (0x1p107)
  Result:
   is:          1.6225927682921334e+32   0x1.fffffffffffffp+106
   should be:   1.6225927682921336e+32   0x1.0000000000000p+107
   difference:  1.8014398509481984e+16   0x1.0000000000000p+54
   ulp       :  0.5000
   max.ulp   :  0.0000

Change this by returning the input value when its absolute value is
greater than 0x1.0p23 or 0x1.0p52. NaN have to go through the add and
subtract operations to get possibly silenced.

Finally remove the code to handle inexact exception, trunc should never
generate such an exception.

Changelog:
	* sysdeps/alpha/fpu/s_trunc.c (__trunc): Return the input value
	when its absolute value is greater than 0x1.0p52.
	[_IEEE_FP_INEXACT] Remove.
	* sysdeps/alpha/fpu/s_truncf.c (__truncf): Return the input value
	when its absolute value is greater than 0x1.0p23.
	[_IEEE_FP_INEXACT] Remove.

(cherry picked from commit b74d259fe7)
2016-12-08 00:57:11 -05:00
Aurelien Jarno 8eb9a92e05 alpha: fix rint on sNaN input
The alpha version of rint wrongly return sNaN for sNaN input. Fix that
by checking for NaN and by returning the input value added with itself
in that case.

Changelog:
	* sysdeps/alpha/fpu/s_rint.c (__rint): Add argument with itself
	when it is a NaN.
	* sysdeps/alpha/fpu/s_rintf.c (__rintf): Likewise.

(cherry picked from commit cb7f9d63b9)
2016-12-08 00:57:05 -05:00
Aurelien Jarno 1912cc082d alpha: fix floor on sNaN input
The alpha version of floor wrongly return sNaN for sNaN input. Fix that
by checking for NaN and by returning the input value added with itself
in that case.

Finally remove the code to handle inexact exception, floor should never
generate such an exception.

Changelog:
	* sysdeps/alpha/fpu/s_floor.c (__floor): Add argument with itself
	when it is a NaN.
	[_IEEE_FP_INEXACT] Remove.
	* sysdeps/alpha/fpu/s_floorf.c (__floorf): Likewise.

(cherry picked from commit 65cc568cf5)
2016-12-08 00:56:59 -05:00
Aurelien Jarno 3eff6f8431 alpha: fix ceil on sNaN input
The alpha version of ceil wrongly return sNaN for sNaN input. Fix that
by checking for NaN and by returning the input value added with itself
in that case.

Finally remove the code to handle inexact exception, ceil should never
generate such an exception.

Changelog:
	* sysdeps/alpha/fpu/s_ceil.c (__ceil): Add argument with itself
	when it is a NaN.
	[_IEEE_FP_INEXACT] Remove.
	* sysdeps/alpha/fpu/s_ceilf.c (__ceilf): Likewise.

(cherry picked from commit 062e53c195)
2016-12-08 00:56:55 -05:00
H.J. Lu 4b8790c81c X86-64: Add _dl_runtime_resolve_avx[512]_{opt|slow} [BZ #20508]
There is transition penalty when SSE instructions are mixed with 256-bit
AVX or 512-bit AVX512 load instructions.  Since _dl_runtime_resolve_avx
and _dl_runtime_profile_avx512 save/restore 256-bit YMM/512-bit ZMM
registers, there is transition penalty when SSE instructions are used
with lazy binding on AVX and AVX512 processors.

To avoid SSE transition penalty, if only the lower 128 bits of the first
8 vector registers are non-zero, we can preserve %xmm0 - %xmm7 registers
with the zero upper bits.

For AVX and AVX512 processors which support XGETBV with ECX == 1, we can
use XGETBV with ECX == 1 to check if the upper 128 bits of YMM registers
or the upper 256 bits of ZMM registers are zero.  We can restore only the
non-zero portion of vector registers with AVX/AVX512 load instructions
which will zero-extend upper bits of vector registers.

This patch adds _dl_runtime_resolve_sse_vex which saves and restores
XMM registers with 128-bit AVX store/load instructions.  It is used to
preserve YMM/ZMM registers when only the lower 128 bits are non-zero.
_dl_runtime_resolve_avx_opt and _dl_runtime_resolve_avx512_opt are added
and used on AVX/AVX512 processors supporting XGETBV with ECX == 1 so
that we store and load only the non-zero portion of vector registers.
This avoids SSE transition penalty caused by _dl_runtime_resolve_avx and
_dl_runtime_profile_avx512 when only the lower 128 bits of vector
registers are used.

_dl_runtime_resolve_avx_slow is added and used for AVX processors which
don't support XGETBV with ECX == 1.  Since there is no SSE transition
penalty on AVX512 processors which don't support XGETBV with ECX == 1,
_dl_runtime_resolve_avx512_slow isn't provided.

	[BZ #20495]
	[BZ #20508]
	* sysdeps/x86/cpu-features.c (init_cpu_features): For Intel
	processors, set Use_dl_runtime_resolve_slow and set
	Use_dl_runtime_resolve_opt if XGETBV suports ECX == 1.
	* sysdeps/x86/cpu-features.h (bit_arch_Use_dl_runtime_resolve_opt):
	New.
	(bit_arch_Use_dl_runtime_resolve_slow): Likewise.
	(index_arch_Use_dl_runtime_resolve_opt): Likewise.
	(index_arch_Use_dl_runtime_resolve_slow): Likewise.
	* sysdeps/x86_64/dl-machine.h (elf_machine_runtime_setup): Use
	_dl_runtime_resolve_avx512_opt and _dl_runtime_resolve_avx_opt
	if Use_dl_runtime_resolve_opt is set.  Use
	_dl_runtime_resolve_slow if Use_dl_runtime_resolve_slow is set.
	* sysdeps/x86_64/dl-trampoline.S: Include <cpu-features.h>.
	(_dl_runtime_resolve_opt): New.  Defined for AVX and AVX512.
	(_dl_runtime_resolve): Add one for _dl_runtime_resolve_sse_vex.
	* sysdeps/x86_64/dl-trampoline.h (_dl_runtime_resolve_avx_slow):
	New.
	(_dl_runtime_resolve_opt): Likewise.
	(_dl_runtime_profile): Define only if _dl_runtime_profile is
	defined.

(cherry picked from commit fb0f7a6755)
2016-11-30 08:37:50 -08:00
Aurelien Jarno 2d16e81bab x86_64: fix static build of __memcpy_chk for compilers defaulting to PIC/PIE
When glibc is compiled with gcc 6.2 that has been configured with
to default to PIC/PIE, the static version of __memcpy_chk is not built,
as the test is done on PIC instead of SHARED. Fix the test to check for
SHARED, like it is done for similar functions like memmove_chk.

Changelog:
	* sysdeps/x86_64/memcpy_chk.S (__memcpy_chk): Check for SHARED
	instead of PIC.

(cherry picked from commit 380ec16d62)
2016-11-24 16:57:23 +01:00
Maciej W. Rozycki 65a2b63756 MIPS: Add `.insn' to ensure a text label is defined as code not data
Avoid a build error with microMIPS compilation and recent versions of
GAS which complain if a branch targets a label which is marked as data
rather than microMIPS code:

../sysdeps/mips/mips32/crti.S: Assembler messages:
../sysdeps/mips/mips32/crti.S:72: Error: branch to a symbol in another ISA mode
make[2]: *** [.../csu/crti.o] Error 1

as commit 9d862524f6ae ("MIPS: Verify the ISA mode and alignment of
branch and jump targets") closed a hole in branch processing, making
relocation calculation respect the ISA mode of the symbol referred.
This allowed diagnosing the situation where an attempt is made to pass
control from code assembled for one ISA mode to code assembled for a
different ISA mode and either relaxing the branch to a cross-mode jump
or if that is not possible, then reporting this as an error rather than
letting such code build and then fail unpredictably at the run time.

This however requires the correct annotation of branch targets as code,
because the ISA mode is not relevant for data symbols and is therefore
not recorded for them.  The `.insn' pseudo-op is used for this purpose
and has been supported by GAS since:

Wed Feb 12 14:36:29 1997  Ian Lance Taylor  <ian@cygnus.com>

	* config/tc-mips.c (mips_pseudo_table): Add "insn".
	(s_insn): New static function.
	* doc/c-mips.texi: Document .insn.

so there has been no reason to avoid it where required.  More recently
this pseudo-op has been documented, by the microMIPS architecture
specification[1][2], as required for the correct interpretation of any
code label which is not followed by an actual instruction in an assembly
source.

Use it in our crti.S files then, to mark that the trailing label there
with no instructions following is indeed not a code bug and the branch
is legitimate.

References:

[1] "MIPS Architecture for Programmers, Volume II-B: The microMIPS32
    Instruction Set", MIPS Technologies, Inc., Document Number: MD00582,
    Revision 5.04, January 15, 2014, Section 7.1 "Assembly-Level
    Compatibility", p. 533

[2] "MIPS Architecture for Programmers, Volume II-B: The microMIPS64
    Instruction Set", MIPS Technologies, Inc., Document Number: MD00594,
    Revision 5.04, January 15, 2014, Section 8.1 "Assembly-Level
    Compatibility", p. 623

2016-11-23  Matthew Fortune  <Matthew.Fortune@imgtec.com>
            Maciej W. Rozycki  <macro@imgtec.com>

	* sysdeps/mips/mips32/crti.S (_init): Add `.insn' pseudo-op at
	`.Lno_weak_fn' label.
	* sysdeps/mips/mips64/n32/crti.S (_init): Likewise.
	* sysdeps/mips/mips64/n64/crti.S (_init): Likewise.

(cherry picked from commit cfaf1949ff)
2016-11-23 12:55:45 +00:00
Adhemerval Zanella d174436712 Fix writes past the allocated array bounds in execvpe (BZ#20847)
This patch fixes an invalid write out or stack allocated buffer in
2 places at execvpe implementation:

  1. On 'maybe_script_execute' function where it allocates the new
     argument list and it does not account that a minimum of argc
     plus 3 elements (default shell path, script name, arguments,
     and ending null pointer) should be considered.  The straightforward
     fix is just to take account of the correct list size on argument
     copy.

  2. On '__execvpe' where the executable file name lenght may not
     account for ending '\0' and thus subsequent path creation may
     write past array bounds because it requires to add the terminating
     null.  The fix is to change how to calculate the executable name
     size to add the final '\0' and adjust the rest of the code
     accordingly.

As described in GCC bug report 78433 [1], these issues were masked off by
GCC because it allocated several bytes more than necessary so that many
off-by-one bugs went unnoticed.

Checked on x86_64 with a latest GCC (7.0.0 20161121) with -O3 on CFLAGS.

	[BZ #20847]
	* posix/execvpe.c (maybe_script_execute): Remove write past allocated
	array bounds.
	(__execvpe): Likewise.

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78433
2016-11-22 10:56:07 -02:00
Denis Kaganovich 2bdb3d2ee1 configure: accept __stack_chk_fail_local for ssp support too [BZ #20662]
When glibc is compiled with gcc 6.2 that has been configured with
--enable-default-pie and --enable-default-ssp, the configure script
fails to detect that the compiler has ssp turned on by default when
being built for i686-linux-gnu.

This is because gcc is emitting __stack_chk_fail_local but the
script is only looking for __stack_chk_fail.  Support both.

Example output:
checking whether x86_64-pc-linux-gnu-gcc -m32 -Wl,-O1 -Wl,--as-needed
implicitly enables -fstack-protector... no

(cherry picked from commit c7409aded4)
2016-11-15 14:30:27 -05:00
Joseph Myers 822305be76 Fix linknamespace parallel test failures.
Having found that with my script to build many glibc variants I could
reproduce the linknamespace test failures in parallel builds (that
various people had previously reported but I hadn't seen myself), I
investigated those failures further.  This patch adds a missing
dependency to those tests.

Tested for x86_64, including the configuration where I saw those
failures and where I don't see them with this patch.

	* conform/Makefile ($(linknamespace-header-tests)): Also depend on
	$(linknamespace-symlists-tests).

(cherry picked from commit 6c50bb532b)
2016-11-06 21:37:27 +01:00
Aurelien Jarno fe783a26a5 gconv.h: fix build with GCC 7
gconv.h is using a flex array to define the __gconv_info member in an
invalid way, causing GCC 7 to issue an error:

| In file included from ../include/gconv.h:1:0,
|                  from ../sysdeps/unix/sysv/linux/_G_config.h:32,
|                  from ../libio/libio.h:31,
|                  from ../include/libio.h:4,
|                  from ../libio/stdio.h:74,
|                  from ../include/stdio.h:5,
|                  from test-math-isinff.cc:22:
| ../iconv/gconv.h:142:50: error: flexible array member '__gconv_info::__data' not at end of 'struct _IO_codecvt'
| In file included from ../include/libio.h:4:0,
|                  from ../libio/stdio.h:74,
|                  from ../include/stdio.h:5,
|                  from test-math-isinff.cc:22:
| ../libio/libio.h:211:14: note: next member '_G_iconv_t _IO_codecvt::__cd_out' declared here
| ../libio/libio.h:187:8: note: in the definition of 'struct _IO_codecvt'
| In file included from ../include/gconv.h:1:0,
|                  from ../sysdeps/unix/sysv/linux/_G_config.h:32,
|                  from ../libio/libio.h:31,
|                  from ../include/libio.h:4,
|                  from ../libio/stdio.h:74,
|                  from ../include/stdio.h:5,
|                  from test-math-isinff.cc:22:
| ../iconv/gconv.h:142:50: error: flexible array member '__gconv_info::__data' not at end of 'struct _IO_wide_data'
| In file included from ../include/libio.h:4:0,
|                  from ../libio/stdio.h:74,
|                  from ../include/stdio.h:5,
|                  from test-math-isinff.cc:22:
| ../libio/libio.h:211:14: note: next member '_G_iconv_t _IO_codecvt::__cd_out' declared here
| ../libio/libio.h:215:8: note: in the definition of 'struct _IO_wide_data'

This is basically a revert to the code from 15 years ago. More details
are available in the GCC bug:
  https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78039

Changelog:
	* iconv/gconv.h (__gconv_info): Define __data element using a
	zero-length array.

(cherry picked from commit 0623b9e6a9)
2016-11-06 21:34:19 +01:00
Joseph Myers 797c7fb197 Fix cmpli usage in power6 memset.
Building glibc for powerpc64 with recent (2.27.51.20161012) binutils,
with multi-arch enabled, I get the error:

../sysdeps/powerpc/powerpc64/power6/memset.S: Assembler messages:
../sysdeps/powerpc/powerpc64/power6/memset.S:254: Error: operand out of range (5 is not between 0 and 1)
../sysdeps/powerpc/powerpc64/power6/memset.S:254: Error: operand out of range (128 is not between 0 and 31)
../sysdeps/powerpc/powerpc64/power6/memset.S:254: Error: missing operand

Indeed, cmpli is documented as a four-operand instruction, and looking
at nearby code it seems likely cmpldi was intended.  This patch fixes
this powerpc64 code accordingly, and makes a corresponding change to
the powerpc32 code.

Tested for powerpc, powerpc64 and powerpc64le by Tulio Magno Quites
Machado Filho

	* sysdeps/powerpc/powerpc32/power6/memset.S (memset): Use cmplwi
	instead of cmpli.
	* sysdeps/powerpc/powerpc64/power6/memset.S (memset): Use cmpldi
	instead of cmpli.

(cherry picked from commit 78b7adbaea)
2016-11-06 21:19:21 +01:00
Adhemerval Zanella ccebcff824 Fix Linux sh4 pread/pwrite argument passing
Although conceptually correct for p{read,write}{64} offset argument passing,
sh4 implementation does not generate the correct expected code.  The
__ALIGNMENT_ARG redefinition is incorrect for two reasons: 1. the
kernel-features.h header is included multiple times (since it contains no
guards) and 2. the value it redefines is also incorrect (should be '0, '
instead of empty definition).

This patch fixes it by adding another macro, SYSCALL_LL_PRW{64}, meant to be
used to pass the offset argument on p{read,write}64.  It is basically the
already define SYSCALL_LL{64} plus __ALIGNMENT_ARG unless __ASSUME_PRW_DUMMY_ARG
is define.  In this case an empty dummy argument is used regardless how
__ALIGNMENT_ARG is defined (sh4 case).

Checked on x86_64, i686, aarch64, armhf, and powerpc64le (basically a sanity
check).  Also, John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de> and
James Clarke <jrtc27@jrtc27.com> help me check on a debian sh4 bootstrap using
2.24 plus this patch to verify it also corrected fixed the regression issue.

I also verified the generated object for a 2.24 build and master with this
patch for sh4 and both look identical.

	* sysdeps/unix/sysv/linux/pread.c (__libc_pread): Use SYSCALL_LL_PRW.
	* sysdeps/unix/sysv/linux/pwrite.c (__libc_pwrite): Likewise.
	* sysdeps/unix/sysv/linux/pread64.c (__libc_pread64): Use
	SYSCALL_LL64_PRW.
	* sysdeps/unix/sysv/linux/pwrite64.c (__libc_pwrite64): Likewise.
	* sysdeps/unix/sysv/linux/sh/kernel-features.h: Define
	__ASSUME_PRW_DUMMY_ARG.
	* sysdeps/unix/sysv/linux/sh/pread.c: Remove file.
	* sysdeps/unix/sysv/linux/sh/pread64.c: Likewise.
	* sysdeps/unix/sysv/linux/sh/pwrite.c: Likewise.
	* sysdeps/unix/sysv/linux/sh/pwrite64.c: Likewise.
	* sysdeps/unix/sysv/linux/sysdep.h: Define SYSCALL_LL_PRW and
	SYSCALL_LL_PRW64 based on __ASSUME_PRW_DUMMY_ARG.
2016-10-24 15:29:11 -02:00
Tulio Magno Quites Machado Filho 4467e53ab2 powerpc: Regenerate ULPs
* sysdeps/powerpc/fpu/libm-test-ulps: Regenerated.
2016-10-05 11:00:04 -03:00
Adhemerval Zanella 066437ad32 posix: Correctly block/unblock all signals on Linux posix_spawn
This patch correctly block and unblocks all signals when executing
Linux posix_spawn by using the __libc_signal_{un}block_all functions
instead of default sigprocmask.  The latter might remove both
SIGCANCEL and SIGSETXID from the blocked signal list.

Checked on x86_64, i686, powerpc64le, and aarch64.

	* sysdeps/unix/sysv/linux/spawni.c (__spawnix): Correctly block and unblock
	all signals when executing the clone vfork child.
	(SIGALL_SET): Remove macro.
2016-09-28 15:30:07 -07:00
Adhemerval Zanella 28202d1341 posix: Correctly enable/disable cancellation on Linux posix_spawn
This patch correctly enable and disable asynchronous cancellation on
Linux posix_spawn.  Current code invert the logic by enabling and
disabling instead.  It also adds a new test to check if posix_spawn
is not a cancellation entrypoint.

Checked on x86_64, i686, powerpc64le, and aarch64.

	* nptl/Makefile (tests): Add tst-exec5.
	* nptl/tst-exec5.c: New file.
	* sysdeps/unix/sysv/linux/spawni.c (__spawni): Correctly enable and disable
	asynchronous cancellation.
2016-09-28 15:29:59 -07:00
Tulio Magno Quites Machado Filho 66b8f3d8ec powerpc: Fix POWER9 implies
Fix multiarch build for POWER9 by correcting the order of the
directories listed at sysnames configure variable.

(cherry picked from commit 1850ce5a2e)
2016-09-19 11:02:49 -03:00
Roland McGrath e591222f99 NaCl: Fix libc.abilist missing GLIBC_2.24 A.
* sysdeps/arm/nacl/libc.abilist: Add GLIBC_2.24 A.
2016-09-02 17:19:31 -07:00
Roland McGrath a7a8929491 NaCl: Fix compile error for __dup after libc_hidden_proto addition.
* sysdeps/nacl/dup.c: Add libc_hidden_def.

(cherry picked from commit 6b75ba1388)
2016-09-02 16:59:57 -07:00
Roland McGrath d289049cf5 Fix generic wait3 after union wait_status removal.
* sysdeps/posix/wait3.c: Don't treat STAT_LOC as a union, since it's
	not any more.

(cherry picked from commit 9a3d16ac15)
2016-09-02 16:59:49 -07:00
Roland McGrath 5370672480 NaCl: Fix compile error in clock function.
* sysdeps/nacl/clock.c (clock): nacl_abi_clock_t -> nacl_irt_clock_t

(cherry picked from commit 307c2c2dff)
2016-09-02 16:59:45 -07:00
Florian Weimer 8c716c2e2f nptl/tst-once5: Reduce time to expected failure
(cherry picked from commit 1f645571d2)
2016-08-18 12:00:11 +02:00
Florian Weimer 58ef663c94 argp: Do not override GCC keywords with macros [BZ #16907]
glibc provides fallback definitions already.  It is not necessary to
suppress warnings for unknown attributes because GCC does this
automatically for system headers.

This commit does not sync with gnulib because gnulib has started to use
_GL_* macros in the header file, which are arguably in the gnulib
implementation space and not suitable for an installed glibc header
file.

(cherry picked from commit 2c820533c6)
2016-08-18 11:40:21 +02:00
Andreas Schwab 72450627ba arm: mark __startcontext as .cantunwind (bug 20435)
__startcontext marks the bottom of the call stack of the contexts created
by makecontext.

(cherry picked from commit 9e2ff6c9cc)

Also includes the NEWS update, cherry-picked from commits
056dd72af8 and
4d047efdbc.
2016-08-18 11:38:28 +02:00
Florian Weimer e2e4984ad6 Do not override objects in libc.a in other static libraries [BZ #20452]
With this change, we no longer add sysdep.o and similar objects which
are present in libc.a to other static libraries.

(cherry picked from commit d9067fca40)
2016-08-18 11:35:45 +02:00
Aurelien Jarno 0ba4a7522b sparc: remove fdim sparc specific implementations
The fdim and fdimf functions on sparc do not fully follow the standard
and do not set errno to ERANGE when the result overflows. Since glibc
2.24 this causes the two following tests to fail:

  Failure: fdim (max_value, -max_value): errno set to 0, expected 34 (ERANGE)
  Failure: fdim_upward (max_value, -max_value): errno set to 0, expected 34 (ERANGE)

It happens that using GCC with the generic C code generates very similar
code to the sparc specific implementations. Therefore this patches
remove them. Note it might still worth adding a vis3 specific version of
fdim on sparc32/sparcv9, this is done in a following patch to ease
backporting.

Changelog:
	* sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/Makefile
	[$(subdir) = math && $(have-as-vis3) = yes] (libm-sysdep_routines):
	Remove s_fdimf-vis3, s_fdim-vis3.
	* sysdeps/sparc/sparc32/fpu/s_fdim.S: Delete file.
	* sysdeps/sparc/sparc32/fpu/s_fdimf.S: Likewise.
	* sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/s_fdim-vis3.S: Likewise.
	* sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/s_fdim.S: Likewise.
	* sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/s_fdimf-vis3.S: Likewise.
	* sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/s_fdimf.S: Likewise.
	* sysdeps/sparc/sparc32/sparcv9/fpu/s_fdim.S: Likewise.
	* sysdeps/sparc/sparc32/sparcv9/fpu/s_fdimf.S: Likewise.
	* sysdeps/sparc/sparc64/fpu/s_fdim.S: Likewise.
	* sysdeps/sparc/sparc64/fpu/s_fdimf.S: Likewise.

(cherry picked from commit 8a9f4eb958)
2016-08-15 00:29:30 +02:00
David S. Miller b3012e4d56 Fix sNaN handling in nearbyint on 32-bit sparc.
* sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/s_nearbyint-vis3.S
	(__nearbyint_vis3): Don't check for sNaN before float register is
	loaded with the incoming argument.
	* sysdeps/sparc/sparc32/sparcv9/fpu/multiarch/s_nearbyintf-vis3.S
	(__nearbyintf_vis3): Likewise.
	* sysdeps/sparc/sparc32/sparcv9/fpu/s_nearbyint.S (__nearbyint):
	Likewise.
	* sysdeps/sparc/sparc32/sparcv9/fpu/s_nearbyintf.S (__nearbyintf):
	Likewise.

(cherry picked from commit 3ef3f1b93f)
2016-08-15 00:28:58 +02:00
Aurelien Jarno f038a42f54 powerpc: fix ifunc-sel.h fix asm constraints and clobber list
As pointer out on the mailing list, the inline assembly code in
sysdeps/powerpc/ifunc-sel.h doesn't have a list of clobbered registers
and used wrong constraints.

This patch fixes that. I verified it doesn't introduce any change in the
generated code.

Changelog:
	* sysdeps/powerpc/ifunc-sel.h (ifunc_sel): Add "11", "12", "cr0" to the
	clobber list. Use "i" constraint instead of "X".
	(ifunc_one): Add "12" to the clobber list. Use "i" constraint instead
	of "X".

(cherry picked from commit 30f926d3b3)
2016-08-14 22:48:23 +02:00
Aurelien Jarno 8026e9db17 powerpc: fix ifunc-sel.h with GCC 6
On 32-bit PowerPC GCC 6 always saves the PIC register on the stack in
the prologue and adjust the stack in the epilogue. It is therefore not
possible anymore to just exit the function in the inline asm code,
otherwise it corrupts the stack pointer. This causes the following tests
to fail when using GCC 6:

FAIL: elf/ifuncmain1
FAIL: elf/ifuncmain1pic
FAIL: elf/ifuncmain1picstatic
FAIL: elf/ifuncmain1pie
FAIL: elf/ifuncmain1staticpic
FAIL: elf/ifuncmain1staticpie
FAIL: elf/ifuncmain1vis
FAIL: elf/ifuncmain1vispic
FAIL: elf/ifuncmain1vispie
FAIL: elf/ifuncmain2pic
FAIL: elf/ifuncmain2picstatic
FAIL: elf/ifuncmain3
FAIL: elf/ifuncmain4picstatic
FAIL: elf/ifuncmain5
FAIL: elf/ifuncmain5picstatic
FAIL: elf/ifuncmain5staticpic

The solution is to replace the beqlr instructions by a beq to the end
of the inline asm code. This fixes all the above failures.

ChangeLog:
	* sysdeps/powerpc/ifunc-sel.h (ifunc_sel): Replace beqlr instructions
	by beq instructions jumping to the end of the function.

(cherry picked from commit ee71e5b6dd)
2016-08-14 22:48:18 +02:00
Carlos O'Donell ea23815a79 Update from Translation Project. 2016-08-04 12:21:42 -04:00
Florian Weimer 96cd434f66 malloc: Preserve arena free list/thread count invariant [BZ #20370]
It is necessary to preserve the invariant that if an arena is
on the free list, it has thread attach count zero.  Otherwise,
when arena_thread_freeres sees the zero attach count, it will
add it, and without the invariant, an arena could get pushed
to the list twice, resulting in a cycle.

One possible execution trace looks like this:

Thread 1 examines free list and observes it as empty.
Thread 2 exits and adds its arena to the free list,
  with attached_threads == 0).
Thread 1 selects this arena in reused_arena (not from the free list).
Thread 1 increments attached_threads and attaches itself.
  (The arena remains on the free list.)
Thread 1 exits, decrements attached_threads,
  and adds the arena to the free list.

The final step creates a cycle in the usual way (by overwriting the
next_free member with the former list head, while there is another
list item pointing to the arena structure).

tst-malloc-thread-exit exhibits this issue, but it was only visible
with a debugger because the incorrect fix in bug 19243 removed
the assert from get_free_list.

(cherry picked from commit f88aab5d50)
2016-08-04 11:49:55 +02:00
Florian Weimer d39c4a5ec0 x86: Use sysdep.o from libc.a in static libraries
Static libraries can use the sysdep.o copy in libc.a without
a performance penalty.  This results in a visible difference
if libpthread.a is relinked into a single object file (which
is needed to support libraries which check for the presence
of certain symbols to enable threading support, which generally
fails with static linking unless libpthread.a is relinked).

(cherry picked from commit e67330ab57)
2016-08-04 11:45:53 +02:00
402 changed files with 13171 additions and 2438 deletions
+1100
View File
File diff suppressed because it is too large Load Diff
+12 -3
View File
@@ -394,6 +394,9 @@ ifndef after-link
after-link =
endif
# Additional libraries to link into every test.
link-extra-libs-tests = $(libsupport)
# Command for linking PIE programs with the C library.
ifndef +link-pie
+link-pie-before-libc = $(CC) -pie -Wl,-O1 -nostdlib -nostartfiles -o $@ \
@@ -503,7 +506,7 @@ link-libc = $(link-libc-rpath-link) $(link-libc-before-gnulib) $(gnulib)
link-libc-tests = $(link-libc-tests-rpath-link) \
$(link-libc-before-gnulib) $(gnulib-tests)
# This is how to find at build-time things that will be installed there.
rpath-dirs = math elf dlfcn nss nis rt resolv crypt mathvec
rpath-dirs = math elf dlfcn nss nis rt resolv crypt mathvec support
rpath-link = \
$(common-objdir):$(subst $(empty) ,:,$(patsubst ../$(subdir),.,$(rpath-dirs:%=$(common-objpfx)%)))
else
@@ -850,7 +853,7 @@ libio-include = -I$(..)libio
# List of non-library modules that we build.
built-modules = iconvprogs iconvdata ldconfig lddlibc4 libmemusage \
libSegFault libpcprofile librpcsvc locale-programs \
memusagestat nonlib nscd extramodules libnldbl
memusagestat nonlib nscd extramodules libnldbl libsupport
in-module = $(subst -,_,$(firstword $(libof-$(basename $(@F))) \
$(libof-$(<F)) \
@@ -1089,6 +1092,12 @@ libm = $(common-objpfx)math/libm.a
libmvec = $(common-objpfx)mathvec/libmvec.a
endif
ifeq ($(build-shared),yes)
libsupport = $(common-objpfx)support/libsupport_nonshared.a
else
libsupport = $(common-objpfx)support/libsupport.a
endif
# These are the subdirectories containing the library source. The order
# is more or less arbitrary. The sorting step will take care of the
# dependencies.
@@ -1096,7 +1105,7 @@ all-subdirs = csu assert ctype locale intl catgets math setjmp signal \
stdlib stdio-common libio malloc string wcsmbs time dirent \
grp pwd posix io termios resource misc socket sysvipc gmon \
gnulib iconv iconvdata wctype manual shadow gshadow po argp \
crypt localedata timezone rt conform debug mathvec \
crypt localedata timezone rt conform debug mathvec support \
$(add-on-subdirs) dlfcn elf
ifndef avoid-generated
+102
View File
@@ -4,6 +4,108 @@ See the end for copying conditions.
Please send GNU C library bug reports via <http://sourceware.org/bugzilla/>
using `glibc' in the "product" field.
Version 2.24.1
Security related changes:
* On ARM EABI (32-bit), generating a backtrace for execution contexts which
have been created with makecontext could fail to terminate due to a
missing .cantunwind annotation. This has been observed to lead to a hang
(denial of service) in some Go applications compiled with gccgo. Reported
by Andreas Schwab. (CVE-2016-6323)
* The DNS stub resolver functions would crash due to a NULL pointer
dereference when processing a query with a valid DNS question type which
was used internally in the implementation. The stub resolver now uses a
question type which is outside the range of valid question type values.
(CVE-2015-5180)
* CVE-2017-15670: The glob function, when invoked with GLOB_TILDE, suffered
from a one-byte overflow during ~ operator processing (either on the stack
or the heap, depending on the length of the user name).
* CVE-2017-15671: The glob function, when invoked with GLOB_TILDE,
would sometimes fail to free memory allocated during ~ operator
processing, leading to a memory leak and, potentially, to a denial
of service.
* CVE-2017-15804: The glob function, when invoked with GLOB_TILDE and
without GLOB_NOESCAPE, could write past the end of a buffer while
unescaping user names. Reported by Tim Rühsen.
* CVE-2017-1000408: Incorrect array size computation in _dl_init_paths leads
to the allocation of too much memory. (This is not a security bug per se,
it is mentioned here only because of the CVE assignment.) Reported by
Qualys.
* CVE-2017-1000409: Buffer overflow in _dl_init_paths due to miscomputation
of the number of search path components. (This is not a security
vulnerability per se because no trust boundary is crossed if the fix for
CVE-2017-1000366 has been applied, but it is mentioned here only because
of the CVE assignment.) Reported by Qualys.
CVE-2017-16997: Incorrect handling of RPATH or RUNPATH containing $ORIGIN
for AT_SECURE or SUID binaries could be used to load libraries from the
current directory.
CVE-2017-18269: An SSE2-based memmove implementation for the i386
architecture could corrupt memory. Reported by Max Horn.
CVE-2018-11236: Very long pathname arguments to realpath function could
result in an integer overflow and buffer overflow. Reported by Alexey
Izbyshev.
CVE-2018-11237: The mempcpy implementation for the Intel Xeon Phi
architecture could write beyond the target buffer, resulting in a buffer
overflow. Reported by Andreas Schwab.
CVE-2019-6488: On x32, the size_t parameter may be passed in the lower
32 bits of a 64-bit register with with non-zero upper 32 bit. When it
happened, accessing the 32-bit size_t value as the full 64-bit register
in the assembly string/memory functions would cause a buffer overflow.
Reported by H.J. Lu.
CVE-2019-7309: x86-64 memcmp used signed Jcc instructions to check
size. For x86-64, memcmp on an object size larger than SSIZE_MAX
has undefined behavior. On x32, the size_t argument may be passed
in the lower 32 bits of the 64-bit RDX register with non-zero upper
32 bits. When it happened with the sign bit of RDX register set,
memcmp gave the wrong result since it treated the size argument as
zero. Reported by H.J. Lu.
CVE-2019-19126: ld.so failed to ignore the LD_PREFER_MAP_32BIT_EXEC
environment variable during program execution after a security
transition, allowing local attackers to restrict the possible mapping
addresses for loaded libraries and thus bypass ASLR for a setuid
program. Reported by Marcin Kościelnicki.
The following bugs are resolved with this release:
[20116] nptl: use after free in pthread_create
[20790] Fix rpcgen buffer overrun
[20978] Fix strlen on null pointer in nss_nisplus
[21209] Ignore and remove LD_HWCAP_MASK for AT_SECURE programs
[21265] x86-64: Use fxsave/xsave/xsavec in _dl_runtime_resolve
[21289] Fix symbol redirect for fts_set
[21386] Assertion in fork for distinct parent PID is incorrect
[21609] x86-64: Align the stack in __tls_get_addr
[21624] Unsafe alloca allows local attackers to alias stack and heap (CVE-2017-1000366)
[21654] nss: Fix invalid cast in group merging
[22636] PTHREAD_STACK_MIN is too small on x86-64
[22637] nptl: Fix stack guard size accounting
[22644] string: memmove-sse2-unaligned on 32bit x86 produces garbage when
crossing 2GB threshold (CVE-2017-18269)
[22715] x86-64: Properly align La_x86_64_retval to VEC_SIZE
[22786] libc: Stack buffer overflow in realpath() if input size is close
to SSIZE_MAX (CVE-2018-11236)
[23196] string: __mempcpy_avx512_no_vzeroupper mishandles large copies
(CVE-2018-11237)
[24027] malloc: Integer overflow in realloc
[24097] Can't use 64-bit register for size_t in assembly codes for x32 (CVE-2019-6488)
[24155] x32 memcmp can treat positive length as 0 (if sign bit in RDX is set) (CVE-2019-7309)
[25204] Ignore LD_PREFER_MAP_32BIT_EXEC for SUID programs
Version 2.24
+3
View File
@@ -149,6 +149,7 @@ endif
ifneq "$(strip $(binaries-shared-tests))" ""
$(addprefix $(objpfx),$(binaries-shared-tests)): %: %.o \
$(link-extra-libs-tests) \
$(sort $(filter $(common-objpfx)lib%,$(link-libc))) \
$(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
$(+link-tests)
@@ -156,6 +157,7 @@ endif
ifneq "$(strip $(binaries-pie-tests))" ""
$(addprefix $(objpfx),$(binaries-pie-tests)): %: %.o \
$(link-extra-libs-tests) \
$(sort $(filter $(common-objpfx)lib%,$(link-libc))) \
$(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
$(+link-pie-tests)
@@ -177,6 +179,7 @@ endif
ifneq "$(strip $(binaries-static-tests))" ""
$(addprefix $(objpfx),$(binaries-static-tests)): %: %.o \
$(link-extra-libs-tests) \
$(sort $(filter $(common-objpfx)lib%,$(link-libc-static-tests))) \
$(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
$(+link-static-tests)
+4 -15
View File
@@ -29,21 +29,6 @@
#include <string.h>
#include <unistd.h>
#ifndef __attribute__
/* This feature is available in gcc versions 2.5 and later. */
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || \
defined __STRICT_ANSI__
# define __attribute__(Spec) /* empty */
# endif
/* The __-protected variants of `format' and `printf' attributes
are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) || \
defined __STRICT_ANSI__
# define __format__ format
# define __printf__ printf
# endif
#endif
#if defined (__GNU_LIBRARY__) && defined (HAVE_LINEWRAP_H)
/* line_wrap_stream is available, so use that. */
#define ARGP_FMTSTREAM_USE_LINEWRAP
@@ -111,6 +96,8 @@ struct argp_fmtstream
typedef struct argp_fmtstream *argp_fmtstream_t;
__BEGIN_DECLS
/* Return an argp_fmtstream that outputs to STREAM, and which prefixes lines
written on it with LMARGIN spaces and limits them to RMARGIN columns
total. If WMARGIN >= 0, words that extend past RMARGIN are wrapped by
@@ -297,6 +284,8 @@ __argp_fmtstream_point (argp_fmtstream_t __fs)
#endif /* __OPTIMIZE__ */
__END_DECLS
#endif /* ARGP_FMTSTREAM_USE_LINEWRAP */
#endif /* argp-fmtstream.h */
+2 -40
View File
@@ -28,48 +28,12 @@
#define __need_error_t
#include <errno.h>
#ifndef __THROW
# define __THROW
#endif
#ifndef __NTH
# define __NTH(fct) fct __THROW
#endif
#ifndef __attribute__
/* This feature is available in gcc versions 2.5 and later. */
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || \
defined __STRICT_ANSI__
# define __attribute__(Spec) /* empty */
# endif
/* The __-protected variants of `format' and `printf' attributes
are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) || \
defined __STRICT_ANSI__
# define __format__ format
# define __printf__ printf
# endif
#endif
/* GCC 2.95 and later have "__restrict"; C99 compilers have
"restrict", and "configure" may have defined "restrict". */
#ifndef __restrict
# if ! (2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__))
# if defined restrict || 199901L <= __STDC_VERSION__
# define __restrict restrict
# else
# define __restrict
# endif
# endif
#endif
#ifndef __error_t_defined
typedef int error_t;
# define __error_t_defined
#endif
#ifdef __cplusplus
extern "C" {
#endif
__BEGIN_DECLS
/* A description of a particular option. A pointer to an array of
these is passed in the OPTIONS field of an argp structure. Each option
@@ -590,8 +554,6 @@ __NTH (__option_is_end (const struct argp_option *__opt))
# endif
#endif /* Use extern inlines. */
#ifdef __cplusplus
}
#endif
__END_DECLS
#endif /* argp.h */
Vendored
+5 -3
View File
@@ -6289,12 +6289,14 @@ echo >&5 "libc_undefs='$libc_undefs'"
# symbols (resolved by the linker), so filter out unknown symbols.
# This will fail to produce the correct result if the compiler
# defaults to -fstack-protector but this produces an undefined symbol
# other than __stack_chk_fail. However, compilers like that have not
# been encountered in practice.
libc_undefs=`echo "$libc_undefs" | egrep '^(foobar|__stack_chk_fail)$'`
# other than __stack_chk_fail or __stack_chk_fail_local. However,
# compilers like that have not been encountered in practice.
libc_undefs=`echo "$libc_undefs" | \
egrep '^(foobar|__stack_chk_fail|__stack_chk_fail_local)$'`
case "$libc_undefs" in
foobar) libc_cv_predef_stack_protector=no ;;
'__stack_chk_fail
foobar'|'__stack_chk_fail_local
foobar') libc_cv_predef_stack_protector=yes ;;
*) as_fn_error $? "unexpected symbols in test: $libc_undefs" "$LINENO" 5 ;;
esac
+5 -3
View File
@@ -1626,12 +1626,14 @@ echo >&AS_MESSAGE_LOG_FD "libc_undefs='$libc_undefs'"
# symbols (resolved by the linker), so filter out unknown symbols.
# This will fail to produce the correct result if the compiler
# defaults to -fstack-protector but this produces an undefined symbol
# other than __stack_chk_fail. However, compilers like that have not
# been encountered in practice.
libc_undefs=`echo "$libc_undefs" | egrep '^(foobar|__stack_chk_fail)$'`
# other than __stack_chk_fail or __stack_chk_fail_local. However,
# compilers like that have not been encountered in practice.
libc_undefs=`echo "$libc_undefs" | \
egrep '^(foobar|__stack_chk_fail|__stack_chk_fail_local)$'`
case "$libc_undefs" in
foobar) libc_cv_predef_stack_protector=no ;;
'__stack_chk_fail
foobar'|'__stack_chk_fail_local
foobar') libc_cv_predef_stack_protector=yes ;;
*) AC_MSG_ERROR([unexpected symbols in test: $libc_undefs]) ;;
esac],
+4 -3
View File
@@ -196,13 +196,13 @@ $(conformtest-header-tests): $(objpfx)%/conform.out: \
conformtest.pl $(conformtest-headers-data)
(set -e; std_hdr=$*; std=$${std_hdr%%/*}; hdr=$${std_hdr#*/}; \
mkdir -p $(@D)/scratch; \
$(PERL) conformtest.pl --tmpdir=$(@D)/scratch --cc='$(CC)' \
$(PERL) -I. conformtest.pl --tmpdir=$(@D)/scratch --cc='$(CC)' \
--flags='$(conformtest-cc-flags)' --standard=$$std \
--headers=$$hdr > $@); \
$(evaluate-test)
$(linknamespace-symlists-tests): $(objpfx)symlist-%: list-header-symbols.pl
$(PERL) -w $< --tmpdir=$(objpfx) --cc='$(CC)' \
$(PERL) -I. -w $< --tmpdir=$(objpfx) --cc='$(CC)' \
--flags='$(conformtest-cc-flags)' --standard=$* \
--headers="$(strip $(conformtest-headers-$*))" \
> $@ 2> $@.err; \
@@ -229,10 +229,11 @@ $(linknamespace-symlist-stdlibs-tests): $(objpfx)symlist-stdlibs-%: \
$(linknamespace-header-tests): $(objpfx)%/linknamespace.out: \
linknamespace.pl \
$(linknamespace-symlists-tests) \
$(linknamespace-symlist-stdlibs-tests)
(set -e; std_hdr=$*; std=$${std_hdr%%/*}; hdr=$${std_hdr#*/}; \
mkdir -p $(@D)/scratch; \
$(PERL) -w $< --tmpdir=$(@D)/scratch --cc='$(CC)' \
$(PERL) -I. -w $< --tmpdir=$(@D)/scratch --cc='$(CC)' \
--flags='$(conformtest-cc-flags)' --standard=$$std \
--stdsyms=$(objpfx)symlist-$$std --header=$$hdr \
--libsyms=$(objpfx)symlist-stdlibs-$$std \
+13 -2
View File
@@ -149,7 +149,8 @@ tests += loadtest restest1 preloadtest loadfail multiload origtest resolvfail \
tst-nodelete) \
tst-initorder tst-initorder2 tst-relsort1 tst-null-argv \
tst-ptrguard1 tst-tlsalign tst-tlsalign-extern tst-nodelete-opened \
tst-nodelete2 tst-audit11 tst-audit12 tst-dlsym-error
tst-nodelete2 tst-audit11 tst-audit12 tst-dlsym-error \
tst-nodelete-dlclose
# reldep9
ifeq ($(build-hardcoded-path-in-tests),yes)
tests += tst-dlopen-aout
@@ -223,7 +224,8 @@ modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \
tst-array5dep tst-null-argv-lib \
tst-tlsalign-lib tst-nodelete-opened-lib tst-nodelete2mod \
tst-audit11mod1 tst-audit11mod2 tst-auditmod11 \
tst-audit12mod1 tst-audit12mod2 tst-audit12mod3 tst-auditmod12
tst-audit12mod1 tst-audit12mod2 tst-audit12mod3 tst-auditmod12 \
tst-nodelete-dlclose-dso tst-nodelete-dlclose-plugin
ifeq (yes,$(have-mtls-dialect-gnu2))
tests += tst-gnu2-tls1
modules-names += tst-gnu2-tls1mod
@@ -1267,3 +1269,12 @@ $(objpfx)tst-ldconfig-X.out : tst-ldconfig-X.sh $(objpfx)ldconfig
$(evaluate-test)
$(objpfx)tst-dlsym-error: $(libdl)
# The application depends on the DSO, and the DSO loads the plugin.
# The plugin also depends on the DSO. This creates the circular
# dependency via dlopen that we're testing to make sure works.
$(objpfx)tst-nodelete-dlclose-dso.so: $(libdl)
$(objpfx)tst-nodelete-dlclose-plugin.so: $(objpfx)tst-nodelete-dlclose-dso.so
$(objpfx)tst-nodelete-dlclose: $(objpfx)tst-nodelete-dlclose-dso.so
$(objpfx)tst-nodelete-dlclose.out: $(objpfx)tst-nodelete-dlclose-dso.so \
$(objpfx)tst-nodelete-dlclose-plugin.so
+24 -6
View File
@@ -805,19 +805,37 @@ _dl_close (void *_map)
{
struct link_map *map = _map;
/* First see whether we can remove the object at all. */
/* We must take the lock to examine the contents of map and avoid
concurrent dlopens. */
__rtld_lock_lock_recursive (GL(dl_load_lock));
/* At this point we are guaranteed nobody else is touching the list of
loaded maps, but a concurrent dlclose might have freed our map
before we took the lock. There is no way to detect this (see below)
so we proceed assuming this isn't the case. First see whether we
can remove the object at all. */
if (__glibc_unlikely (map->l_flags_1 & DF_1_NODELETE))
{
assert (map->l_init_called);
/* Nope. Do nothing. */
__rtld_lock_unlock_recursive (GL(dl_load_lock));
return;
}
/* At present this is an unreliable check except in the case where the
caller has recursively called dlclose and we are sure the link map
has not been freed. In a non-recursive dlclose the map itself
might have been freed and this access is potentially a data race
with whatever other use this memory might have now, or worse we
might silently corrupt memory if it looks enough like a link map.
POSIX has language in dlclose that appears to guarantee that this
should be a detectable case and given that dlclose should be threadsafe
we need this to be a reliable detection.
This is bug 20990. */
if (__builtin_expect (map->l_direct_opencount, 1) == 0)
GLRO(dl_signal_error) (0, map->l_name, NULL, N_("shared object not open"));
/* Acquire the lock. */
__rtld_lock_lock_recursive (GL(dl_load_lock));
{
__rtld_lock_unlock_recursive (GL(dl_load_lock));
_dl_signal_error (0, map->l_name, NULL, N_("shared object not open"));
}
_dl_close_worker (map, false);
+47 -53
View File
@@ -37,6 +37,7 @@
#include <sysdep.h>
#include <stap-probe.h>
#include <libc-internal.h>
#include <array_length.h>
#include <dl-dst.h>
#include <dl-load.h>
@@ -103,7 +104,9 @@ static size_t ncapstr attribute_relro;
static size_t max_capstrlen attribute_relro;
/* Get the generated information about the trusted directories. */
/* Get the generated information about the trusted directories. Use
an array of concatenated strings to avoid relocations. See
gen-trusted-dirs.awk. */
#include "trusted-dirs.h"
static const char system_dirs[] = SYSTEM_DIRS;
@@ -111,9 +114,7 @@ static const size_t system_dirs_len[] =
{
SYSTEM_DIRS_LEN
};
#define nsystem_dirs_len \
(sizeof (system_dirs_len) / sizeof (system_dirs_len[0]))
#define nsystem_dirs_len array_length (system_dirs_len)
static bool
is_trusted_path (const char *path, size_t len)
@@ -433,32 +434,41 @@ fillin_rpath (char *rpath, struct r_search_path_elem **result, const char *sep,
{
char *cp;
size_t nelems = 0;
char *to_free;
while ((cp = __strsep (&rpath, sep)) != NULL)
{
struct r_search_path_elem *dirp;
char *to_free = NULL;
size_t len = 0;
to_free = cp = expand_dynamic_string_token (l, cp, 1);
size_t len = strlen (cp);
/* `strsep' can pass an empty string. This has to be
interpreted as `use the current directory'. */
if (len == 0)
/* `strsep' can pass an empty string. */
if (*cp != '\0')
{
static const char curwd[] = "./";
cp = (char *) curwd;
to_free = cp = expand_dynamic_string_token (l, cp, 1);
/* expand_dynamic_string_token can return NULL in case of empty
path or memory allocation failure. */
if (cp == NULL)
continue;
/* Compute the length after dynamic string token expansion and
ignore empty paths. */
len = strlen (cp);
if (len == 0)
{
free (to_free);
continue;
}
/* Remove trailing slashes (except for "/"). */
while (len > 1 && cp[len - 1] == '/')
--len;
/* Now add one if there is none so far. */
if (len > 0 && cp[len - 1] != '/')
cp[len++] = '/';
}
/* Remove trailing slashes (except for "/"). */
while (len > 1 && cp[len - 1] == '/')
--len;
/* Now add one if there is none so far. */
if (len > 0 && cp[len - 1] != '/')
cp[len++] = '/';
/* Make sure we don't use untrusted directories if we run SUID. */
if (__glibc_unlikely (check_trusted) && !is_trusted_path (cp, len))
{
@@ -621,6 +631,14 @@ decompose_rpath (struct r_search_path_struct *sps,
necessary. */
free (copy);
/* There is no path after expansion. */
if (result[0] == NULL)
{
free (result);
sps->dirs = (struct r_search_path_elem **) -1;
return false;
}
sps->dirs = result;
/* The caller will change this value if we haven't used a real malloc. */
sps->malloced = 1;
@@ -688,9 +706,8 @@ _dl_init_paths (const char *llp)
+ ncapstr * sizeof (enum r_dir_status))
/ sizeof (struct r_search_path_elem));
rtld_search_dirs.dirs[0] = (struct r_search_path_elem *)
malloc ((sizeof (system_dirs) / sizeof (system_dirs[0]))
* round_size * sizeof (struct r_search_path_elem));
rtld_search_dirs.dirs[0] = malloc (nsystem_dirs_len * round_size
* sizeof (*rtld_search_dirs.dirs[0]));
if (rtld_search_dirs.dirs[0] == NULL)
{
errstring = N_("cannot create cache for search path");
@@ -776,37 +793,14 @@ _dl_init_paths (const char *llp)
if (llp != NULL && *llp != '\0')
{
size_t nllp;
const char *cp = llp;
char *llp_tmp;
#ifdef SHARED
/* Expand DSTs. */
size_t cnt = DL_DST_COUNT (llp, 1);
if (__glibc_likely (cnt == 0))
llp_tmp = strdupa (llp);
else
{
/* Determine the length of the substituted string. */
size_t total = DL_DST_REQUIRED (l, llp, strlen (llp), cnt);
/* Allocate the necessary memory. */
llp_tmp = (char *) alloca (total + 1);
llp_tmp = _dl_dst_substitute (l, llp, llp_tmp, 1);
}
#else
llp_tmp = strdupa (llp);
#endif
char *llp_tmp = strdupa (llp);
/* Decompose the LD_LIBRARY_PATH contents. First determine how many
elements it has. */
nllp = 1;
while (*cp)
{
if (*cp == ':' || *cp == ';')
++nllp;
++cp;
}
size_t nllp = 1;
for (const char *cp = llp_tmp; *cp != '\0'; ++cp)
if (*cp == ':' || *cp == ';')
++nllp;
env_path_list.dirs = (struct r_search_path_elem **)
malloc ((nllp + 1) * sizeof (struct r_search_path_elem *));
+165 -33
View File
@@ -99,14 +99,121 @@ uintptr_t __pointer_chk_guard_local
strong_alias (__pointer_chk_guard_local, __pointer_chk_guard)
#endif
/* Length limits for names and paths, to protect the dynamic linker,
particularly when __libc_enable_secure is active. */
#ifdef NAME_MAX
# define SECURE_NAME_LIMIT NAME_MAX
#else
# define SECURE_NAME_LIMIT 255
#endif
#ifdef PATH_MAX
# define SECURE_PATH_LIMIT PATH_MAX
#else
# define SECURE_PATH_LIMIT 1024
#endif
/* List of auditing DSOs. */
/* Check that AT_SECURE=0, or that the passed name does not contain
directories and is not overly long. Reject empty names
unconditionally. */
static bool
dso_name_valid_for_suid (const char *p)
{
if (__glibc_unlikely (__libc_enable_secure))
{
/* Ignore pathnames with directories for AT_SECURE=1
programs, and also skip overlong names. */
size_t len = strlen (p);
if (len >= SECURE_NAME_LIMIT || memchr (p, '/', len) != NULL)
return false;
}
return *p != '\0';
}
/* LD_AUDIT variable contents. Must be processed before the
audit_list below. */
const char *audit_list_string;
/* Cyclic list of auditing DSOs. audit_list->next is the first
element. */
static struct audit_list
{
const char *name;
struct audit_list *next;
} *audit_list;
/* Iterator for audit_list_string followed by audit_list. */
struct audit_list_iter
{
/* Tail of audit_list_string still needing processing, or NULL. */
const char *audit_list_tail;
/* The list element returned in the previous iteration. NULL before
the first element. */
struct audit_list *previous;
/* Scratch buffer for returning a name which is part of
audit_list_string. */
char fname[SECURE_NAME_LIMIT];
};
/* Initialize an audit list iterator. */
static void
audit_list_iter_init (struct audit_list_iter *iter)
{
iter->audit_list_tail = audit_list_string;
iter->previous = NULL;
}
/* Iterate through both audit_list_string and audit_list. */
static const char *
audit_list_iter_next (struct audit_list_iter *iter)
{
if (iter->audit_list_tail != NULL)
{
/* First iterate over audit_list_string. */
while (*iter->audit_list_tail != '\0')
{
/* Split audit list at colon. */
size_t len = strcspn (iter->audit_list_tail, ":");
if (len > 0 && len < sizeof (iter->fname))
{
memcpy (iter->fname, iter->audit_list_tail, len);
iter->fname[len] = '\0';
}
else
/* Do not return this name to the caller. */
iter->fname[0] = '\0';
/* Skip over the substring and the following delimiter. */
iter->audit_list_tail += len;
if (*iter->audit_list_tail == ':')
++iter->audit_list_tail;
/* If the name is valid, return it. */
if (dso_name_valid_for_suid (iter->fname))
return iter->fname;
/* Otherwise, wrap around and try the next name. */
}
/* Fall through to the procesing of audit_list. */
}
if (iter->previous == NULL)
{
if (audit_list == NULL)
/* No pre-parsed audit list. */
return NULL;
/* Start of audit list. The first list element is at
audit_list->next (cyclic list). */
iter->previous = audit_list->next;
return iter->previous->name;
}
if (iter->previous == audit_list)
/* Cyclic list wrap-around. */
return NULL;
iter->previous = iter->previous->next;
return iter->previous->name;
}
#ifndef HAVE_INLINED_SYSCALLS
/* Set nonzero during loading and initialization of executable and
libraries, cleared before the executable's entry point runs. This
@@ -730,6 +837,42 @@ static const char *preloadlist attribute_relro;
/* Nonzero if information about versions has to be printed. */
static int version_info attribute_relro;
/* The LD_PRELOAD environment variable gives list of libraries
separated by white space or colons that are loaded before the
executable's dependencies and prepended to the global scope list.
(If the binary is running setuid all elements containing a '/' are
ignored since it is insecure.) Return the number of preloads
performed. */
unsigned int
handle_ld_preload (const char *preloadlist, struct link_map *main_map)
{
unsigned int npreloads = 0;
const char *p = preloadlist;
char fname[SECURE_PATH_LIMIT];
while (*p != '\0')
{
/* Split preload list at space/colon. */
size_t len = strcspn (p, " :");
if (len > 0 && len < sizeof (fname))
{
memcpy (fname, p, len);
fname[len] = '\0';
}
else
fname[0] = '\0';
/* Skip over the substring and the following delimiter. */
p += len;
if (*p != '\0')
++p;
if (dso_name_valid_for_suid (fname))
npreloads += do_preload (fname, main_map, "LD_PRELOAD");
}
return npreloads;
}
static void
dl_main (const ElfW(Phdr) *phdr,
ElfW(Word) phnum,
@@ -1257,11 +1400,13 @@ of this helper program; chances are you did not intend to run this program.\n\
GL(dl_rtld_map).l_tls_modid = _dl_next_tls_modid ();
/* If we have auditing DSOs to load, do it now. */
if (__glibc_unlikely (audit_list != NULL))
bool need_security_init = true;
if (__glibc_unlikely (audit_list != NULL)
|| __glibc_unlikely (audit_list_string != NULL))
{
/* Iterate over all entries in the list. The order is important. */
struct audit_ifaces *last_audit = NULL;
struct audit_list *al = audit_list->next;
struct audit_list_iter al_iter;
audit_list_iter_init (&al_iter);
/* Since we start using the auditing DSOs right away we need to
initialize the data structures now. */
@@ -1272,9 +1417,14 @@ of this helper program; chances are you did not intend to run this program.\n\
use different values (especially the pointer guard) and will
fail later on. */
security_init ();
need_security_init = false;
do
while (true)
{
const char *name = audit_list_iter_next (&al_iter);
if (name == NULL)
break;
int tls_idx = GL(dl_tls_max_dtv_idx);
/* Now it is time to determine the layout of the static TLS
@@ -1283,7 +1433,7 @@ of this helper program; chances are you did not intend to run this program.\n\
no DF_STATIC_TLS bit is set. The reason is that we know
glibc will use the static model. */
struct dlmopen_args dlmargs;
dlmargs.fname = al->name;
dlmargs.fname = name;
dlmargs.map = NULL;
const char *objname;
@@ -1296,7 +1446,7 @@ of this helper program; chances are you did not intend to run this program.\n\
not_loaded:
_dl_error_printf ("\
ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
al->name, err_str);
name, err_str);
if (malloced)
free ((char *) err_str);
}
@@ -1400,10 +1550,7 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
goto not_loaded;
}
}
al = al->next;
}
while (al != audit_list->next);
/* If we have any auditing modules, announce that we already
have two objects loaded. */
@@ -1481,23 +1628,8 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
if (__glibc_unlikely (preloadlist != NULL))
{
/* The LD_PRELOAD environment variable gives list of libraries
separated by white space or colons that are loaded before the
executable's dependencies and prepended to the global scope
list. If the binary is running setuid all elements
containing a '/' are ignored since it is insecure. */
char *list = strdupa (preloadlist);
char *p;
HP_TIMING_NOW (start);
/* Prevent optimizing strsep. Speed is not important here. */
while ((p = (strsep) (&list, " :")) != NULL)
if (p[0] != '\0'
&& (__builtin_expect (! __libc_enable_secure, 1)
|| strchr (p, '/') == NULL))
npreloads += do_preload (p, main_map, "LD_PRELOAD");
npreloads += handle_ld_preload (preloadlist, main_map);
HP_TIMING_NOW (stop);
HP_TIMING_DIFF (diff, start, stop);
HP_TIMING_ACCUM_NT (load_time, diff);
@@ -1682,7 +1814,7 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
if (tcbp == NULL)
tcbp = init_tls ();
if (__glibc_likely (audit_list == NULL))
if (__glibc_likely (need_security_init))
/* Initialize security features. But only if we have not done it
earlier. */
security_init ();
@@ -2313,9 +2445,7 @@ process_dl_audit (char *str)
char *p;
while ((p = (strsep) (&str, ":")) != NULL)
if (p[0] != '\0'
&& (__builtin_expect (! __libc_enable_secure, 1)
|| strchr (p, '/') == NULL))
if (dso_name_valid_for_suid (p))
{
/* This is using the local malloc, not the system malloc. The
memory can never be freed. */
@@ -2379,7 +2509,7 @@ process_envvars (enum mode *modep)
break;
}
if (memcmp (envline, "AUDIT", 5) == 0)
process_dl_audit (&envline[6]);
audit_list_string = &envline[6];
break;
case 7:
@@ -2423,7 +2553,8 @@ process_envvars (enum mode *modep)
case 10:
/* Mask for the important hardware capabilities. */
if (memcmp (envline, "HWCAP_MASK", 10) == 0)
if (!__libc_enable_secure
&& memcmp (envline, "HWCAP_MASK", 10) == 0)
GLRO(dl_hwcap_mask) = __strtoul_internal (&envline[11], NULL,
0, 0);
break;
@@ -2437,7 +2568,8 @@ process_envvars (enum mode *modep)
case 12:
/* The library search path. */
if (memcmp (envline, "LIBRARY_PATH", 12) == 0)
if (!__libc_enable_secure
&& memcmp (envline, "LIBRARY_PATH", 12) == 0)
{
library_path = &envline[13];
break;
+90
View File
@@ -0,0 +1,90 @@
/* Bug 11941: Improper assert map->l_init_called in dlclose.
Copyright (C) 2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
/* This is the primary DSO that is loaded by the appliation. This DSO
then loads a plugin with RTLD_NODELETE. This plugin depends on this
DSO. This dependency chain means that at application shutdown the
plugin will be destructed first. Thus by the time this DSO is
destructed we will be calling dlclose on an object that has already
been destructed. It is allowed to call dlclose in this way and
should not assert. */
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
/* Plugin to load. */
static void *plugin_lib = NULL;
/* Plugin function. */
static void (*plugin_func) (void);
#define LIB_PLUGIN "tst-nodelete-dlclose-plugin.so"
/* This function is never called but the plugin references it.
We do this to avoid any future --as-needed from removing the
plugin's DT_NEEDED on this DSO (required for the test). */
void
primary_reference (void)
{
printf ("INFO: Called primary_reference function.\n");
}
void
primary (void)
{
char *error;
plugin_lib = dlopen (LIB_PLUGIN, RTLD_NOW | RTLD_LOCAL | RTLD_NODELETE);
if (plugin_lib == NULL)
{
printf ("ERROR: Unable to load plugin library.\n");
exit (EXIT_FAILURE);
}
dlerror ();
plugin_func = (void (*) (void)) dlsym (plugin_lib, "plugin_func");
error = dlerror ();
if (error != NULL)
{
printf ("ERROR: Unable to find symbol with error \"%s\".",
error);
exit (EXIT_FAILURE);
}
return;
}
__attribute__ ((destructor))
static void
primary_dtor (void)
{
int ret;
printf ("INFO: Calling primary destructor.\n");
/* The destructor runs in the test driver also, which
hasn't called primary, in that case do nothing. */
if (plugin_lib == NULL)
return;
ret = dlclose (plugin_lib);
if (ret != 0)
{
printf ("ERROR: Calling dlclose failed with \"%s\"\n",
dlerror ());
exit (EXIT_FAILURE);
}
}
+40
View File
@@ -0,0 +1,40 @@
/* Bug 11941: Improper assert map->l_init_called in dlclose.
Copyright (C) 2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
/* This DSO simulates a plugin with a dependency on the
primary DSO loaded by the appliation. */
#include <stdio.h>
extern void primary_reference (void);
void
plugin_func (void)
{
printf ("INFO: Calling plugin function.\n");
/* Need a reference to the DSO to ensure that a potential --as-needed
doesn't remove the DT_NEEDED entry which we rely upon to ensure
destruction ordering. */
primary_reference ();
}
__attribute__ ((destructor))
static void
plugin_dtor (void)
{
printf ("INFO: Calling plugin destructor.\n");
}
+36
View File
@@ -0,0 +1,36 @@
/* Bug 11941: Improper assert map->l_init_called in dlclose.
Copyright (C) 2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
/* This simulates an application using the primary DSO which loads the
plugin DSO. */
#include <stdio.h>
#include <stdlib.h>
extern void primary (void);
static int
do_test (void)
{
printf ("INFO: Starting application.\n");
primary ();
printf ("INFO: Exiting application.\n");
return 0;
}
#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"
+5
View File
@@ -5,6 +5,9 @@
# The variable $($(lib)-routines) defines the list of modules
# to be included in that library. A sysdep Makefile can add to
# $(lib)-sysdep_routines to include additional modules.
#
# Libraries listed in $(extra-libs-noinstall) are built, but not
# installed.
lib := $(firstword $(extra-libs-left))
extra-libs-left := $(filter-out $(lib),$(extra-libs-left))
@@ -28,7 +31,9 @@ extra-objs := $(extra-objs)
all-$(lib)-routines := $($(lib)-routines) $($(lib)-sysdep_routines)
# Add each flavor of library to the lists of things to build and install.
ifeq (,$(filter $(lib), $(extra-libs-noinstall)))
install-lib += $(foreach o,$(object-suffixes-$(lib)),$(lib:lib%=$(libtype$o)))
endif
extra-objs += $(foreach o,$(filter-out .os .oS,$(object-suffixes-$(lib))),\
$(patsubst %,%$o,$(filter-out \
$($(lib)-shared-only-routines),\
+17 -1
View File
@@ -85,6 +85,14 @@ __copy_grp (const struct group srcgrp, const size_t buflen,
}
members[i] = NULL;
/* Align for pointers. We can't simply align C because we need to
align destbuf[c]. */
if ((((uintptr_t)destbuf + c) & (__alignof__(char **) - 1)) != 0)
{
uintptr_t mis_align = ((uintptr_t)destbuf + c) & (__alignof__(char **) - 1);
c += __alignof__(char **) - mis_align;
}
/* Copy the pointers from the members array into the buffer and assign them
to the gr_mem member of destgrp. */
destgrp->gr_mem = (char **) &destbuf[c];
@@ -129,7 +137,7 @@ __merge_grp (struct group *savedgrp, char *savedbuf, char *savedend,
/* Get the count of group members from the last sizeof (size_t) bytes in the
mergegrp buffer. */
savedmemcount = (size_t) *(savedend - sizeof (size_t));
savedmemcount = *(size_t *) (savedend - sizeof (size_t));
/* Get the count of new members to add. */
for (memcount = 0; mergegrp->gr_mem[memcount]; memcount++)
@@ -168,6 +176,14 @@ __merge_grp (struct group *savedgrp, char *savedbuf, char *savedend,
/* Add the NULL-terminator. */
members[savedmemcount + memcount] = NULL;
/* Align for pointers. We can't simply align C because we need to
align savedbuf[c]. */
if ((((uintptr_t)savedbuf + c) & (__alignof__(char **) - 1)) != 0)
{
uintptr_t mis_align = ((uintptr_t)savedbuf + c) & (__alignof__(char **) - 1);
c += __alignof__(char **) - mis_align;
}
/* Copy the member array back into the buffer after the member list and free
the member array. */
savedgrp->gr_mem = (char **) &savedbuf[c];
+1 -1
View File
@@ -139,7 +139,7 @@ typedef struct __gconv_info
{
size_t __nsteps;
struct __gconv_step *__steps;
__extension__ struct __gconv_step_data __data __flexarr;
__extension__ struct __gconv_step_data __data[0];
} *__gconv_t;
/* Transliteration using the locale's data. */
+3 -3
View File
@@ -1,8 +1,8 @@
#ifndef _ARPA_NAMESER_COMPAT_
#include <resolv/arpa/nameser_compat.h>
/* Picksome unused number to represent lookups of IPv4 and IPv6 (i.e.,
T_A and T_AAAA). */
#define T_UNSPEC 62321
/* The number is outside the 16-bit RR type range and is used
internally by the implementation. */
#define T_QUERY_A_AND_AAAA 439963904
#endif
+36
View File
@@ -0,0 +1,36 @@
/* The array_length and array_end macros.
Copyright (C) 2017 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#ifndef _ARRAY_LENGTH_H
#define _ARRAY_LENGTH_H
/* array_length (VAR) is the number of elements in the array VAR. VAR
must evaluate to an array, not a pointer. */
#define array_length(var) \
__extension__ ({ \
_Static_assert (!__builtin_types_compatible_p \
(__typeof (var), __typeof (&(var)[0])), \
"argument must be an array"); \
sizeof (var) / sizeof ((var)[0]); \
})
/* array_end (VAR) is a pointer one past the end of the array VAR.
VAR must evaluate to an array, not a pointer. */
#define array_end(var) (&(var)[array_length (var)])
#endif /* _ARRAY_LENGTH_H */
+1 -1
View File
@@ -193,7 +193,7 @@ FTS *__REDIRECT (fts_open, (char * const *, int,
int (*)(const FTSENT **, const FTSENT **)),
fts64_open);
FTSENT *__REDIRECT (fts_read, (FTS *), fts64_read);
int __REDIRECT (fts_set, (FTS *, FTSENT *, int), fts64_set) __THROW;
int __REDIRECT_NTH (fts_set, (FTS *, FTSENT *, int), fts64_set);
# else
# define fts_children fts64_children
# define fts_close fts64_close
+5
View File
@@ -87,6 +87,11 @@ _IO_check_libio (void)
stdout->_vtable_offset = stderr->_vtable_offset =
((int) sizeof (struct _IO_FILE)
- (int) sizeof (struct _IO_FILE_complete));
if (_IO_stdin_.vtable != &_IO_old_file_jumps
|| _IO_stdout_.vtable != &_IO_old_file_jumps
|| _IO_stderr_.vtable != &_IO_old_file_jumps)
IO_set_accept_foreign_vtables (&_IO_vtable_check);
}
}
+16
View File
@@ -70,3 +70,19 @@ _IO_vtable_check (void)
__libc_fatal ("Fatal error: glibc detected an invalid stdio handle\n");
}
/* Some variants of libstdc++ interpose _IO_2_1_stdin_ etc. and
install their own vtables directly, without calling _IO_init or
other functions. Detect this by looking at the vtables values
during startup, and disable vtable validation in this case. */
#ifdef SHARED
__attribute__ ((constructor))
static void
check_stdfiles_vtables (void)
{
if (_IO_2_1_stdin_.vtable != &_IO_file_jumps
|| _IO_2_1_stdout_.vtable != &_IO_file_jumps
|| _IO_2_1_stderr_.vtable != &_IO_file_jumps)
IO_set_accept_foreign_vtables (&_IO_vtable_check);
}
#endif
+14
View File
@@ -1,3 +1,17 @@
2017-06-11 Santhosh Thottingal <santhosh.thottingal@gmail.com>
[BZ #19922]
* locales/iso14651_t1_common: Add collation rules for U+07DA to U+07DF.
[BZ #19919]
* locales/iso14651_t1_common: Correct collation of U+0D36 and U+0D37.
2016-12-30 Mike Frysinger <vapier@gentoo.org>
[BZ #20974]
* localedata/bs_BA (LC_MESSAGES): Delete "*." from the end of
yesexpr and noexpr.
2016-07-07 Aurelien Jarno <aurelien@aurel32.net>
* locales/de_LI (postal_fmt): Fix indentation.
+2 -2
View File
@@ -148,8 +148,8 @@ copy "en_DK"
END LC_CTYPE
LC_MESSAGES
yesexpr "<U005E><U005B><U002B><U0031><U0064><U0044><U0079><U0059><U005D><U002A><U002E>"
noexpr "<U005E><U005B><U002D><U0030><U006E><U004E><U005D><U002A><U002E>"
yesexpr "<U005E><U005B><U002B><U0031><U0064><U0044><U0079><U0059><U005D>"
noexpr "<U005E><U005B><U002D><U0030><U006E><U004E><U005D>"
yesstr "<U0064><U0061>"
nostr "<U006E><U0065>"
END LC_MESSAGES
+22 -4
View File
@@ -1042,9 +1042,9 @@ collating-element <ml-bh> from "<U0D2D><U0D4D>"
collating-element <ml-m> from "<U0D2E><U0D4D>"
collating-element <ml-y> from "<U0D2F><U0D4D>"
collating-element <ml-v> from "<U0D35><U0D4D>"
collating-element <ml-s> from "<U0D38><U0D4D>"
collating-element <ml-ss> from "<U0D36><U0D4D>"
collating-element <ml-sh> from "<U0D37><U0D4D>"
collating-element <ml-s> from "<U0D38><U0D4D>"
collating-element <ml-h> from "<U0D39><U0D4D>"
collating-element <ml-zh> from "<U0D34><U0D4D>"
collating-element <ml-rr> from "<U0D31><U0D4D>"
@@ -1103,8 +1103,8 @@ collating-symbol <ml-rra>
collating-symbol <ml-la>
collating-symbol <ml-lla>
collating-symbol <ml-va>
collating-symbol <ml-sha>
collating-symbol <ml-ssa>
collating-symbol <ml-sha>
collating-symbol <ml-sa>
collating-symbol <ml-ha>
collating-symbol <ml-avagrah>
@@ -1126,6 +1126,12 @@ collating-symbol <mlvs-o>
collating-symbol <mlvs-au>
collating-symbol <ml-visarga>
collating-symbol <ml-virama>
collating-symbol <ml-atomic-chillu-k>
collating-symbol <ml-atomic-chillu-n>
collating-symbol <ml-atomic-chillu-nn>
collating-symbol <ml-atomic-chillu-l>
collating-symbol <ml-atomic-chillu-ll>
collating-symbol <ml-atomic-chillu-r>
#
# <BENGALI>
#
@@ -4552,6 +4558,12 @@ collating-symbol <TIB-subA>
<mlvs-o>
<mlvs-au>
<ml-visarga>
<ml-atomic-chillu-k>
<ml-atomic-chillu-n>
<ml-atomic-chillu-nn>
<ml-atomic-chillu-l>
<ml-atomic-chillu-ll>
<ml-atomic-chillu-r>
#
# <BENGALI>
#
@@ -7252,6 +7264,7 @@ order_start <MALAYALAM>;forward;forward;forward;forward,position
<U0D13> <mlvw-o>;<BAS>;<MIN>;IGNORE
<U0D14> <mlvw-au>;<BAS>;<MIN>;IGNORE
<ml-chillu-k> "<ml-ka><ml-virama>";<BAS>;<MIN>;IGNORE
<U0D7F> "<ml-ka><ml-virama>";<ml-atomic-chillu-k>;<MIN>;IGNORE
<U0D15> "<ml-ka><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE
<ml-kh> "<ml-kha><ml-virama>";<BAS>;<MIN>;IGNORE
<U0D16> "<ml-kha><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE
@@ -7280,6 +7293,7 @@ order_start <MALAYALAM>;forward;forward;forward;forward,position
<ml-dh> "<ml-dha><ml-virama>";<BAS>;<MIN>;IGNORE
<U0D22> "<ml-dha><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE
<ml-chillu-nn> "<ml-nna><ml-virama>";<BAS>;<MIN>;IGNORE # ണ്‍ = ണ + ് + zwj
<U0D7A> "<ml-nna><ml-virama>";<ml-atomic-chillu-nn>;<MIN>;IGNORE
<U0D23> "<ml-nna><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE # ണ = ണ + ് + അ
<ml-th> "<ml-tha><ml-virama>";<BAS>;<MIN>;IGNORE
<U0D24> "<ml-tha><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE
@@ -7290,6 +7304,7 @@ order_start <MALAYALAM>;forward;forward;forward;forward,position
<ml-ddh> "<ml-ddha><ml-virama>";<BAS>;<MIN>;IGNORE
<U0D27> "<ml-ddha><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE
<ml-chillu-n> "<ml-na><ml-virama>";<BAS>;<MIN>;IGNORE # ന്‍= ന + ് + zwj
<U0D7B> "<ml-na><ml-virama>";<ml-atomic-chillu-n>;<MIN>;IGNORE
<U0D28> "<ml-na><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE #ന = ന + ് + അ
<ml-p> "<ml-pa><ml-virama>";<BAS>;<MIN>;IGNORE
<U0D2A> "<ml-pa><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE
@@ -7305,20 +7320,23 @@ order_start <MALAYALAM>;forward;forward;forward;forward,position
<ml-y> "<ml-ya><ml-virama>";<BAS>;<MIN>;IGNORE
<U0D2F> "<ml-ya><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE
<ml-chillu-r> "<ml-ra><ml-virama>";<BAS>;<MIN>;IGNORE # ര = ര + ് + zwj
<U0D7C> "<ml-ra><ml-virama>";<ml-atomic-chillu-r>;<MIN>;IGNORE
<U0D30> "<ml-ra><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE # ര = ര + ് + അ
<ml-chillu-l> <ml-la>;<BAS>;<MIN>;IGNORE # ല്‍ = ല + ് + zwj
<U0D7D> "<ml-la><ml-virama>";<ml-atomic-chillu-l>;<MIN>;IGNORE
<U0D32> "<ml-la><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE # ല = ല + ് + അ
<ml-v> "<ml-va><ml-virama>";<BAS>;<MIN>;IGNORE
<U0D35> "<ml-va><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE
<ml-ss> "<ml-ssa><ml-virama>";<BAS>;<MIN>;IGNORE
<U0D37> "<ml-ssa><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE
<U0D36> "<ml-ssa><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE
<ml-sh> "<ml-sha><ml-virama>";<BAS>;<MIN>;IGNORE
<U0D36> "<ml-sha><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE
<U0D37> "<ml-sha><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE
<ml-s> "<ml-sa><ml-virama>";<BAS>;<MIN>;IGNORE
<U0D38> "<ml-sa><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE
<ml-h> "<ml-ha><ml-virama>";<BAS>;<MIN>;IGNORE
<U0D39> "<ml-ha><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE
<ml-chillu-ll> "<ml-lla><ml-virama>";<BAS>;<MIN>;IGNORE # ള്‍ = ള + ് + zwj
<U0D7E> "<ml-lla><ml-virama>";<ml-atomic-chillu-ll>;<MIN>;IGNORE
<U0D33> "<ml-lla><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE # ള = ള + ് + അ
<ml-zh> "<ml-zha><ml-virama>";<BAS>;<MIN>;IGNORE
<U0D34> "<ml-zha><ml-virama><mlvw-shorta>";<BAS>;<MIN>;IGNORE
+36 -5
View File
@@ -702,8 +702,7 @@ _int_new_arena (size_t size)
}
/* Remove an arena from free_list. The arena may be in use because it
was attached concurrently to a thread by reused_arena below. */
/* Remove an arena from free_list. */
static mstate
get_free_list (void)
{
@@ -718,7 +717,8 @@ get_free_list (void)
free_list = result->next_free;
/* The arena will be attached to this thread. */
++result->attached_threads;
assert (result->attached_threads == 0);
result->attached_threads = 1;
detach_arena (replaced_arena);
}
@@ -735,6 +735,26 @@ get_free_list (void)
return result;
}
/* Remove the arena from the free list (if it is present).
free_list_lock must have been acquired by the caller. */
static void
remove_from_free_list (mstate arena)
{
mstate *previous = &free_list;
for (mstate p = free_list; p != NULL; p = p->next_free)
{
assert (p->attached_threads == 0);
if (p == arena)
{
/* Remove the requested arena from the list. */
*previous = p->next_free;
break;
}
else
previous = &p->next_free;
}
}
/* Lock and return an arena that can be reused for memory allocation.
Avoid AVOID_ARENA as we have already failed to allocate memory in
it and it is currently locked. */
@@ -782,14 +802,25 @@ reused_arena (mstate avoid_arena)
(void) mutex_lock (&result->mutex);
out:
/* Attach the arena to the current thread. Note that we may have
selected an arena which was on free_list. */
/* Attach the arena to the current thread. */
{
/* Update the arena thread attachment counters. */
mstate replaced_arena = thread_arena;
(void) mutex_lock (&free_list_lock);
detach_arena (replaced_arena);
/* We may have picked up an arena on the free list. We need to
preserve the invariant that no arena on the free list has a
positive attached_threads counter (otherwise,
arena_thread_freeres cannot use the counter to determine if the
arena needs to be put on the free list). We unconditionally
remove the selected arena from the free list. The caller of
reused_arena checked the free list and observed it to be empty,
so the list is very short. */
remove_from_free_list (result);
++result->attached_threads;
(void) mutex_unlock (&free_list_lock);
}
+1 -42
View File
@@ -4271,11 +4271,6 @@ _int_realloc(mstate av, mchunkptr oldp, INTERNAL_SIZE_T oldsize,
mchunkptr bck; /* misc temp for linking */
mchunkptr fwd; /* misc temp for linking */
unsigned long copysize; /* bytes to copy */
unsigned int ncopies; /* INTERNAL_SIZE_T words to copy */
INTERNAL_SIZE_T* s; /* copy source */
INTERNAL_SIZE_T* d; /* copy destination */
const char *errstr = NULL;
/* oldmem size */
@@ -4353,43 +4348,7 @@ _int_realloc(mstate av, mchunkptr oldp, INTERNAL_SIZE_T oldsize,
}
else
{
/*
Unroll copy of <= 36 bytes (72 if 8byte sizes)
We know that contents have an odd number of
INTERNAL_SIZE_T-sized words; minimally 3.
*/
copysize = oldsize - SIZE_SZ;
s = (INTERNAL_SIZE_T *) (chunk2mem (oldp));
d = (INTERNAL_SIZE_T *) (newmem);
ncopies = copysize / sizeof (INTERNAL_SIZE_T);
assert (ncopies >= 3);
if (ncopies > 9)
memcpy (d, s, copysize);
else
{
*(d + 0) = *(s + 0);
*(d + 1) = *(s + 1);
*(d + 2) = *(s + 2);
if (ncopies > 4)
{
*(d + 3) = *(s + 3);
*(d + 4) = *(s + 4);
if (ncopies > 6)
{
*(d + 5) = *(s + 5);
*(d + 6) = *(s + 6);
if (ncopies > 8)
{
*(d + 7) = *(s + 7);
*(d + 8) = *(s + 8);
}
}
}
}
memcpy (newmem, chunk2mem (oldp), oldsize - SIZE_SZ);
_int_free (av, oldp, 1);
check_inuse_chunk (av, newp);
return chunk2mem (newp);
+5 -4
View File
@@ -29,14 +29,15 @@
#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_23)
/* Define the variables used for the interface. */
char *loc1;
char *loc2;
/* Define the variables used for the interface. Avoid .symver on common
symbol, which just creates a new common symbol, not an alias. */
char *loc1 __attribute__ ((nocommon));
char *loc2 __attribute__ ((nocommon));
compat_symbol (libc, loc1, loc1, GLIBC_2_0);
compat_symbol (libc, loc2, loc2, GLIBC_2_0);
/* Although we do not support the use we define this variable as well. */
char *locs;
char *locs __attribute__ ((nocommon));
compat_symbol (libc, locs, locs, GLIBC_2_0);
+1 -1
View File
@@ -291,7 +291,7 @@ _nss_nisplus_getaliasbyname_r (const char *name, struct aliasent *alias,
return status;
}
if (name != NULL)
if (name == NULL)
{
*errnop = EINVAL;
return NSS_STATUS_UNAVAIL;
+5 -2
View File
@@ -268,7 +268,7 @@ tests = tst-typesizes \
tst-flock1 tst-flock2 \
tst-signal1 tst-signal2 tst-signal3 tst-signal4 tst-signal5 \
tst-signal6 tst-signal7 \
tst-exec1 tst-exec2 tst-exec3 tst-exec4 \
tst-exec1 tst-exec2 tst-exec3 tst-exec4 tst-exec5 \
tst-exit1 tst-exit2 tst-exit3 \
tst-stdio1 tst-stdio2 \
tst-stack1 tst-stack2 tst-stack3 tst-stack4 tst-pthread-getattr \
@@ -290,7 +290,10 @@ tests = tst-typesizes \
tst-initializers1 $(addprefix tst-initializers1-,\
c89 gnu89 c99 gnu99 c11 gnu11) \
tst-bad-schedattr \
tst-thread_local1 tst-mutex-errorcheck tst-robust10
tst-thread_local1 tst-mutex-errorcheck tst-robust10 \
tst-minstack-cancel tst-minstack-exit \
tst-create-detached
xtests = tst-setuid1 tst-setuid1-static tst-setuid2 \
tst-mutexpp1 tst-mutexpp6 tst-mutexpp10
test-srcs = tst-oddstacklimit
+6 -18
View File
@@ -440,9 +440,6 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
SETUP_THREAD_SYSINFO (pd);
#endif
/* The process ID is also the same as that of the caller. */
pd->pid = THREAD_GETMEM (THREAD_SELF, pid);
/* Don't allow setxid until cloned. */
pd->setxid_futex = -1;
@@ -487,6 +484,10 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
/* Make sure the size of the stack is enough for the guard and
eventually the thread descriptor. */
guardsize = (attr->guardsize + pagesize_m1) & ~pagesize_m1;
if (guardsize < attr->guardsize || size + guardsize < guardsize)
/* Arithmetic overflow. */
return EINVAL;
size += guardsize;
if (__builtin_expect (size < ((guardsize + __static_tls_size
+ MINIMAL_REST_STACK + pagesize_m1)
& ~pagesize_m1),
@@ -579,9 +580,6 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
/* Don't allow setxid until cloned. */
pd->setxid_futex = -1;
/* The process ID is also the same as that of the caller. */
pd->pid = THREAD_GETMEM (THREAD_SELF, pid);
/* Allocate the DTV for this thread. */
if (_dl_allocate_tls (TLS_TPADJ (pd)) == NULL)
{
@@ -875,9 +873,6 @@ __reclaim_stacks (void)
/* This marks the stack as free. */
curp->tid = 0;
/* The PID field must be initialized for the new process. */
curp->pid = self->pid;
/* Account for the size of the stack. */
stack_cache_actsize += curp->stackblock_size;
@@ -903,13 +898,6 @@ __reclaim_stacks (void)
}
}
/* Reset the PIDs in any cached stacks. */
list_for_each (runp, &stack_cache)
{
struct pthread *curp = list_entry (runp, struct pthread, list);
curp->pid = self->pid;
}
/* Add the stack of all running threads to the cache. */
list_splice (&stack_used, &stack_cache);
@@ -1054,9 +1042,9 @@ setxid_signal_thread (struct xid_command *cmdp, struct pthread *t)
return 0;
int val;
pid_t pid = __getpid ();
INTERNAL_SYSCALL_DECL (err);
val = INTERNAL_SYSCALL (tgkill, err, 3, THREAD_GETMEM (THREAD_SELF, pid),
t->tid, SIGSETXID);
val = INTERNAL_SYSCALL_CALL (tgkill, err, pid, t->tid, SIGSETXID);
/* If this failed, it must have had not started yet or else exited. */
if (!INTERNAL_SYSCALL_ERROR_P (val, err))
+4 -6
View File
@@ -25,16 +25,14 @@
static int
create_thread (struct pthread *pd, const struct pthread_attr *attr,
bool stopped_start, STACK_VARIABLES_PARMS, bool *thread_ran)
bool *stopped_start, STACK_VARIABLES_PARMS, bool *thread_ran)
{
/* If the implementation needs to do some tweaks to the thread after
it has been created at the OS level, it can set STOPPED_START here. */
pd->stopped_start = stopped_start;
if (__glibc_unlikely (stopped_start))
/* We make sure the thread does not run far by forcing it to get a
lock. We lock it here too so that the new thread cannot continue
until we tell it to. */
pd->stopped_start = *stopped_start;
if (__glibc_unlikely (*stopped_start))
/* See CONCURRENCY NOTES in nptl/pthread_create.c. */
lll_lock (pd->lock, LLL_PRIVATE);
return ENOSYS;
+4 -4
View File
@@ -167,8 +167,8 @@ struct pthread
therefore stack) used' flag. */
pid_t tid;
/* Process ID - thread group ID in kernel speak. */
pid_t pid;
/* Ununsed. */
pid_t pid_ununsed;
/* List of robust mutexes the thread is holding. */
#ifdef __PTHREAD_MUTEX_HAVE_PREV
@@ -363,9 +363,9 @@ struct pthread
/* Machine-specific unwind info. */
struct _Unwind_Exception exc;
/* If nonzero pointer to area allocated for the stack and its
size. */
/* If nonzero, pointer to the area allocated for the stack and guard. */
void *stackblock;
/* Size of the stackblock area including the guard. */
size_t stackblock_size;
/* Size of the included guard area. */
size_t guardsize;
+3 -17
View File
@@ -184,18 +184,12 @@ __nptl_set_robust (struct pthread *self)
static void
sigcancel_handler (int sig, siginfo_t *si, void *ctx)
{
/* Determine the process ID. It might be negative if the thread is
in the middle of a fork() call. */
pid_t pid = THREAD_GETMEM (THREAD_SELF, pid);
if (__glibc_unlikely (pid < 0))
pid = -pid;
/* Safety check. It would be possible to call this function for
other signals and send a signal from another process. This is not
correct and might even be a security problem. Try to catch as
many incorrect invocations as possible. */
if (sig != SIGCANCEL
|| si->si_pid != pid
|| si->si_pid != __getpid()
|| si->si_code != SI_TKILL)
return;
@@ -243,19 +237,14 @@ struct xid_command *__xidcmd attribute_hidden;
static void
sighandler_setxid (int sig, siginfo_t *si, void *ctx)
{
/* Determine the process ID. It might be negative if the thread is
in the middle of a fork() call. */
pid_t pid = THREAD_GETMEM (THREAD_SELF, pid);
int result;
if (__glibc_unlikely (pid < 0))
pid = -pid;
/* Safety check. It would be possible to call this function for
other signals and send a signal from another process. This is not
correct and might even be a security problem. Try to catch as
many incorrect invocations as possible. */
if (sig != SIGSETXID
|| si->si_pid != pid
|| si->si_pid != __getpid ()
|| si->si_code != SI_TKILL)
return;
@@ -504,8 +493,5 @@ strong_alias (__pthread_initialize_minimal_internal,
size_t
__pthread_get_minstack (const pthread_attr_t *attr)
{
struct pthread_attr *iattr = (struct pthread_attr *) attr;
return (GLRO(dl_pagesize) + __static_tls_size + PTHREAD_STACK_MIN
+ iattr->guardsize);
return GLRO(dl_pagesize) + __static_tls_size + PTHREAD_STACK_MIN;
}
+5 -13
View File
@@ -22,7 +22,7 @@
#include "pthreadP.h"
#include <atomic.h>
#include <sysdep.h>
#include <unistd.h>
int
pthread_cancel (pthread_t th)
@@ -66,19 +66,11 @@ pthread_cancel (pthread_t th)
#ifdef SIGCANCEL
/* The cancellation handler will take care of marking the
thread as canceled. */
pid_t pid = getpid ();
INTERNAL_SYSCALL_DECL (err);
/* One comment: The PID field in the TCB can temporarily be
changed (in fork). But this must not affect this code
here. Since this function would have to be called while
the thread is executing fork, it would have to happen in
a signal handler. But this is no allowed, pthread_cancel
is not guaranteed to be async-safe. */
int val;
val = INTERNAL_SYSCALL (tgkill, err, 3,
THREAD_GETMEM (THREAD_SELF, pid), pd->tid,
SIGCANCEL);
int val = INTERNAL_SYSCALL_CALL (tgkill, err, pid, pd->tid,
SIGCANCEL);
if (INTERNAL_SYSCALL_ERROR_P (val, err))
result = INTERNAL_SYSCALL_ERRNO (val, err);
#else
+174 -33
View File
@@ -54,25 +54,141 @@ unsigned int __nptl_nthreads = 1;
/* Code to allocate and deallocate a stack. */
#include "allocatestack.c"
/* createthread.c defines this function, and two macros:
/* CONCURRENCY NOTES:
Understanding who is the owner of the 'struct pthread' or 'PD'
(refers to the value of the 'struct pthread *pd' function argument)
is critically important in determining exactly which operations are
allowed and which are not and when, particularly when it comes to the
implementation of pthread_create, pthread_join, pthread_detach, and
other functions which all operate on PD.
The owner of PD is responsible for freeing the final resources
associated with PD, and may examine the memory underlying PD at any
point in time until it frees it back to the OS or to reuse by the
runtime.
The thread which calls pthread_create is called the creating thread.
The creating thread begins as the owner of PD.
During startup the new thread may examine PD in coordination with the
owner thread (which may be itself).
The four cases of ownership transfer are:
(1) Ownership of PD is released to the process (all threads may use it)
after the new thread starts in a joinable state
i.e. pthread_create returns a usable pthread_t.
(2) Ownership of PD is released to the new thread starting in a detached
state.
(3) Ownership of PD is dynamically released to a running thread via
pthread_detach.
(4) Ownership of PD is acquired by the thread which calls pthread_join.
Implementation notes:
The PD->stopped_start and thread_ran variables are used to determine
exactly which of the four ownership states we are in and therefore
what actions can be taken. For example after (2) we cannot read or
write from PD anymore since the thread may no longer exist and the
memory may be unmapped. The most complicated cases happen during
thread startup:
(a) If the created thread is in a detached (PTHREAD_CREATE_DETACHED),
or joinable (default PTHREAD_CREATE_JOINABLE) state and
STOPPED_START is true, then the creating thread has ownership of
PD until the PD->lock is released by pthread_create. If any
errors occur we are in states (c), (d), or (e) below.
(b) If the created thread is in a detached state
(PTHREAD_CREATED_DETACHED), and STOPPED_START is false, then the
creating thread has ownership of PD until it invokes the OS
kernel's thread creation routine. If this routine returns
without error, then the created thread owns PD; otherwise, see
(c) and (e) below.
(c) If the detached thread setup failed and THREAD_RAN is true, then
the creating thread releases ownership to the new thread by
sending a cancellation signal. All threads set THREAD_RAN to
true as quickly as possible after returning from the OS kernel's
thread creation routine.
(d) If the joinable thread setup failed and THREAD_RAN is true, then
then the creating thread retains ownership of PD and must cleanup
state. Ownership cannot be released to the process via the
return of pthread_create since a non-zero result entails PD is
undefined and therefore cannot be joined to free the resources.
We privately call pthread_join on the thread to finish handling
the resource shutdown (Or at least we should, see bug 19511).
(e) If the thread creation failed and THREAD_RAN is false, then the
creating thread retains ownership of PD and must cleanup state.
No waiting for the new thread is required because it never
started.
The nptl_db interface:
The interface with nptl_db requires that we enqueue PD into a linked
list and then call a function which the debugger will trap. The PD
will then be dequeued and control returned to the thread. The caller
at the time must have ownership of PD and such ownership remains
after control returns to thread. The enqueued PD is removed from the
linked list by the nptl_db callback td_thr_event_getmsg. The debugger
must ensure that the thread does not resume execution, otherwise
ownership of PD may be lost and examining PD will not be possible.
Note that the GNU Debugger as of (December 10th 2015) commit
c2c2a31fdb228d41ce3db62b268efea04bd39c18 no longer uses
td_thr_event_getmsg and several other related nptl_db interfaces. The
principal reason for this is that nptl_db does not support non-stop
mode where other threads can run concurrently and modify runtime
structures currently in use by the debugger and the nptl_db
interface.
Axioms:
* The create_thread function can never set stopped_start to false.
* The created thread can read stopped_start but never write to it.
* The variable thread_ran is set some time after the OS thread
creation routine returns, how much time after the thread is created
is unspecified, but it should be as quickly as possible.
*/
/* CREATE THREAD NOTES:
createthread.c defines the create_thread function, and two macros:
START_THREAD_DEFN and START_THREAD_SELF (see below).
create_thread is obliged to initialize PD->stopped_start. It
should be true if the STOPPED_START parameter is true, or if
create_thread needs the new thread to synchronize at startup for
some other implementation reason. If PD->stopped_start will be
true, then create_thread is obliged to perform the operation
"lll_lock (PD->lock, LLL_PRIVATE)" before starting the thread.
create_thread must initialize PD->stopped_start. It should be true
if the STOPPED_START parameter is true, or if create_thread needs the
new thread to synchronize at startup for some other implementation
reason. If STOPPED_START will be true, then create_thread is obliged
to lock PD->lock before starting the thread. Then pthread_create
unlocks PD->lock which synchronizes-with START_THREAD_DEFN in the
child thread which does an acquire/release of PD->lock as the last
action before calling the user entry point. The goal of all of this
is to ensure that the required initial thread attributes are applied
(by the creating thread) before the new thread runs user code. Note
that the the functions pthread_getschedparam, pthread_setschedparam,
pthread_setschedprio, __pthread_tpp_change_priority, and
__pthread_current_priority reuse the same lock, PD->lock, for a
similar purpose e.g. synchronizing the setting of similar thread
attributes. These functions are never called before the thread is
created, so don't participate in startup syncronization, but given
that the lock is present already and in the unlocked state, reusing
it saves space.
The return value is zero for success or an errno code for failure.
If the return value is ENOMEM, that will be translated to EAGAIN,
so create_thread need not do that. On failure, *THREAD_RAN should
be set to true iff the thread actually started up and then got
cancelled before calling user code (*PD->start_routine), in which
case it is responsible for doing its own cleanup. */
canceled before calling user code (*PD->start_routine). */
static int create_thread (struct pthread *pd, const struct pthread_attr *attr,
bool stopped_start, STACK_VARIABLES_PARMS,
bool *stopped_start, STACK_VARIABLES_PARMS,
bool *thread_ran);
#include <createthread.c>
@@ -314,12 +430,19 @@ START_THREAD_DEFN
/* Store the new cleanup handler info. */
THREAD_SETMEM (pd, cleanup_jmp_buf, &unwind_buf);
/* We are either in (a) or (b), and in either case we either own
PD already (2) or are about to own PD (1), and so our only
restriction would be that we can't free PD until we know we
have ownership (see CONCURRENCY NOTES above). */
if (__glibc_unlikely (pd->stopped_start))
{
int oldtype = CANCEL_ASYNC ();
/* Get the lock the parent locked to force synchronization. */
lll_lock (pd->lock, LLL_PRIVATE);
/* We have ownership of PD now. */
/* And give it up right away. */
lll_unlock (pd->lock, LLL_PRIVATE);
@@ -378,7 +501,8 @@ START_THREAD_DEFN
pd, pd->nextevent));
}
/* Now call the function to signal the event. */
/* Now call the function which signals the event. See
CONCURRENCY NOTES for the nptl_db interface comments. */
__nptl_death_event ();
}
}
@@ -642,19 +766,28 @@ __pthread_create_2_1 (pthread_t *newthread, const pthread_attr_t *attr,
that cares whether the thread count is correct. */
atomic_increment (&__nptl_nthreads);
bool thread_ran = false;
/* Our local value of stopped_start and thread_ran can be accessed at
any time. The PD->stopped_start may only be accessed if we have
ownership of PD (see CONCURRENCY NOTES above). */
bool stopped_start = false; bool thread_ran = false;
/* Start the thread. */
if (__glibc_unlikely (report_thread_creation (pd)))
{
/* Create the thread. We always create the thread stopped
so that it does not get far before we tell the debugger. */
retval = create_thread (pd, iattr, true, STACK_VARIABLES_ARGS,
&thread_ran);
stopped_start = true;
/* We always create the thread stopped at startup so we can
notify the debugger. */
retval = create_thread (pd, iattr, &stopped_start,
STACK_VARIABLES_ARGS, &thread_ran);
if (retval == 0)
{
/* create_thread should have set this so that the logic below can
test it. */
/* We retain ownership of PD until (a) (see CONCURRENCY NOTES
above). */
/* Assert stopped_start is true in both our local copy and the
PD copy. */
assert (stopped_start);
assert (pd->stopped_start);
/* Now fill in the information about the new thread in
@@ -671,26 +804,30 @@ __pthread_create_2_1 (pthread_t *newthread, const pthread_attr_t *attr,
pd, pd->nextevent)
!= 0);
/* Now call the function which signals the event. */
/* Now call the function which signals the event. See
CONCURRENCY NOTES for the nptl_db interface comments. */
__nptl_create_event ();
}
}
else
retval = create_thread (pd, iattr, false, STACK_VARIABLES_ARGS,
&thread_ran);
retval = create_thread (pd, iattr, &stopped_start,
STACK_VARIABLES_ARGS, &thread_ran);
if (__glibc_unlikely (retval != 0))
{
/* If thread creation "failed", that might mean that the thread got
created and ran a little--short of running user code--but then
create_thread cancelled it. In that case, the thread will do all
its own cleanup just like a normal thread exit after a successful
creation would do. */
if (thread_ran)
assert (pd->stopped_start);
/* State (c) or (d) and we may not have PD ownership (see
CONCURRENCY NOTES above). We can assert that STOPPED_START
must have been true because thread creation didn't fail, but
thread attribute setting did. */
/* See bug 19511 which explains why doing nothing here is a
resource leak for a joinable thread. */
assert (stopped_start);
else
{
/* State (e) and we have ownership of PD (see CONCURRENCY
NOTES above). */
/* Oops, we lied for a second. */
atomic_decrement (&__nptl_nthreads);
@@ -710,10 +847,14 @@ __pthread_create_2_1 (pthread_t *newthread, const pthread_attr_t *attr,
}
else
{
if (pd->stopped_start)
/* The thread blocked on this lock either because we're doing TD_CREATE
event reporting, or for some other reason that create_thread chose.
Now let it run free. */
/* We don't know if we have PD ownership. Once we check the local
stopped_start we'll know if we're in state (a) or (b) (see
CONCURRENCY NOTES above). */
if (stopped_start)
/* State (a), we own PD. The thread blocked on this lock either
because we're doing TD_CREATE event reporting, or for some
other reason that create_thread chose. Now let it run
free. */
lll_unlock (pd->lock, LLL_PRIVATE);
/* We now have for sure more than one thread. The main thread might
+5 -3
View File
@@ -57,9 +57,12 @@ pthread_getattr_np (pthread_t thread_id, pthread_attr_t *attr)
/* The sizes are subject to alignment. */
if (__glibc_likely (thread->stackblock != NULL))
{
iattr->stacksize = thread->stackblock_size;
/* The stack size reported to the user should not include the
guard size. */
iattr->stacksize = thread->stackblock_size - thread->guardsize;
#if _STACK_GROWS_DOWN
iattr->stackaddr = (char *) thread->stackblock + iattr->stacksize;
iattr->stackaddr = (char *) thread->stackblock
+ thread->stackblock_size;
#else
iattr->stackaddr = (char *) thread->stackblock;
#endif
@@ -68,7 +71,6 @@ pthread_getattr_np (pthread_t thread_id, pthread_attr_t *attr)
{
/* No stack information available. This must be for the initial
thread. Get the info in some magical way. */
assert (abs (thread->pid) == thread->tid);
/* Stack size limit. */
struct rlimit rl;
+1
View File
@@ -35,6 +35,7 @@ __pthread_getschedparam (pthread_t threadid, int *policy,
int result = 0;
/* See CREATE THREAD NOTES in nptl/pthread_create.c. */
lll_lock (pd->lock, LLL_PRIVATE);
/* The library is responsible for maintaining the values at all
+1
View File
@@ -36,6 +36,7 @@ __pthread_setschedparam (pthread_t threadid, int policy,
int result = 0;
/* See CREATE THREAD NOTES in nptl/pthread_create.c. */
lll_lock (pd->lock, LLL_PRIVATE);
struct sched_param p;
+1
View File
@@ -38,6 +38,7 @@ pthread_setschedprio (pthread_t threadid, int prio)
struct sched_param param;
param.sched_priority = prio;
/* See CREATE THREAD NOTES in nptl/pthread_create.c. */
lll_lock (pd->lock, LLL_PRIVATE);
/* If the thread should have higher priority because of some
+2
View File
@@ -114,6 +114,7 @@ __pthread_tpp_change_priority (int previous_prio, int new_prio)
if (priomax == newpriomax)
return 0;
/* See CREATE THREAD NOTES in nptl/pthread_create.c. */
lll_lock (self->lock, LLL_PRIVATE);
tpp->priomax = newpriomax;
@@ -165,6 +166,7 @@ __pthread_current_priority (void)
int result = 0;
/* See CREATE THREAD NOTES in nptl/pthread_create.c. */
lll_lock (self->lock, LLL_PRIVATE);
if ((self->flags & ATTR_FLAG_SCHED_SET) == 0)
+137
View File
@@ -0,0 +1,137 @@
/* Bug 20116: Test rapid creation of detached threads.
Copyright (C) 2017 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, see <http://www.gnu.org/licenses/>. */
/* The goal of the test is to trigger a failure if the parent touches
any part of the thread descriptor after the detached thread has
exited. We test this by creating many detached threads with large
stacks. The stacks quickly fill the the stack cache and subsequent
threads will start to cause the thread stacks to be immediately
unmapped to satisfy the stack cache max. With the stacks being
unmapped the parent's read of any part of the thread descriptor will
trigger a segfault. That segfault is what we are trying to cause,
since any segfault is a defect in the implementation. */
#include <pthread.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <stdbool.h>
#include <sys/resource.h>
#include <support/xthread.h>
/* Number of threads to create. */
enum { threads_to_create = 100000 };
/* Number of threads which should spawn other threads. */
enum { creator_threads = 2 };
/* Counter of threads created so far. This is incremented by all the
running creator threads. */
static unsigned threads_created;
/* Thread callback which does nothing, so that the thread exits
immediatedly. */
static void *
do_nothing (void *arg)
{
return NULL;
}
/* Attribute indicating that the thread should be created in a detached
fashion. */
static pthread_attr_t detached;
/* Barrier to synchronize initialization. */
static pthread_barrier_t barrier;
static void *
creator_thread (void *arg)
{
int ret;
xpthread_barrier_wait (&barrier);
while (true)
{
pthread_t thr;
/* Thread creation will fail if the kernel does not free old
threads quickly enough, so we do not report errors. */
ret = pthread_create (&thr, &detached, do_nothing, NULL);
if (ret == 0 && __atomic_add_fetch (&threads_created, 1, __ATOMIC_SEQ_CST)
>= threads_to_create)
break;
}
return NULL;
}
static int
do_test (void)
{
/* Limit the size of the process, so that memory allocation will
fail without impacting the entire system. */
{
struct rlimit limit;
if (getrlimit (RLIMIT_AS, &limit) != 0)
{
printf ("FAIL: getrlimit (RLIMIT_AS) failed: %m\n");
return 1;
}
/* This limit, 800MB, is just a heuristic. Any value can be
picked. */
long target = 800 * 1024 * 1024;
if (limit.rlim_cur == RLIM_INFINITY || limit.rlim_cur > target)
{
limit.rlim_cur = target;
if (setrlimit (RLIMIT_AS, &limit) != 0)
{
printf ("FAIL: setrlimit (RLIMIT_AS) failed: %m\n");
return 1;
}
}
}
xpthread_attr_init (&detached);
xpthread_attr_setdetachstate (&detached, PTHREAD_CREATE_DETACHED);
/* A large thread stack seems beneficial for reproducing a race
condition in detached thread creation. The goal is to reach the
limit of the runtime thread stack cache such that the detached
thread's stack is unmapped after exit and causes a segfault when
the parent reads the thread descriptor data stored on the the
unmapped stack. */
xpthread_attr_setstacksize (&detached, 16 * 1024 * 1024);
xpthread_barrier_init (&barrier, NULL, creator_threads);
pthread_t threads[creator_threads];
for (int i = 0; i < creator_threads; ++i)
threads[i] = xpthread_create (NULL, creator_thread, NULL);
for (int i = 0; i < creator_threads; ++i)
xpthread_join (threads[i]);
xpthread_attr_destroy (&detached);
xpthread_barrier_destroy (&barrier);
return 0;
}
#include <support/test-driver.c>
+196
View File
@@ -0,0 +1,196 @@
/* Check if posix_spawn does not act as a cancellation entrypoint.
Copyright (C) 2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <errno.h>
#include <paths.h>
#include <pthread.h>
#include <signal.h>
#include <spawn.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
static int do_test (void);
#define TEST_FUNCTION do_test ()
#include <test-skeleton.c>
static pthread_barrier_t b;
static pid_t pid;
static int pipefd[2];
static void *
tf (void *arg)
{
int r = pthread_barrier_wait (&b);
if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
{
puts ("error: pthread_barrier_wait failed");
exit (1);
}
posix_spawn_file_actions_t a;
if (posix_spawn_file_actions_init (&a) != 0)
{
puts ("error: spawn_file_actions_init failed");
exit (1);
}
if (posix_spawn_file_actions_adddup2 (&a, pipefd[1], STDOUT_FILENO) != 0)
{
puts ("error: spawn_file_actions_adddup2 failed");
exit (1);
}
if (posix_spawn_file_actions_addclose (&a, pipefd[0]) != 0)
{
puts ("error: spawn_file_actions_addclose");
exit (1);
}
char *argv[] = { (char *) _PATH_BSHELL, (char *) "-c", (char *) "echo $$",
NULL };
if (posix_spawn (&pid, _PATH_BSHELL, &a, NULL, argv, NULL) != 0)
{
puts ("error: spawn failed");
exit (1);
}
return NULL;
}
static int
do_test (void)
{
/* The test basically pipe a 'echo $$' created by a thread with a
cancellation pending. It then checks if the thread is not cancelled,
the process is created and if the output is the expected one. */
if (pipe (pipefd) != 0)
{
puts ("error: pipe failed");
exit (1);
}
/* Not interested in knowing when the pipe is closed. */
if (sigignore (SIGPIPE) != 0)
{
puts ("error: sigignore failed");
exit (1);
}
/* To synchronize with the thread. */
if (pthread_barrier_init (&b, NULL, 2) != 0)
{
puts ("error: pthread_barrier_init failed");
exit (1);
}
pthread_t th;
if (pthread_create (&th, NULL, &tf, NULL) != 0)
{
puts ("error: pthread_create failed");
exit (1);
}
if (pthread_cancel (th) != 0)
{
puts ("error: pthread_cancel failed");
exit (1);
}
int r = pthread_barrier_wait (&b);
if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
{
puts ("error: pthread_barrier_wait");
exit (1);
}
void *retval;
if (pthread_join (th, &retval) != 0)
{
puts ("error: pthread_join failed\n");
}
if (retval == PTHREAD_CANCELED)
{
puts ("error: thread cancelled");
exit (1);
}
close (pipefd[1]);
/* The global 'pid' should be set by thread posix_spawn calling. Check
below if it was executed correctly and with expected output. */
char buf[64];
ssize_t n;
bool seen_pid = false;
while (TEMP_FAILURE_RETRY ((n = read (pipefd[0], buf, sizeof (buf)))) > 0)
{
/* We only expect to read the PID. */
char *endp;
long int rpid = strtol (buf, &endp, 10);
if (*endp != '\n')
{
printf ("error: didn't parse whole line: \"%s\"\n", buf);
exit (1);
}
if (endp == buf)
{
puts ("error: read empty line");
exit (1);
}
if (rpid != pid)
{
printf ("error: found \"%s\", expected PID %ld\n", buf,
(long int) pid);
exit (1);
}
if (seen_pid)
{
puts ("error: found more than one PID line");
exit (1);
}
seen_pid = true;
}
close (pipefd[0]);
int status;
int err = waitpid (pid, &status, 0);
if (err != pid)
{
puts ("errnor: waitpid failed");
exit (1);
}
if (!seen_pid)
{
puts ("error: didn't get PID");
exit (1);
}
return 0;
}
+48
View File
@@ -0,0 +1,48 @@
/* Test cancellation with a minimal stack size.
Copyright (C) 2018 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
/* Note: This test is similar to tst-minstack-exit, but is separate to
avoid spurious test passes due to warm-up effects. */
#include <limits.h>
#include <unistd.h>
#include <support/check.h>
#include <support/xthread.h>
static void *
threadfunc (void *closure)
{
while (1)
pause ();
return NULL;
}
static int
do_test (void)
{
pthread_attr_t attr;
xpthread_attr_init (&attr);
xpthread_attr_setstacksize (&attr, PTHREAD_STACK_MIN);
pthread_t thr = xpthread_create (&attr, threadfunc, NULL);
xpthread_cancel (thr);
TEST_VERIFY (xpthread_join (thr) == PTHREAD_CANCELED);
xpthread_attr_destroy (&attr);
return 0;
}
#include <support/test-driver.c>
+46
View File
@@ -0,0 +1,46 @@
/* Test that pthread_exit works with the minimum stack size.
Copyright (C) 2018 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
/* Note: This test is similar to tst-minstack-cancel, but is separate
to avoid spurious test passes due to warm-up effects. */
#include <limits.h>
#include <unistd.h>
#include <support/check.h>
#include <support/xthread.h>
static void *
threadfunc (void *closure)
{
pthread_exit (threadfunc);
return NULL;
}
static int
do_test (void)
{
pthread_attr_t attr;
xpthread_attr_init (&attr);
xpthread_attr_setstacksize (&attr, PTHREAD_STACK_MIN);
pthread_t thr = xpthread_create (&attr, threadfunc, NULL);
TEST_VERIFY (xpthread_join (thr) == threadfunc);
xpthread_attr_destroy (&attr);
return 0;
}
#include <support/test-driver.c>
+2
View File
@@ -75,5 +75,7 @@ do_test (void)
return result;
}
// The test currently hangs and is XFAILed. Reduce the timeout.
#define TIMEOUT 1
#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"
-1
View File
@@ -48,7 +48,6 @@ DB_STRUCT (pthread)
DB_STRUCT_FIELD (pthread, list)
DB_STRUCT_FIELD (pthread, report_events)
DB_STRUCT_FIELD (pthread, tid)
DB_STRUCT_FIELD (pthread, pid)
DB_STRUCT_FIELD (pthread, start_routine)
DB_STRUCT_FIELD (pthread, cancelhandling)
DB_STRUCT_FIELD (pthread, schedpolicy)
+18 -38
View File
@@ -76,48 +76,28 @@ iterate_thread_list (td_thragent_t *ta, td_thr_iter_f *callback,
if (ps_pdread (ta->ph, addr, copy, ta->ta_sizeof_pthread) != PS_OK)
return TD_ERR;
/* Verify that this thread's pid field matches the child PID.
If its pid field is negative, it's about to do a fork or it
is the sole thread in a fork child. */
psaddr_t pid;
err = DB_GET_FIELD_LOCAL (pid, ta, copy, pthread, pid, 0);
if (err == TD_OK && (pid_t) (uintptr_t) pid < 0)
{
if (-(pid_t) (uintptr_t) pid == match_pid)
/* It is about to do a fork, but is really still the parent PID. */
pid = (psaddr_t) (uintptr_t) match_pid;
else
/* It must be a fork child, whose new PID is in the tid field. */
err = DB_GET_FIELD_LOCAL (pid, ta, copy, pthread, tid, 0);
}
err = DB_GET_FIELD_LOCAL (schedpolicy, ta, copy, pthread,
schedpolicy, 0);
if (err != TD_OK)
break;
err = DB_GET_FIELD_LOCAL (schedprio, ta, copy, pthread,
schedparam_sched_priority, 0);
if (err != TD_OK)
break;
if ((pid_t) (uintptr_t) pid == match_pid)
/* Now test whether this thread matches the specified conditions. */
/* Only if the priority level is as high or higher. */
int descr_pri = ((uintptr_t) schedpolicy == SCHED_OTHER
? 0 : (uintptr_t) schedprio);
if (descr_pri >= ti_pri)
{
err = DB_GET_FIELD_LOCAL (schedpolicy, ta, copy, pthread,
schedpolicy, 0);
if (err != TD_OK)
break;
err = DB_GET_FIELD_LOCAL (schedprio, ta, copy, pthread,
schedparam_sched_priority, 0);
if (err != TD_OK)
break;
/* Now test whether this thread matches the specified conditions. */
/* Only if the priority level is as high or higher. */
int descr_pri = ((uintptr_t) schedpolicy == SCHED_OTHER
? 0 : (uintptr_t) schedprio);
if (descr_pri >= ti_pri)
{
/* Yep, it matches. Call the callback function. */
td_thrhandle_t th;
th.th_ta_p = (td_thragent_t *) ta;
th.th_unique = addr;
if (callback (&th, cbdata_p) != 0)
return TD_DBERR;
}
/* Yep, it matches. Call the callback function. */
td_thrhandle_t th;
th.th_ta_p = (td_thragent_t *) ta;
th.th_unique = addr;
if (callback (&th, cbdata_p) != 0)
return TD_DBERR;
}
/* Get the pointer to the next element. */
-23
View File
@@ -80,28 +80,5 @@ td_thr_validate (const td_thrhandle_t *th)
err = TD_OK;
}
if (err == TD_OK)
{
/* Verify that this is not a stale element in a fork child. */
pid_t match_pid = ps_getpid (th->th_ta_p->ph);
psaddr_t pid;
err = DB_GET_FIELD (pid, th->th_ta_p, th->th_unique, pthread, pid, 0);
if (err == TD_OK && (pid_t) (uintptr_t) pid < 0)
{
/* This was a thread that was about to fork, or it is the new sole
thread in a fork child. In the latter case, its tid was stored
via CLONE_CHILD_SETTID and so is already the proper child PID. */
if (-(pid_t) (uintptr_t) pid == match_pid)
/* It is about to do a fork, but is really still the parent PID. */
pid = (psaddr_t) (uintptr_t) match_pid;
else
/* It must be a fork child, whose new PID is in the tid field. */
err = DB_GET_FIELD (pid, th->th_ta_p, th->th_unique,
pthread, tid, 0);
}
if (err == TD_OK && (pid_t) (uintptr_t) pid != match_pid)
err = TD_NOTHR;
}
return err;
}
+3 -3
View File
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: GNU libc 2.22-pre1\n"
"POT-Creation-Date: 2015-07-31 00:10-0400\n"
"PO-Revision-Date: 2015-08-31 18:30+0200\n"
"PO-Revision-Date: 2016-04-22 18:44+0200\n"
"Last-Translator: Jochen Hein <jochen@jochen.org>\n"
"Language-Team: German <translation-team-de@lists.sourceforge.net>\n"
"Language: de\n"
@@ -4479,13 +4479,13 @@ msgstr ""
"%15s Cache ist dauerhaft\n"
"%15s Cache wird gemeinsam verwendet\n"
"%15Zu vorgeschlagene Größe\n"
"%15Zu Gesamtröße des Data-Pools\n"
"%15Zu Gesamtgröße des Data-Pools\n"
"%15Zu Benutzter Speicher im Data-Pool\n"
"%15lu Time to Live für positive Einträge in Sekunden\n"
"%15lu Time to Live für negative Einträge in Sekunden\n"
"%15<PRIuMAX> Cache-Hits bei positiven Einträgen\n"
"%15<PRIuMAX> Cache-Hits bei positiven Einträgen\n"
"%15<PRIuMAX> Cache-Misses bei positiven Einträgen\n"
"%15<PRIuMAX> Cache-Misses bei positiven Einträgen\n"
"%15<PRIuMAX> Cache-Misses bei negativen Einträgen\n"
"%15lu%% Cache-Hit Verhältnis\n"
"%15zu aktuelle Anzahl der Werte im Cache\n"
+40 -50
View File
@@ -24,16 +24,16 @@
#
msgid ""
msgstr ""
"Project-Id-Version: libc 2.21-pre1\n"
"Project-Id-Version: libc 2.22-pre1\n"
"POT-Creation-Date: 2015-07-31 00:10-0400\n"
"PO-Revision-Date: 2015-07-28 20:29+0300\n"
"PO-Revision-Date: 2016-05-26 21:14+0300\n"
"Last-Translator: Lauri Nurmi <lanurmi@iki.fi>\n"
"Language-Team: Finnish <translation-team-fi@lists.sourceforge.net>\n"
"Language: fi\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 1.8.3\n"
"X-Generator: Poedit 1.8.7\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: argp/argp-help.c:227
@@ -126,7 +126,7 @@ msgid "%s%s%s:%u: %s%sUnexpected error: %s.\n"
msgstr "%s%s%s:%u: %s%sOdottamaton virhe: %s.\n"
#: assert/assert.c:101
#, fuzzy, c-format
#, c-format
msgid ""
"%s%s%s:%u: %s%sAssertion `%s' failed.\n"
"%n"
@@ -169,12 +169,12 @@ msgstr ""
#: malloc/memusagestat.c:563 nss/getent.c:973 nss/makedb.c:369
#: posix/getconf.c:486 sunrpc/rpcinfo.c:691
#: sysdeps/unix/sysv/linux/lddlibc4.c:61
#, fuzzy, c-format
#, c-format
msgid ""
"For bug reporting instructions, please see:\n"
"%s.\n"
msgstr ""
"Ohjeet ohjelmistovioista ilmoittamiseen ovat osoitteessa\n"
"Katso ohjeet vikailmoitusten tekemiseen osoitteesta:\n"
"%s.\n"
#: catgets/gencat.c:245 debug/pcprofiledump.c:225 debug/xtrace.sh:64
@@ -321,9 +321,8 @@ msgstr "Käyttö: xtrace [VALITSIN]... OHJELMA [OHJELMANVALITSIN]...\\n"
#: debug/xtrace.sh:32 elf/sotruss.sh:56 elf/sotruss.sh:67 elf/sotruss.sh:135
#: malloc/memusage.sh:26
#, fuzzy
msgid "Try \\`%s --help' or \\`%s --usage' for more information.\\n"
msgstr "Kokeile ”%s --help” tai ”%s --usage” saadaksesi lisää tietoa.\n"
msgstr "Kokeile ”%s --help” tai ”%s --usage” saadaksesi lisää tietoa.\\n"
#: debug/xtrace.sh:38
#, fuzzy
@@ -594,9 +593,8 @@ msgid "cannot enable executable stack as shared object requires"
msgstr "jaettua objektikahvaa ei voi luoda"
#: elf/dl-load.c:1339
#, fuzzy
msgid "cannot close file descriptor"
msgstr "tiedostoa %s ei voi sulkea"
msgstr "tiedostokahvaa ei voi sulkea"
#: elf/dl-load.c:1568
msgid "file too short"
@@ -796,9 +794,8 @@ msgid "Format to use: new, old or compat (default)"
msgstr "Käytettävä muoto: ”new”, ”old” tai ”compat” (oletus)"
#: elf/ldconfig.c:151
#, fuzzy
msgid "Ignore auxiliary cache file"
msgstr "Käytä CACHEa välimuistitiedostona"
msgstr "Jätä huomiotta apuvälimuistitiedosto"
#: elf/ldconfig.c:159
msgid "Configure Dynamic Linker Run Time Bindings."
@@ -1087,9 +1084,9 @@ msgid "invalid process ID '%s'"
msgstr "virheellinen prosessi-ID ”%s”"
#: elf/pldd.c:120
#, fuzzy, c-format
#, c-format
msgid "cannot open %s"
msgstr "laitetta %s ei voi avata"
msgstr "tiedostoa %s ei voi avata"
#: elf/pldd.c:152
#, fuzzy, c-format
@@ -1102,24 +1099,24 @@ msgid "cannot prepare reading %s/task"
msgstr "ei voi avata laitetta %s lukutilaan"
#: elf/pldd.c:168
#, fuzzy, c-format
#, c-format
msgid "invalid thread ID '%s'"
msgstr "virheellinen prosessi-ID ”%s”"
msgstr "virheellinen säie-ID ”%s”"
#: elf/pldd.c:179
#, fuzzy, c-format
#, c-format
msgid "cannot attach to process %lu"
msgstr "tiedostoa ”%s” ei voi avata"
msgstr "ei voida kiinnittyä prosessiin %lu"
#: elf/pldd.c:294
#, c-format
msgid "cannot get information about process %lu"
msgstr ""
msgstr "tietojen saaminen prosessista %lu ei onnistu"
#: elf/pldd.c:307
#, fuzzy, c-format
#, c-format
msgid "process %lu is no ELF program"
msgstr "ohjelma %lu ei ole käytettävissä\n"
msgstr "prosessi %lu ei ole ELF-ohjelma"
#: elf/readelflib.c:34
#, c-format
@@ -1203,7 +1200,7 @@ msgstr "%s kohde ei saa olla hakemisto\n"
#: elf/sln.c:184
#, c-format
msgid "%s: failed to remove the old destination\n"
msgstr ""
msgstr "%s: vanhan kohteen poistaminen epäonnistui\n"
#: elf/sln.c:192
#, c-format
@@ -1237,9 +1234,8 @@ msgid "Mandatory arguments to long options are also mandatory for any correspond
msgstr "Pakolliset argumentit pitkille valitsimille ovat pakollisia kaikille vastaaville lyhyille valitsimille.\\n"
#: elf/sotruss.sh:55
#, fuzzy
msgid "%s: option requires an argument -- '%s'\\n"
msgstr "%s: valitsin ”%s” vaatii argumentin\n"
msgstr "%s: valitsin vaatii argumentin -- ”%c”\\n"
#: elf/sotruss.sh:61
msgid "%s: option is ambiguous; possibilities:"
@@ -1507,7 +1503,6 @@ msgid "unknown iconv() error %d"
msgstr "tuntematon iconv()-virhe %d"
#: iconv/iconv_prog.c:791
#, fuzzy
msgid ""
"The following list contains all the coded character sets known. This does\n"
"not necessarily mean that all combinations of these names can be used for\n"
@@ -1516,9 +1511,9 @@ msgid ""
"\n"
" "
msgstr ""
"Seuraavassa listassa ovat kaikki tunnetut koodatut merkistöt. Se ei\n"
"Seuraavassa listassa ovat kaikki tunnetut koodatut merkistöt. Tämä ei\n"
"kuitenkaan välttämättä tarkoita sitä, että kaikkia näiden nimien\n"
"yhdistelmiä voidaan käyttää FROM- ja TO-komentoriviparametreina. Yksi\n"
"yhdistelmiä voisi käyttää FROM- ja TO-komentoriviparametreina. Yksi\n"
"koodattu merkistö voi olla listalla useilla eri nimillä (aliaksilla).\n"
"\n"
" "
@@ -2733,14 +2728,12 @@ msgid "locale.alias file to consult when making archive"
msgstr "Arkistoa luotaessa käytettävä locale.alias-tiedosto"
#: locale/programs/localedef.c:150
#, fuzzy
msgid "Generate little-endian output"
msgstr "Tuota little-endian-koodia"
msgstr "Tuota little-endian-muotoa"
#: locale/programs/localedef.c:152
#, fuzzy
msgid "Generate big-endian output"
msgstr "Tuota big-endian-koodia"
msgstr "Tuota big-endian-muotoa"
#: locale/programs/localedef.c:157
msgid "Compile locale specification"
@@ -4275,10 +4268,9 @@ msgid ""
msgstr ""
#: nscd/nscd.c:635
#, fuzzy, c-format
#| msgid "lstat failed"
#, c-format
msgid "'wait' failed\n"
msgstr "tiedoston tilan luku epäonnistui"
msgstr "”wait” epäonnistui\n"
#: nscd/nscd.c:642
#, c-format
@@ -4670,9 +4662,9 @@ msgid "cannot create temporary file"
msgstr "tilapäistä tiedostoa ei voi luoda"
#: nss/makedb.c:304
#, fuzzy, c-format
#, c-format
msgid "cannot stat newly created file"
msgstr "tiedoston ”%s” tilaa ei voi lukea: %s"
msgstr "juuri luodun tiedoston tilaa ei voi lukea"
#: nss/makedb.c:315
#, c-format
@@ -4680,9 +4672,9 @@ msgid "cannot rename temporary file"
msgstr "tilapäistä tiedostoa ei voi nimetä uudelleen"
#: nss/makedb.c:531 nss/makedb.c:554
#, fuzzy, c-format
#, c-format
msgid "cannot create search tree"
msgstr "hakupolulle ei voi luoda välimuistia"
msgstr "hakupuuta ei voi luoda"
#: nss/makedb.c:560
msgid "duplicate key"
@@ -4699,9 +4691,9 @@ msgid "failed to write new database file"
msgstr "uuden tietokantatiedoston kirjoittaminen epäonnistui"
#: nss/makedb.c:812
#, fuzzy, c-format
#, c-format
msgid "cannot stat database file"
msgstr "tiedoston ”%s” tilaa ei voi lukea: %s"
msgstr "tietokantatiedoston tilaa ei voi lukea"
#: nss/makedb.c:817
#, fuzzy, c-format
@@ -4709,9 +4701,9 @@ msgid "cannot map database file"
msgstr "Karttatietokannassa ei ole enempää tietueita"
#: nss/makedb.c:820
#, fuzzy, c-format
#, c-format
msgid "file not a database file"
msgstr "luettaessa profilointidatatiedoston tilaa"
msgstr "tiedosto ei ole tietokantatiedosto"
#: nss/makedb.c:871
#, fuzzy, c-format
@@ -4726,7 +4718,7 @@ msgstr "Käyttö: %s [-v määrittely] muuttujanimi [polku]\n"
#: posix/getconf.c:403
#, c-format
msgid " %s -a [pathname]\n"
msgstr ""
msgstr " %s -a [polku]\n"
#: posix/getconf.c:479
#, c-format
@@ -5094,11 +5086,11 @@ msgstr "Laitetta irrotettu"
#: stdio-common/psiginfo.c:139
msgid "Signal sent by kill()"
msgstr ""
msgstr "Signaalin lähetti kill()"
#: stdio-common/psiginfo.c:142
msgid "Signal sent by sigqueue()"
msgstr ""
msgstr "Signaalin lähetti sigqueue()"
#: stdio-common/psiginfo.c:145
msgid "Signal generated by the expiration of a timer"
@@ -5114,7 +5106,7 @@ msgstr ""
#: stdio-common/psiginfo.c:157
msgid "Signal sent by tkill()"
msgstr ""
msgstr "Signaalin lähetti tkill()"
#: stdio-common/psiginfo.c:162
msgid "Signal generated by the completion of an asynchronous name lookup request"
@@ -5296,9 +5288,8 @@ msgid "Failed (unspecified error)"
msgstr "Epäonnistui (määrittelemätön virhe)"
#: sunrpc/clnt_raw.c:115
#, fuzzy
msgid "clnt_raw.c: fatal header serialization error"
msgstr "clnt_raw.c: vakava otsikon serialisointivirhe"
msgstr "clnt_raw.c: vakava otsikon sarjallistamisvirhe"
#: sunrpc/pm_getmaps.c:77
msgid "pmap_getmaps.c: rpc problem"
@@ -6825,9 +6816,8 @@ msgid "Interrupted by a signal"
msgstr "Signaalin keskeyttämä"
#: sysdeps/posix/gai_strerror-strs.h:17
#, fuzzy
msgid "Parameter string not correctly encoded"
msgstr "Parametrimerkkijono on väärin koodattu"
msgstr "Parametrimerkkijono ei ole koodattu oikein"
#: sysdeps/unix/sysv/linux/i386/readelflib.c:65
#, c-format
+65 -78
View File
@@ -1,13 +1,17 @@
# GNU libc message catalog for Swedish
# Copyright © 1996, 1998, 2001, 2002, 2003, 2006, 2008, 2009, 2011, 2012, 2013, 2014, 2015 Free Software Foundation, Inc.
# Copyright © 1996, 1998, 2001, 2002, 2003, 2006, 2008, 2009, 2011, 2012, 2013, 2014, 2015, 2016 Free Software Foundation, Inc.
# This file is distributed under the same license as the glibc package.
# Jan Djärv <jan.h.d@swipnet.se>, 1996, 1998, 2001, 2002, 2003, 2006, 2007, 2008, 2009, 2011, 2012, 2013, 2014, 2015
#
# Jan Djärv <jan.h.d@swipnet.se>, 1996, 1998, 2001, 2002, 2003, 2006, 2007, 2008, 2009, 2011, 2012, 2013, 2014, 2015.
# Göran Uddeborg <goeran@uddeborg.se>, 2016.
#
# $Revision: 1.3 $
msgid ""
msgstr ""
"Project-Id-Version: libc 2.21-pre1\n"
"Project-Id-Version: libc 2.22-pre1\n"
"POT-Creation-Date: 2015-07-31 00:10-0400\n"
"PO-Revision-Date: 2015-01-24 10:35+0100\n"
"Last-Translator: Jan Djärv <jan.h.d@swipnet.se>\n"
"PO-Revision-Date: 2016-08-02 17:17+0200\n"
"Last-Translator: Göran Uddeborg <goeran@uddeborg.se>\n"
"Language-Team: Swedish <tp-sv@listor.tp-sv.se>\n"
"Language: sv\n"
"MIME-Version: 1.0\n"
@@ -48,7 +52,7 @@ msgstr " [FLAGGA...]"
#: argp/argp-help.c:1643
#, c-format
msgid "Try `%s --help' or `%s --usage' for more information.\n"
msgstr "Försök med \"%s --help\" eller \"%s --usage\" för mer information\n"
msgstr "Försök med %s --help eller %s --usage för mer information.\n"
#: argp/argp-help.c:1671
#, c-format
@@ -304,11 +308,11 @@ msgstr "Användning: xtrace [FLAGGA]... PROGRAM [PROGRAMFLAGGA}...\\n"
#: debug/xtrace.sh:32 elf/sotruss.sh:56 elf/sotruss.sh:67 elf/sotruss.sh:135
#: malloc/memusage.sh:26
msgid "Try \\`%s --help' or \\`%s --usage' for more information.\\n"
msgstr "Försök med \\\"%s --help\\\" eller \\\"%s --usage\\\" för mer information\\n"
msgstr "Försök med %s --help eller %s --usage för mer information\\n"
#: debug/xtrace.sh:38
msgid "%s: option '%s' requires an argument.\\n"
msgstr "%s: flaggan \\\"%s\\\" kräver ett argument\\n"
msgstr "%s: flaggan ”%s” kräver ett argument.\\n"
#: debug/xtrace.sh:45
msgid ""
@@ -332,19 +336,17 @@ msgstr ""
" --usage Visa en kort hjälptext\n"
" -V,--version Visa versionsinformation och avsluta\n"
"\n"
"Obligatoriska argument för långa flaggor är obligatoriska även för\n"
"Obligatoriska argument för långa flaggor är obligatoriska även för\n"
"motsvarande korta.\n"
#: debug/xtrace.sh:57 elf/ldd.bash.in:55 elf/sotruss.sh:49
#: malloc/memusage.sh:64
msgid "For bug reporting instructions, please see:\\\\n%s.\\\\n"
msgstr ""
"För felrapporteringsinstruktioner, se:\\\\n%s.\\\\n\n"
"Rapportera fel eller synpunkter på översättningen till <tp-sv@listor.tp-sv.se>.\\\\n"
msgstr "För felrapporteringsinstruktioner, se:\\\\n%s.\\\\nRapportera fel eller synpunkter på översättningen till:\\\\n<tp-sv@listor.tp-sv.se>.\\\\n"
#: debug/xtrace.sh:125
msgid "xtrace: unrecognized option \\`$1'\\n"
msgstr "xtrace: okänd flagga \"$1\"\\n"
msgstr "xtrace: okänd flagga ”$1”\\n"
#: debug/xtrace.sh:138
msgid "No program name given\\n"
@@ -353,12 +355,12 @@ msgstr "Inget programnamn givet\\n"
#: debug/xtrace.sh:146
#, sh-format
msgid "executable \\`$program' not found\\n"
msgstr "program \"$program\" hittades inte\\n"
msgstr "program $program hittades inte\\n"
#: debug/xtrace.sh:150
#, sh-format
msgid "\\`$program' is no executable\\n"
msgstr "\"$program\" är inte en körbar binär\\n"
msgstr "$program är inte en körbar binär\\n"
#: dlfcn/dlinfo.c:63
msgid "RTLD_SELF used in code not dynamically loaded"
@@ -396,7 +398,7 @@ msgstr ", OS ABI: %s %d.%d.%d"
#: elf/cache.c:157 elf/ldconfig.c:1340
#, c-format
msgid "Can't open cache file %s\n"
msgstr "Kan inte öppna cache-fil \"%s\"\n"
msgstr "Kan inte öppna cache-filen %s\n"
#: elf/cache.c:171
#, c-format
@@ -416,7 +418,7 @@ msgstr "%d bibliotek hittades i cache \"%s\"\n"
#: elf/cache.c:426
#, c-format
msgid "Can't create temporary cache file %s"
msgstr "Kan inte skapa temporär cache-fil \"%s\""
msgstr "Kan inte skapa en temporär cache-fil %s"
#: elf/cache.c:434 elf/cache.c:444 elf/cache.c:448 elf/cache.c:453
#, c-format
@@ -829,7 +831,7 @@ msgstr "Kan inte ta status (lstat) på %s"
#: elf/ldconfig.c:609
#, c-format
msgid "Ignored file %s since it is not a regular file."
msgstr "Ignorerar fil %s eftersom den inte är en vanlig fil"
msgstr "Ignorerar fil %s eftersom den inte är en vanlig fil."
#: elf/ldconfig.c:618
#, c-format
@@ -951,7 +953,7 @@ msgstr ""
#: elf/ldd.bash.in:80
msgid "ldd: option \\`$1' is ambiguous"
msgstr "ldd: flaggan \"$1\" är tvetydig"
msgstr "ldd: flaggan ”$1” är tvetydig"
#: elf/ldd.bash.in:87
msgid "unrecognized option"
@@ -959,7 +961,7 @@ msgstr "okänd flagga"
#: elf/ldd.bash.in:88 elf/ldd.bash.in:125
msgid "Try \\`ldd --help' for more information."
msgstr "Försök med \"ldd --help\" för mer information"
msgstr "Försök med \"ldd --help\" för mer information."
#: elf/ldd.bash.in:124
msgid "missing file arguments"
@@ -1028,10 +1030,9 @@ msgid "cannot read object name"
msgstr "kan inte läsa objektnamn"
#: elf/pldd-xx.c:219
#, fuzzy, c-format
#| msgid "cannot allocate memory for program header"
#, c-format
msgid "cannot allocate buffer for object name"
msgstr "kan inte allokera minne för programhuvud"
msgstr "kan inte allokera en buffert för objektnamn"
#: elf/pldd.c:64
msgid "List dynamic shared objects loaded into process."
@@ -1212,11 +1213,11 @@ msgstr ""
#: elf/sotruss.sh:46
msgid "Mandatory arguments to long options are also mandatory for any corresponding\\nshort options.\\n"
msgstr "Obligatoriska respektive valfria argument för långa flaggor är obligatoriska respektive\\nvalfria även för korta.\\n"
msgstr "Obligatoriska respektive valfria argument för långa flaggor är obligatoriska\\nrespektive valfria även för korta.\\n"
#: elf/sotruss.sh:55
msgid "%s: option requires an argument -- '%s'\\n"
msgstr "%s: flaggan kräver ett argument -- \\\"%s\\\"\\n"
msgstr "%s: flaggan kräver ett argument — ”%s”\\n"
#: elf/sotruss.sh:61
msgid "%s: option is ambiguous; possibilities:"
@@ -1240,7 +1241,7 @@ msgstr ""
#: elf/sotruss.sh:134
msgid "%s: unrecognized option '%c%s'\\n"
msgstr "%s: okänd flagga \\\"%c%s\\\"\\n"
msgstr "%s: okänd flagga ”%c%s”\\n"
#: elf/sprof.c:77
msgid "Output selection:"
@@ -1260,7 +1261,7 @@ msgstr "generera anropsgraf"
#: elf/sprof.c:89
msgid "Read and display shared object profiling data."
msgstr "Läs och visa profildata för delat objekt"
msgstr "Läs och visa profildata för delat objekt."
#: elf/sprof.c:94
msgid "SHOBJ [PROFDATA]"
@@ -1622,7 +1623,7 @@ msgstr "Fel: .netrc kan läsas av andra."
#: inet/ruserpass.c:185
msgid "Remove password or make file unreadable by others."
msgstr "Ta bort lösenord eller gör filen oläsbar för andra"
msgstr "Ta bort lösenord eller gör filen oläsbar för andra."
#: inet/ruserpass.c:277
#, c-format
@@ -2182,12 +2183,12 @@ msgstr "Inget namn definierat i teckenuppsättning"
#: locale/programs/ld-ctype.c:479
#, c-format
msgid "character L'\\u%0*x' in class `%s' must be in class `%s'"
msgstr "tecken L\"\\u%0*x\" i klass \"%s\" måste vara i klass \"%s\""
msgstr "tecken L'\\u%0*x' i klassen ”%s” måste vara i klassen ”%s”"
#: locale/programs/ld-ctype.c:494
#, c-format
msgid "character L'\\u%0*x' in class `%s' must not be in class `%s'"
msgstr "tecken L\"\\u%0*x\" i klass \"%s\" får inte vara i klass \"%s\""
msgstr "tecken L'\\u%0*x' i klassen ”%s” får inte vara i klassen ”%s”"
#: locale/programs/ld-ctype.c:508 locale/programs/ld-ctype.c:566
#, c-format
@@ -2611,7 +2612,7 @@ msgstr "Skriv mer information"
#: locale/programs/locale.c:85
msgid "Get locale-specific information."
msgstr "Hämta lokalspecifik information"
msgstr "Hämta lokalspecifik information."
#: locale/programs/locale.c:88
msgid ""
@@ -3022,7 +3023,7 @@ msgstr "felaktig mcheck_status, biblioteket är felaktigt\n"
#: malloc/memusage.sh:32
msgid "%s: option '%s' requires an argument\\n"
msgstr "%s: flaggan \\\"%s\\\" kräver ett argument\\n"
msgstr "%s: flaggan ”%s” kräver ett argument\\n"
#: malloc/memusage.sh:38
msgid ""
@@ -3091,11 +3092,11 @@ msgstr ""
#: malloc/memusage.sh:191
msgid "memusage: option \\`${1##*=}' is ambiguous"
msgstr "memusage: flaggan \"${1##*=}\" är tvetydig"
msgstr "memusage: flaggan ${1##*=} är tvetydig"
#: malloc/memusage.sh:200
msgid "memusage: unrecognized option \\`$1'"
msgstr "memusage: okänd flagga \"$1\""
msgstr "memusage: okänd flagga ”$1”"
#: malloc/memusage.sh:213
msgid "No program name given"
@@ -3341,7 +3342,7 @@ msgstr "Kan inte skapa process hos server"
#: nis/nis_error.h:48
msgid "Master server busy, full dump rescheduled."
msgstr "Huvudserver är upptagen, full dump åter schemalagd"
msgstr "Huvudserver är upptagen, full dump åter schemalagd."
#: nis/nis_local_names.c:121
#, c-format
@@ -3511,7 +3512,7 @@ msgstr "\t\tRättigheter : "
#: nis/nis_print.c:290
msgid "Linked Object Type : "
msgstr "Länkad objekttyp: "
msgstr "Länkad objekttyp : "
#: nis/nis_print.c:292
#, c-format
@@ -3802,15 +3803,14 @@ msgid " (first)"
msgstr " (första)"
#: nscd/cache.c:288
#, fuzzy, c-format
#| msgid "cannot stat() file `%s': %s"
#, c-format
msgid "checking for monitored file `%s': %s"
msgstr "kan inte ta status på fil \"%s\": %s"
msgstr "kontrollerar den övervakade filen ”%s”: %s"
#: nscd/cache.c:298
#, c-format
msgid "monitored file `%s` changed (mtime)"
msgstr ""
msgstr "den övervakade filen ”%s” ändrades (mtime)"
#: nscd/cache.c:341
#, c-format
@@ -3906,34 +3906,32 @@ msgstr "kan inte få uttag (socket) att acceptera förbindelser: %s"
#: nscd/connections.c:973
#, c-format
msgid "disabled inotify-based monitoring for file `%s': %s"
msgstr ""
msgstr "avaktiverade inotify-baserad övervakning för filen ”%s”: %s"
#: nscd/connections.c:977
#, c-format
msgid "monitoring file `%s` (%d)"
msgstr ""
msgstr "övervakar filen ”%s” (%d)"
#: nscd/connections.c:990
#, c-format
msgid "disabled inotify-based monitoring for directory `%s': %s"
msgstr ""
msgstr "avaktiverade inotify-baserad övervakning av katalogen ”%s”: %s"
#: nscd/connections.c:994
#, fuzzy, c-format
#| msgid "Can't open directory %s"
#, c-format
msgid "monitoring directory `%s` (%d)"
msgstr "Kan inte öppna katalog %s"
msgstr "övervakar katalogen ”%s” (%d)"
#: nscd/connections.c:1022
#, fuzzy, c-format
#| msgid "register trace file %s for database %s"
#, c-format
msgid "monitoring file %s for database %s"
msgstr "registrera spårningsfil %s för databas %s"
msgstr "övervakar filen %s för databas %s"
#: nscd/connections.c:1032
#, c-format
msgid "stat failed for file `%s'; will try again later: %s"
msgstr ""
msgstr "stat misslyckades för filen ”%s”; kommer försöka igen senare: %s"
#: nscd/connections.c:1151
#, c-format
@@ -4032,44 +4030,42 @@ msgstr "handle_request: begäran mottagen (Version = %d)"
#: nscd/connections.c:1963
#, c-format
msgid "ignored inotify event for `%s` (file exists)"
msgstr ""
msgstr "ignorerade inotify-händelse för ”%s” (filen finns)"
#: nscd/connections.c:1968
#, c-format
msgid "monitored file `%s` was %s, removing watch"
msgstr ""
msgstr "den övervakade filen ”%s” var %s, tar bort vakten"
#: nscd/connections.c:1976 nscd/connections.c:2018
#, c-format
msgid "failed to remove file watch `%s`: %s"
msgstr ""
msgstr "misslyckades att ta bort filvakt ”%s”: %s"
#: nscd/connections.c:1991
#, c-format
msgid "monitored file `%s` was written to"
msgstr ""
msgstr "den övervakade filen ”%s” skrevs till"
#: nscd/connections.c:2015
#, c-format
msgid "monitored parent directory `%s` was %s, removing watch on `%s`"
msgstr ""
msgstr "den övervakade föräldrakatalogen ”%s” var %s, tar bort vakten av ”%s”"
#: nscd/connections.c:2041
#, c-format
msgid "monitored file `%s` was %s, adding watch"
msgstr ""
msgstr "den övervakade filen ”%s” var %s, lägger till vakt"
#: nscd/connections.c:2053
#, fuzzy, c-format
#| msgid "failed to load shared object `%s'"
#, c-format
msgid "failed to add file watch `%s`: %s"
msgstr "misslyckades med att ladda delat objekt \"%s\""
msgstr "misslyckades med att lägga till filvakt ”%s”: %s"
#: nscd/connections.c:2247 nscd/connections.c:2428
#, fuzzy, c-format
#| msgid "disabled inotify after read error %d"
#, c-format
msgid "disabled inotify-based monitoring after read error %d"
msgstr "inaktiverade inotify efter läsfel %d"
msgstr "avaktiverade inotify-baserad övervakning efter läsfel %d"
#: nscd/connections.c:2543
msgid "could not initialize conditional variable"
@@ -4199,7 +4195,7 @@ msgstr "Använd separat cache för varje användare"
#: nscd/nscd.c:122
msgid "Name Service Cache Daemon."
msgstr "Namntjänst cache-demon"
msgstr "Cache-demon för namntjänsten."
#: nscd/nscd.c:155 nss/getent.c:1007 nss/makedb.c:206
#, c-format
@@ -4531,11 +4527,11 @@ msgstr "Access Vector Cache (AVC) startad"
#: nscd/selinux.c:368
msgid "Error querying policy for undefined object classes or permissions."
msgstr "Fel när policy för odefinierade objektklasser eller rättigheter hämtades"
msgstr "Fel när policy för odefinierade objektklasser eller rättigheter hämtades."
#: nscd/selinux.c:375
msgid "Error getting security class for nscd."
msgstr "Fel när säkerhetsklass för nscd hämtades"
msgstr "Fel när säkerhetsklass för nscd hämtades."
#: nscd/selinux.c:380
#, c-format
@@ -4609,7 +4605,7 @@ msgstr "inaktivera DIN-kodning"
#: nss/getent.c:64
msgid "Get entries from administrative database."
msgstr "Hämta poster från den administrativa databasen"
msgstr "Hämta poster från den administrativa databasen."
#: nss/getent.c:148 nss/getent.c:477 nss/getent.c:522
#, c-format
@@ -4652,7 +4648,7 @@ msgstr "Genererad rad som inte ingår i iterationen"
#: nss/makedb.c:131
msgid "Create simple database from textual input."
msgstr "Skapa en enkel databas från textuell indata"
msgstr "Skapa en enkel databas från textuell indata."
#: nss/makedb.c:134
msgid ""
@@ -5412,7 +5408,7 @@ msgstr "Kan inte ange netid-flaggan utan TIRPC!\n"
#: sunrpc/rpc_main.c:1374
#, c-format
msgid "Cannot use table flags with newstyle!\n"
msgstr "Kan inte ange tabellflaggor med ny stil\n"
msgstr "Kan inte ange tabellflaggor med ny stil!\n"
#: sunrpc/rpc_main.c:1393
#, c-format
@@ -7270,18 +7266,9 @@ msgstr "tidszonsförkortning skiljer sig från POSIX-standarden"
#: timezone/zic.c:2789
msgid "too many, or too long, time zone abbreviations"
msgstr "för många eller för långa tidszonförkortningar"
msgstr "för många eller för långa tidszonsförkortningar"
#: timezone/zic.c:2829
#, c-format
msgid "%s: Can't create directory %s: %s\n"
msgstr "%s: Kan inte skapa katalog %s: %s\n"
#~ msgid "cannot load any more object with static TLS"
#~ msgstr "kan inte ladda fler objekt med statiskt TLS"
#~ msgid "%s: no PLTREL found in object %s\n"
#~ msgstr "%s: hittade inga PLTREL i objekt %s\n"
#~ msgid "cannot create internal descriptors"
#~ msgstr "kan inte skapa interna deskriptorer"
+10 -3
View File
@@ -43,7 +43,7 @@ routines := \
getpgid setpgid getpgrp bsd-getpgrp setpgrp getsid setsid \
getresuid getresgid setresuid setresgid \
pathconf sysconf fpathconf \
glob glob64 fnmatch regex \
glob glob64 globfree globfree64 glob_pattern_p fnmatch regex \
confstr \
getopt getopt1 getopt_init \
sched_setp sched_getp sched_sets sched_gets sched_yield sched_primax \
@@ -90,7 +90,7 @@ tests := tstgetopt testfnm runtests runptests \
bug-getopt5 tst-getopt_long1 bug-regex34 bug-regex35 \
tst-pathconf tst-getaddrinfo4 tst-rxspencer-no-utf8 \
tst-fnmatch3 bug-regex36 tst-getaddrinfo5 \
tst-posix_spawn-fd
tst-posix_spawn-fd tst-glob-tilde
xtests := bug-ga2
ifeq (yes,$(build-shared))
test-srcs := globtest
@@ -133,7 +133,8 @@ tests-special += $(objpfx)bug-regex2-mem.out $(objpfx)bug-regex14-mem.out \
$(objpfx)tst-rxspencer-no-utf8-mem.out $(objpfx)tst-pcre-mem.out \
$(objpfx)tst-boost-mem.out $(objpfx)tst-getconf.out \
$(objpfx)bug-glob2-mem.out $(objpfx)tst-vfork3-mem.out \
$(objpfx)tst-fnmatch-mem.out $(objpfx)bug-regex36-mem.out
$(objpfx)tst-fnmatch-mem.out $(objpfx)bug-regex36-mem.out \
$(objpfx)tst-glob-tilde-mem.out
xtests-special += $(objpfx)bug-ga2-mem.out
endif
@@ -340,6 +341,12 @@ $(objpfx)bug-glob2-mem.out: $(objpfx)bug-glob2.out
$(common-objpfx)malloc/mtrace $(objpfx)bug-glob2.mtrace > $@; \
$(evaluate-test)
tst-glob-tilde-ENV = MALLOC_TRACE=$(objpfx)tst-glob-tilde.mtrace
$(objpfx)tst-glob-tilde-mem.out: $(objpfx)tst-glob-tilde.out
$(common-objpfx)malloc/mtrace $(objpfx)tst-glob-tilde.mtrace > $@; \
$(evaluate-test)
$(inst_libexecdir)/getconf: $(inst_bindir)/getconf \
$(objpfx)getconf.speclist FORCE
$(addprefix $(..)./scripts/mkinstalldirs ,\
+10 -5
View File
@@ -48,12 +48,13 @@ maybe_script_execute (const char *file, char *const argv[], char *const envp[])
}
}
/* Construct an argument list for the shell. */
/* Construct an argument list for the shell. It will contain at minimum 3
arguments (current shell, script, and an ending NULL. */
char *new_argv[argc + 1];
new_argv[0] = (char *) _PATH_BSHELL;
new_argv[1] = (char *) file;
if (argc > 1)
memcpy (new_argv + 2, argv + 1, argc * sizeof(char *));
memcpy (new_argv + 2, argv + 1, (argc - 1) * sizeof(char *));
else
new_argv[2] = NULL;
@@ -91,10 +92,11 @@ __execvpe (const char *file, char *const argv[], char *const envp[])
/* Although GLIBC does not enforce NAME_MAX, we set it as the maximum
size to avoid unbounded stack allocation. Same applies for
PATH_MAX. */
size_t file_len = __strnlen (file, NAME_MAX + 1);
size_t file_len = __strnlen (file, NAME_MAX) + 1;
size_t path_len = __strnlen (path, PATH_MAX - 1) + 1;
if ((file_len > NAME_MAX)
/* NAME_MAX does not include the terminating null character. */
if (((file_len-1) > NAME_MAX)
|| !__libc_alloca_cutoff (path_len + file_len + 1))
{
errno = ENAMETOOLONG;
@@ -103,6 +105,9 @@ __execvpe (const char *file, char *const argv[], char *const envp[])
const char *subp;
bool got_eacces = false;
/* The resulting string maximum size would be potentially a entry
in PATH plus '/' (path_len + 1) and then the the resulting file name
plus '\0' (file_len since it already accounts for the '\0'). */
char buffer[path_len + file_len + 1];
for (const char *p = path; ; p = subp)
{
@@ -123,7 +128,7 @@ __execvpe (const char *file, char *const argv[], char *const envp[])
execute. */
char *pend = mempcpy (buffer, p, subp - p);
*pend = '/';
memcpy (pend + (p < subp), file, file_len + 1);
memcpy (pend + (p < subp), file, file_len);
__execve (buffer, argv, envp);
+45
View File
@@ -0,0 +1,45 @@
/* Sizes of structs with flexible array members.
Copyright 2016-2017 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>.
Written by Paul Eggert. */
#include <stddef.h>
/* Nonzero multiple of alignment of TYPE, suitable for FLEXSIZEOF below.
On older platforms without _Alignof, use a pessimistic bound that is
safe in practice even if FLEXIBLE_ARRAY_MEMBER is 1.
On newer platforms, use _Alignof to get a tighter bound. */
#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112
# define FLEXALIGNOF(type) (sizeof (type) & ~ (sizeof (type) - 1))
#else
# define FLEXALIGNOF(type) _Alignof (type)
#endif
/* Upper bound on the size of a struct of type TYPE with a flexible
array member named MEMBER that is followed by N bytes of other data.
This is not simply sizeof (TYPE) + N, since it may require
alignment on unusually picky C11 platforms, and
FLEXIBLE_ARRAY_MEMBER may be 1 on pre-C11 platforms.
Yield a value less than N if and only if arithmetic overflow occurs. */
#define FLEXSIZEOF(type, member, n) \
((offsetof (type, member) + FLEXALIGNOF (type) - 1 + (n)) \
& ~ (FLEXALIGNOF (type) - 1))
+373 -407
View File
File diff suppressed because it is too large Load Diff
-6
View File
@@ -43,10 +43,4 @@ glob64 (const char *pattern, int flags,
}
libc_hidden_def (glob64)
void
globfree64 (glob64_t *pglob)
{
}
libc_hidden_def (globfree64)
stub_warning (glob64)
+57
View File
@@ -0,0 +1,57 @@
/* Shared definition for glob and glob_pattern_p.
Copyright (C) 2017 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#ifndef GLOB_INTERNAL_H
# define GLOB_INTERNAL_H
static inline int
__glob_pattern_type (const char *pattern, int quote)
{
const char *p;
int ret = 0;
for (p = pattern; *p != '\0'; ++p)
switch (*p)
{
case '?':
case '*':
return 1;
case '\\':
if (quote)
{
if (p[1] != '\0')
++p;
ret |= 2;
}
break;
case '[':
ret |= 4;
break;
case ']':
if (ret & 4)
return 1;
break;
}
return ret;
}
#endif /* GLOB_INTERNAL_H */
+33
View File
@@ -0,0 +1,33 @@
/* Return nonzero if PATTERN contains any metacharacters.
Copyright (C) 2017 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#ifndef _LIBC
# include <config.h>
#endif
#include <glob.h>
#include "glob_internal.h"
/* Return nonzero if PATTERN contains any metacharacters.
Metacharacters can be quoted with backslashes if QUOTE is nonzero. */
int
__glob_pattern_p (const char *pattern, int quote)
{
return __glob_pattern_type (pattern, quote) == 1;
}
weak_alias (__glob_pattern_p, glob_pattern_p)
+41
View File
@@ -0,0 +1,41 @@
/* Frees the dynamically allocated storage from an earlier call to glob.
Copyright (C) 2017 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#ifndef _LIBC
# include <config.h>
#endif
#include <glob.h>
#include <stdlib.h>
/* Free storage allocated in PGLOB by a previous `glob' call. */
void
globfree (glob_t *pglob)
{
if (pglob->gl_pathv != NULL)
{
size_t i;
for (i = 0; i < pglob->gl_pathc; ++i)
free (pglob->gl_pathv[pglob->gl_offs + i]);
free (pglob->gl_pathv);
pglob->gl_pathv = NULL;
}
}
#ifndef globfree
libc_hidden_def (globfree)
#endif
@@ -1,6 +1,6 @@
/* Copyright (C) 1997-2016 Free Software Foundation, Inc.
/* Frees the dynamically allocated storage from an earlier call to glob.
Copyright (C) 2017 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -16,8 +16,16 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
/* SH4 ABI does not really require argument alignment for 64-bits, but
the kernel interface for pread adds a dummy long argument before the
offset. */
#define __ALIGNMENT_ARG
#include <sysdeps/unix/sysv/linux/pread.c>
#ifndef _LIBC
# include <config.h>
#endif
#include <glob.h>
#include <stdlib.h>
/* Free storage allocated in PGLOB by a previous `glob' call. */
void
globfree64 (glob64_t *pglob)
{
}
libc_hidden_def (globfree64)
+143
View File
@@ -0,0 +1,143 @@
/* Check for GLOB_TIDLE heap allocation issues (bugs 22320, 22325, 22332).
Copyright (C) 2017 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <glob.h>
#include <mcheck.h>
#include <nss.h>
#include <pwd.h>
#include <stdlib.h>
#include <string.h>
#include <support/check.h>
#include <support/support.h>
/* Flag which indicates whether to pass the GLOB_ONLYDIR flag. */
static int do_onlydir;
/* Flag which indicates whether to pass the GLOB_NOCHECK flag. */
static int do_nocheck;
/* Flag which indicates whether to pass the GLOB_MARK flag. */
static int do_mark;
/* Flag which indicates whether to pass the GLOB_NOESCAPE flag. */
static int do_noescape;
static void
one_test (const char *prefix, const char *middle, const char *suffix)
{
char *pattern = xasprintf ("%s%s%s", prefix, middle, suffix);
int flags = GLOB_TILDE;
if (do_onlydir)
flags |= GLOB_ONLYDIR;
if (do_nocheck)
flags |= GLOB_NOCHECK;
if (do_mark)
flags |= GLOB_MARK;
if (do_noescape)
flags |= GLOB_NOESCAPE;
glob_t gl;
/* This glob call might result in crashes or memory leaks. */
if (glob (pattern, flags, NULL, &gl) == 0)
globfree (&gl);
free (pattern);
}
enum
{
/* The largest base being tested. */
largest_base_size = 500000,
/* The actual size is the base size plus a variable whose absolute
value is not greater than this. This helps malloc to trigger
overflows. */
max_size_skew = 16,
/* The maximum string length supported by repeating_string
below. */
repeat_size = largest_base_size + max_size_skew,
};
/* Used to construct strings which repeat a single character 'x'. */
static char *repeat;
/* Return a string of SIZE characters. */
const char *
repeating_string (int size)
{
TEST_VERIFY (size >= 0);
TEST_VERIFY (size <= repeat_size);
const char *repeated_shifted = repeat + repeat_size - size;
TEST_VERIFY (strlen (repeated_shifted) == size);
return repeated_shifted;
}
static int
do_test (void)
{
/* Avoid network-based NSS modules and initialize nss_files with a
dummy lookup. This has to come before mtrace because NSS does
not free all memory. */
__nss_configure_lookup ("passwd", "files");
(void) getpwnam ("root");
mtrace ();
repeat = xmalloc (repeat_size + 1);
memset (repeat, 'x', repeat_size);
repeat[repeat_size] = '\0';
/* These numbers control the size of the user name. The values
cover the minimum (0), a typical size (8), a large
stack-allocated size (100000), and a somewhat large
heap-allocated size (largest_base_size). */
static const int base_sizes[] = { 0, 8, 100, 100000, largest_base_size, -1 };
for (do_onlydir = 0; do_onlydir < 2; ++do_onlydir)
for (do_nocheck = 0; do_nocheck < 2; ++do_nocheck)
for (do_mark = 0; do_mark < 2; ++do_mark)
for (do_noescape = 0; do_noescape < 2; ++do_noescape)
for (int base_idx = 0; base_sizes[base_idx] >= 0; ++base_idx)
{
for (int size_skew = -max_size_skew; size_skew <= max_size_skew;
++size_skew)
{
int size = base_sizes[base_idx] + size_skew;
if (size < 0)
continue;
const char *user_name = repeating_string (size);
one_test ("~", user_name, "/a/b");
one_test ("~", user_name, "x\\x\\x////x\\a");
}
const char *user_name = repeating_string (base_sizes[base_idx]);
one_test ("~", user_name, "");
one_test ("~", user_name, "/");
one_test ("~", user_name, "/a");
one_test ("~", user_name, "/*/*");
one_test ("~", user_name, "\\/");
one_test ("/~", user_name, "");
one_test ("*/~", user_name, "/a/b");
}
free (repeat);
return 0;
}
#include <support/test-driver.c>
+5
View File
@@ -40,6 +40,9 @@ ifeq ($(have-thread-library),yes)
extra-libs += libanl
routines += gai_sigqueue
tests += tst-res_hconf_reorder
# This test sends millions of packets and is rather slow.
xtests += tst-resolv-qtypes
endif
extra-libs-others = $(extra-libs)
libresolv-routines := gethnamaddr res_comp res_debug \
@@ -117,3 +120,5 @@ tst-leaks2-ENV = MALLOC_TRACE=$(objpfx)tst-leaks2.mtrace
$(objpfx)mtrace-tst-leaks2.out: $(objpfx)tst-leaks2.out
$(common-objpfx)malloc/mtrace $(objpfx)tst-leaks2.mtrace > $@; \
$(evaluate-test)
$(objpfx)tst-resolv-qtypes: $(objpfx)libresolv.so $(shared-thread-library)
+1 -1
View File
@@ -323,7 +323,7 @@ _nss_dns_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,
int olderr = errno;
enum nss_status status;
int n = __libc_res_nsearch (&_res, name, C_IN, T_UNSPEC,
int n = __libc_res_nsearch (&_res, name, C_IN, T_QUERY_A_AND_AAAA,
host_buffer.buf->buf, 2048, &host_buffer.ptr,
&ans2p, &nans2p, &resplen2, &ans2p_malloced);
if (n >= 0)
+4
View File
@@ -103,6 +103,10 @@ res_nmkquery(res_state statp,
int n;
u_char *dnptrs[20], **dpp, **lastdnptr;
if (class < 0 || class > 65535
|| type < 0 || type > 65535)
return -1;
#ifdef DEBUG
if (statp->options & RES_DEBUG)
printf(";; res_nmkquery(%s, %s, %s, %s)\n",
+3 -3
View File
@@ -122,7 +122,7 @@ __libc_res_nquery(res_state statp,
int n, use_malloc = 0;
u_int oflags = statp->_flags;
size_t bufsize = (type == T_UNSPEC ? 2 : 1) * QUERYSIZE;
size_t bufsize = (type == T_QUERY_A_AND_AAAA ? 2 : 1) * QUERYSIZE;
u_char *buf = alloca (bufsize);
u_char *query1 = buf;
int nquery1 = -1;
@@ -137,7 +137,7 @@ __libc_res_nquery(res_state statp,
printf(";; res_query(%s, %d, %d)\n", name, class, type);
#endif
if (type == T_UNSPEC)
if (type == T_QUERY_A_AND_AAAA)
{
n = res_nmkquery(statp, QUERY, name, class, T_A, NULL, 0, NULL,
query1, bufsize);
@@ -190,7 +190,7 @@ __libc_res_nquery(res_state statp,
if (__builtin_expect (n <= 0, 0) && !use_malloc) {
/* Retry just in case res_nmkquery failed because of too
short buffer. Shouldn't happen. */
bufsize = (type == T_UNSPEC ? 2 : 1) * MAXPACKET;
bufsize = (type == T_QUERY_A_AND_AAAA ? 2 : 1) * MAXPACKET;
buf = malloc (bufsize);
if (buf != NULL) {
query1 = buf;
+185
View File
@@ -0,0 +1,185 @@
/* Exercise low-level query functions with different QTYPEs.
Copyright (C) 2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <resolv.h>
#include <string.h>
#include <support/check.h>
#include <support/check_nss.h>
#include <support/resolv_test.h>
#include <support/support.h>
#include <support/test-driver.h>
#include <support/xmemstream.h>
/* If ture, the response function will send the actual response packet
over TCP instead of UDP. */
static volatile bool force_tcp;
/* Send back a fake resource record matching the QTYPE. */
static void
response (const struct resolv_response_context *ctx,
struct resolv_response_builder *b,
const char *qname, uint16_t qclass, uint16_t qtype)
{
if (force_tcp && ctx->tcp)
{
resolv_response_init (b, (struct resolv_response_flags) { .tc = 1 });
resolv_response_add_question (b, qname, qclass, qtype);
return;
}
resolv_response_init (b, (struct resolv_response_flags) { });
resolv_response_add_question (b, qname, qclass, qtype);
resolv_response_section (b, ns_s_an);
resolv_response_open_record (b, qname, qclass, qtype, 0);
resolv_response_add_data (b, &qtype, sizeof (qtype));
resolv_response_close_record (b);
}
static const const char *domain = "www.example.com";
static int
wrap_res_query (int type, unsigned char *answer, int answer_length)
{
return res_query (domain, C_IN, type, answer, answer_length);
}
static int
wrap_res_search (int type, unsigned char *answer, int answer_length)
{
return res_query (domain, C_IN, type, answer, answer_length);
}
static int
wrap_res_querydomain (int type, unsigned char *answer, int answer_length)
{
return res_querydomain ("www", "example.com", C_IN, type,
answer, answer_length);
}
static int
wrap_res_send (int type, unsigned char *answer, int answer_length)
{
unsigned char buf[512];
int ret = res_mkquery (QUERY, domain, C_IN, type,
(const unsigned char *) "", 0, NULL,
buf, sizeof (buf));
if (type < 0 || type >= 65536)
{
/* res_mkquery fails for out-of-range record types. */
TEST_VERIFY_EXIT (ret == -1);
return -1;
}
TEST_VERIFY_EXIT (ret > 12); /* DNS header length. */
return res_send (buf, ret, answer, answer_length);
}
static int
wrap_res_nquery (int type, unsigned char *answer, int answer_length)
{
return res_nquery (&_res, domain, C_IN, type, answer, answer_length);
}
static int
wrap_res_nsearch (int type, unsigned char *answer, int answer_length)
{
return res_nquery (&_res, domain, C_IN, type, answer, answer_length);
}
static int
wrap_res_nquerydomain (int type, unsigned char *answer, int answer_length)
{
return res_nquerydomain (&_res, "www", "example.com", C_IN, type,
answer, answer_length);
}
static int
wrap_res_nsend (int type, unsigned char *answer, int answer_length)
{
unsigned char buf[512];
int ret = res_nmkquery (&_res, QUERY, domain, C_IN, type,
(const unsigned char *) "", 0, NULL,
buf, sizeof (buf));
if (type < 0 || type >= 65536)
{
/* res_mkquery fails for out-of-range record types. */
TEST_VERIFY_EXIT (ret == -1);
return -1;
}
TEST_VERIFY_EXIT (ret > 12); /* DNS header length. */
return res_nsend (&_res, buf, ret, answer, answer_length);
}
static void
test_function (const char *fname,
int (*func) (int type,
unsigned char *answer, int answer_length))
{
unsigned char buf[512];
for (int tcp = 0; tcp < 2; ++tcp)
{
force_tcp = tcp;
for (unsigned int type = 1; type <= 65535; ++type)
{
if (test_verbose)
printf ("info: sending QTYPE %d with %s (tcp=%d)\n",
type, fname, tcp);
int ret = func (type, buf, sizeof (buf));
if (ret != 47)
FAIL_EXIT1 ("%s tcp=%d qtype=%d return value %d",
fname,tcp, type, ret);
/* One question, one answer record. */
TEST_VERIFY (memcmp (buf + 4, "\0\1\0\1\0\0\0\0", 8) == 0);
/* Question section. */
static const char qname[] = "\3www\7example\3com";
size_t qname_length = sizeof (qname);
TEST_VERIFY (memcmp (buf + 12, qname, qname_length) == 0);
/* RDATA part of answer. */
uint16_t type16 = type;
TEST_VERIFY (memcmp (buf + ret - 2, &type16, sizeof (type16)) == 0);
}
}
TEST_VERIFY (func (-1, buf, sizeof (buf) == -1));
TEST_VERIFY (func (65536, buf, sizeof (buf) == -1));
}
static int
do_test (void)
{
struct resolv_redirect_config config =
{
.response_callback = response,
};
struct resolv_test *obj = resolv_test_start (config);
test_function ("res_query", &wrap_res_query);
test_function ("res_search", &wrap_res_search);
test_function ("res_querydomain", &wrap_res_querydomain);
test_function ("res_send", &wrap_res_send);
test_function ("res_nquery", &wrap_res_nquery);
test_function ("res_nsearch", &wrap_res_nsearch);
test_function ("res_nquerydomain", &wrap_res_nquerydomain);
test_function ("res_nsend", &wrap_res_nsend);
resolv_test_end (obj);
return 0;
}
#define TIMEOUT 300
#include <support/test-driver.c>
+110
View File
@@ -0,0 +1,110 @@
#!/bin/bash
# Create a patch which backports the support/ subdirectory.
# Copyright (C) 2017 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
# The GNU C Library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
# The GNU C Library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public
# License along with the GNU C Library; if not, see
# <http://www.gnu.org/licenses/>.
# This script does not backport the Makefile tweaks outside the
# support/ directory (which need to be backported separately), or the
# changes to test-skeleton.c (which should not be backported).
set -e
export LC_ALL=C
export GIT_CONFIG=/dev/null
export GTT_CONFIG_NOSYSTEM=0
export GIT_PAGER=
usage () {
cat >&2 <<EOF
usage: $0 {patch|commit}
EOF
exit 1
}
if test $# -ne 1 ; then
usage
fi
command="$1"
case "$command" in
patch|commit)
;;
*)
usage
;;
esac
# The upstream branch to work on.
branch=origin/master
# The commit which added the support/ directory.
initial_commit=c23de0aacbeaa7a091609b35764bed931475a16d
# We backport the support directory and this script. Directories need
# to end in a /.
patch_targets="support/ scripts/backport-support.sh"
latest_commit="$(git log --max-count=1 --pretty=format:%H "$branch" -- \
$patch_targets)"
# Simplify the branch name somewhat for reporting.
branch_name="$(echo "$branch" | sed s,^origin/,,)"
command_patch () {
cat <<EOF
This patch creates the contents of the support/ directory up to this
upstream commit on the $branch_name branch:
EOF
git log --max-count=1 "$latest_commit"
echo
git diff "$initial_commit"^.."$latest_commit" $patch_targets
echo "# Before applying the patch, run this command:" >&2
echo "# rm -rf $patch_targets" >&2
}
command_commit () {
git status --porcelain | while read line ; do
echo "error: working copy is not clean, cannot commit" >&2
exit 1
done
for path in $patch_targets; do
echo "# Processing $path" >&2
case "$path" in
[a-zA-Z0-9]*/)
# Directory.
git rm --cached --ignore-unmatch -r "$path"
rm -rf "$path"
git read-tree --prefix="$path" "$latest_commit":"$path"
git checkout "$path"
;;
*)
# File.
git show "$latest_commit":"$path" > "$path"
git add "$path"
esac
done
git commit -m "Synchronize support/ infrastructure with $branch_name
This commit updates the support/ subdirectory to
commit $latest_commit
on the $branch_name branch.
"
}
command_$command
+1 -1
View File
@@ -77,7 +77,7 @@ tests := tst-strtol tst-strtod testmb testrand testsort testdiv \
tst-tininess tst-strtod-underflow tst-tls-atexit \
tst-setcontext3 tst-tls-atexit-nodelete \
tst-strtol-locale tst-strtod-nan-locale tst-strfmon_l \
tst-quick_exit tst-thread-quick_exit
tst-quick_exit tst-thread-quick_exit test-bz22786
tests-static := tst-secure-getenv
ifeq ($(have-cxx-thread_local),yes)
CFLAGS-tst-quick_exit.o = -std=c++11
+1 -1
View File
@@ -181,7 +181,7 @@ __realpath (const char *name, char *resolved)
extra_buf = __alloca (path_max);
len = strlen (end);
if ((long int) (n + len) >= path_max)
if (path_max - n <= len)
{
__set_errno (ENAMETOOLONG);
goto error;
+90
View File
@@ -0,0 +1,90 @@
/* Bug 22786: test for buffer overflow in realpath.
Copyright (C) 2018 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
/* This file must be run from within a directory called "stdlib". */
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <support/test-driver.h>
#include <libc-internal.h>
static int
do_test (void)
{
const char dir[] = "bz22786";
const char lnk[] = "bz22786/symlink";
rmdir (dir);
if (mkdir (dir, 0755) != 0 && errno != EEXIST)
{
printf ("mkdir %s: %m\n", dir);
return EXIT_FAILURE;
}
if (symlink (".", lnk) != 0 && errno != EEXIST)
{
printf ("symlink (%s, %s): %m\n", dir, lnk);
return EXIT_FAILURE;
}
const size_t path_len = (size_t) INT_MAX + 1;
DIAG_PUSH_NEEDS_COMMENT;
#if __GNUC_PREREQ (7, 0)
/* GCC 7 warns about too-large allocations; here we need such
allocation to succeed for the test to work. */
DIAG_IGNORE_NEEDS_COMMENT (7, "-Walloc-size-larger-than=");
#endif
char *path = malloc (path_len);
DIAG_POP_NEEDS_COMMENT;
if (path == NULL)
{
printf ("malloc (%zu): %m\n", path_len);
return EXIT_UNSUPPORTED;
}
/* Construct very long path = "bz22786/symlink/aaaa....." */
char *p = mempcpy (path, lnk, sizeof (lnk) - 1);
*(p++) = '/';
memset (p, 'a', path_len - (path - p) - 2);
p[path_len - (path - p) - 1] = '\0';
/* This call crashes before the fix for bz22786 on 32-bit platforms. */
p = realpath (path, NULL);
if (p != NULL || errno != ENAMETOOLONG)
{
printf ("realpath: %s (%m)", p);
return EXIT_FAILURE;
}
/* Cleanup. */
unlink (lnk);
rmdir (dir);
return 0;
}
#define TEST_FUNCTION do_test
#include <support/test-driver.c>
+57
View File
@@ -245,6 +245,60 @@ do_random_tests (void)
}
}
static void
do_test2 (void)
{
size_t size = 0x20000000;
uint32_t * large_buf;
large_buf = mmap ((void*) 0x70000000, size, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANON, -1, 0);
if (large_buf == MAP_FAILED)
error (77, errno, "Large mmap failed");
if ((uintptr_t) large_buf > 0x80000000 - 128
|| 0x80000000 - (uintptr_t) large_buf > 0x20000000)
{
error (0, 0, "Large mmap allocated improperly");
ret = 77;
munmap ((void *) large_buf, size);
return;
}
size_t bytes_move = 0x80000000 - (uintptr_t) large_buf;
size_t arr_size = bytes_move / sizeof (uint32_t);
size_t i;
FOR_EACH_IMPL (impl, 0)
{
for (i = 0; i < arr_size; i++)
large_buf[i] = (uint32_t) i;
uint32_t * dst = &large_buf[33];
#ifdef TEST_BCOPY
CALL (impl, (char *) large_buf, (char *) dst, bytes_move);
#else
CALL (impl, (char *) dst, (char *) large_buf, bytes_move);
#endif
for (i = 0; i < arr_size; i++)
{
if (dst[i] != (uint32_t) i)
{
error (0, 0,
"Wrong result in function %s dst \"%p\" src \"%p\" offset \"%zd\"",
impl->name, dst, large_buf, i);
ret = 1;
break;
}
}
}
munmap ((void *) large_buf, size);
}
int
test_main (void)
{
@@ -284,6 +338,9 @@ test_main (void)
}
do_random_tests ();
do_test2 ();
return ret;
}
+1
View File
@@ -18,6 +18,7 @@
<http://www.gnu.org/licenses/>. */
#define MEMCPY_RESULT(dst, len) (dst) + (len)
#define MIN_PAGE_SIZE 131072
#define TEST_MAIN
#define TEST_NAME "mempcpy"
#include "test-string.h"
+13 -1
View File
@@ -96,13 +96,18 @@ rpcgen-objs = rpc_main.o rpc_hout.o rpc_cout.o rpc_parse.o \
extra-objs = $(rpcgen-objs) $(addprefix cross-,$(rpcgen-objs))
others += rpcgen
tests = tst-xdrmem tst-xdrmem2 test-rpcent
tests = tst-xdrmem tst-xdrmem2 test-rpcent tst-udp-error
xtests := tst-getmyaddr
ifeq ($(have-thread-library),yes)
xtests += thrsvc
endif
ifeq ($(run-built-tests),yes)
rpcgen-tests := $(objpfx)bug20790.out
tests-special += $(rpcgen-tests)
endif
headers += $(rpcsvc:%.x=rpcsvc/%.h)
extra-libs := librpcsvc
extra-libs-others := librpcsvc # Make it in `others' pass, not `lib' pass.
@@ -153,6 +158,7 @@ BUILD_CPPFLAGS += $(sunrpc-CPPFLAGS)
$(objpfx)tst-getmyaddr: $(common-objpfx)linkobj/libc.so
$(objpfx)tst-xdrmem: $(common-objpfx)linkobj/libc.so
$(objpfx)tst-xdrmem2: $(common-objpfx)linkobj/libc.so
$(objpfx)tst-udp-error: $(common-objpfx)linkobj/libc.so
$(objpfx)rpcgen: $(addprefix $(objpfx),$(rpcgen-objs))
@@ -225,3 +231,9 @@ endif
endif
$(objpfx)thrsvc: $(common-objpfx)linkobj/libc.so $(shared-thread-library)
ifeq ($(run-built-tests),yes)
$(rpcgen-tests): $(objpfx)%.out: %.x $(objpfx)rpcgen
$(built-program-cmd) -c $< -o $@; \
$(evaluate-test)
endif
+1
View File
@@ -0,0 +1 @@
program TPROG { version TVERS { int FUNC(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) = 1; } = 1; } = 1;
+1 -1
View File
@@ -421,9 +421,9 @@ send_again:
cmsg = CMSG_NXTHDR (&msg, cmsg))
if (cmsg->cmsg_level == SOL_IP && cmsg->cmsg_type == IP_RECVERR)
{
free (cbuf);
e = (struct sock_extended_err *) CMSG_DATA(cmsg);
cu->cu_error.re_errno = e->ee_errno;
free (cbuf);
return (cu->cu_error.re_status = RPC_CANTRECV);
}
free (cbuf);
+1 -1
View File
@@ -521,7 +521,7 @@ static void
get_prog_declaration (declaration * dec, defkind dkind, int num /* arg number */ )
{
token tok;
char name[10]; /* argument name */
char name[MAXLINESIZE]; /* argument name */
if (dkind == DEF_PROGRAM)
{
+62
View File
@@ -0,0 +1,62 @@
/* Check for use-after-free in clntudp_call (bug 21115).
Copyright (C) 2017 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <netinet/in.h>
#include <rpc/clnt.h>
#include <rpc/svc.h>
#include <support/check.h>
#include <support/namespace.h>
#include <support/xsocket.h>
#include <unistd.h>
static int
do_test (void)
{
support_become_root ();
support_enter_network_namespace ();
/* Obtain a likely-unused port number. */
struct sockaddr_in sin =
{
.sin_family = AF_INET,
.sin_addr.s_addr = htonl (INADDR_LOOPBACK),
};
{
int fd = xsocket (AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
xbind (fd, (struct sockaddr *) &sin, sizeof (sin));
socklen_t sinlen = sizeof (sin);
xgetsockname (fd, (struct sockaddr *) &sin, &sinlen);
/* Close the socket, so that we will receive an error below. */
close (fd);
}
int sock = RPC_ANYSOCK;
CLIENT *clnt = clntudp_create
(&sin, 1, 2, (struct timeval) { 1, 0 }, &sock);
TEST_VERIFY_EXIT (clnt != NULL);
TEST_VERIFY (clnt_call (clnt, 3,
(xdrproc_t) xdr_void, NULL,
(xdrproc_t) xdr_void, NULL,
((struct timeval) { 3, 0 }))
== RPC_CANTRECV);
clnt_destroy (clnt);
return 0;
}
#include <support/test-driver.c>
+146
View File
@@ -0,0 +1,146 @@
# Makefile for support library, used only at build and test time
# Copyright (C) 2016-2017 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
# The GNU C Library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
# The GNU C Library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public
# License along with the GNU C Library; if not, see
# <http://www.gnu.org/licenses/>.
subdir := support
include ../Makeconfig
extra-libs := libsupport
extra-libs-others = $(extra-libs)
extra-libs-noinstall := $(extra-libs)
libsupport-routines = \
check \
check_addrinfo \
check_dns_packet \
check_hostent \
check_netent \
delayed_exit \
ignore_stderr \
oom_error \
resolv_test \
set_fortify_handler \
support-xstat \
support_become_root \
support_can_chroot \
support_capture_subprocess \
support_capture_subprocess_check \
support_enter_network_namespace \
support_format_address_family \
support_format_addrinfo \
support_format_dns_packet \
support_format_herrno \
support_format_hostent \
support_format_netent \
support_isolate_in_subprocess \
support_record_failure \
support_run_diff \
support_shared_allocate \
support_write_file_string \
support_test_main \
support_test_verify_impl \
temp_file \
write_message \
xaccept \
xaccept4 \
xasprintf \
xbind \
xcalloc \
xchroot \
xclose \
xconnect \
xdup2 \
xfclose \
xfopen \
xfork \
xgetsockname \
xlisten \
xmalloc \
xmemstream \
xmkdir \
xmmap \
xmunmap \
xopen \
xpipe \
xpoll \
xpthread_attr_destroy \
xpthread_attr_init \
xpthread_attr_setdetachstate \
xpthread_attr_setstacksize \
xpthread_barrier_destroy \
xpthread_barrier_init \
xpthread_barrier_wait \
xpthread_cancel \
xpthread_check_return \
xpthread_cond_wait \
xpthread_create \
xpthread_detach \
xpthread_join \
xpthread_mutex_consistent \
xpthread_mutex_destroy \
xpthread_mutex_init \
xpthread_mutex_lock \
xpthread_mutex_unlock \
xpthread_mutexattr_destroy \
xpthread_mutexattr_init \
xpthread_mutexattr_setprotocol \
xpthread_mutexattr_setpshared \
xpthread_mutexattr_setrobust \
xpthread_mutexattr_settype \
xpthread_once \
xpthread_sigmask \
xpthread_spin_lock \
xpthread_spin_unlock \
xrealloc \
xrecvfrom \
xsendto \
xsetsockopt \
xsocket \
xstrdup \
xwaitpid \
xwrite \
libsupport-static-only-routines := $(libsupport-routines)
# Only build one variant of the library.
libsupport-inhibit-o := .os
ifeq ($(build-shared),yes)
libsupport-inhibit-o += .o
endif
tests = \
README-testing \
tst-support-namespace \
tst-support_capture_subprocess \
tst-support_format_dns_packet \
tst-support_record_failure \
ifeq ($(run-built-tests),yes)
tests-special = \
$(objpfx)tst-support_record_failure-2.out
$(objpfx)tst-support_record_failure-2.out: tst-support_record_failure-2.sh \
$(objpfx)tst-support_record_failure
$(SHELL) $< $(common-objpfx) '$(test-program-prefix-before-env)' \
'$(run-program-env)' '$(test-program-prefix-after-env)' \
> $@; \
$(evaluate-test)
endif
$(objpfx)tst-support_format_dns_packet: $(common-objpfx)resolv/libresolv.so
include ../Rules
+29
View File
@@ -0,0 +1,29 @@
This subdirectory contains infrastructure which is not put into
installed libraries, but may be linked into programs (installed or
not) and tests.
# Error-checking wrappers
These wrappers test for error return codes an terminate the process on
error. They are declared in these header files:
* support.h
* xsignal.h
* xthread.h
In general, new wrappers should be added to support.h if possible.
However, support.h must remain fully compatible with C90 and therefore
cannot include headers which use identifers not reserved in C90. If
the wrappers need additional types, additional headers such as
signal.h need to be introduced.
# Test framework
The test framework provides a main program for tests, including a
timeout for hanging tests. See README-testing.c for a minimal
example, and test-driver.c for details how to use it. The following
header files provide related declarations:
* check.h
* temp_file.h
* test-driver.h
+19
View File
@@ -0,0 +1,19 @@
/* This file contains an example test case which shows minimal use of
the test framework. Additional testing hooks are described in
<support/test-driver.c>. */
/* This function will be called from the test driver. */
static int
do_test (void)
{
if (3 == 5)
/* Indicate failure. */
return 1;
else
/* Indicate success. */
return 0;
}
/* This file references do_test above and contains the definition of
the main function. */
#include <support/test-driver.c>
+61
View File
@@ -0,0 +1,61 @@
/* Capture output from a subprocess.
Copyright (C) 2017 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#ifndef SUPPORT_CAPTURE_SUBPROCESS_H
#define SUPPORT_CAPTURE_SUBPROCESS_H
#include <support/xmemstream.h>
struct support_capture_subprocess
{
struct xmemstream out;
struct xmemstream err;
int status;
};
/* Invoke CALLBACK (CLOSURE) in a subprocess and capture standard
output, standard error, and the exit status. The out.buffer and
err.buffer members in the result are null-terminated strings which
can be examined by the caller (out.out and err.out are NULL). */
struct support_capture_subprocess support_capture_subprocess
(void (*callback) (void *), void *closure);
/* Deallocate the subprocess data captured by
support_capture_subprocess. */
void support_capture_subprocess_free (struct support_capture_subprocess *);
enum support_capture_allow
{
/* No output is allowed. */
sc_allow_none = 0x01,
/* Output to stdout is permitted. */
sc_allow_stdout = 0x02,
/* Output to standard error is permitted. */
sc_allow_stderr = 0x04,
};
/* Check that the subprocess exited with STATUS and that only the
allowed outputs happened. ALLOWED is a combination of
support_capture_allow flags. Report errors under the CONTEXT
message. */
void support_capture_subprocess_check (struct support_capture_subprocess *,
const char *context, int status,
int allowed)
__attribute__ ((nonnull (1, 2)));
#endif /* SUPPORT_CAPTURE_SUBPROCESS_H */
+57
View File
@@ -0,0 +1,57 @@
/* Support code for reporting test results.
Copyright (C) 2016-2017 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <support/check.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <support/test-driver.h>
static void
print_failure (const char *file, int line, const char *format, va_list ap)
{
printf ("error: %s:%d: ", file, line);
vprintf (format, ap);
puts ("");
}
int
support_print_failure_impl (const char *file, int line,
const char *format, ...)
{
support_record_failure ();
va_list ap;
va_start (ap, format);
print_failure (file, line, format, ap);
va_end (ap);
return 1;
}
void
support_exit_failure_impl (int status, const char *file, int line,
const char *format, ...)
{
if (status != EXIT_SUCCESS && status != EXIT_UNSUPPORTED)
support_record_failure ();
va_list ap;
va_start (ap, format);
print_failure (file, line, format, ap);
va_end (ap);
exit (status);
}
+94
View File
@@ -0,0 +1,94 @@
/* Functionality for reporting test results.
Copyright (C) 2016-2017 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#ifndef SUPPORT_CHECK_H
#define SUPPORT_CHECK_H
#include <sys/cdefs.h>
__BEGIN_DECLS
/* Record a test failure, print the failure message to standard output
and return 1. */
#define FAIL_RET(...) \
return support_print_failure_impl (__FILE__, __LINE__, __VA_ARGS__)
/* Print the failure message and terminate the process with STATUS.
Record a the process as failed if STATUS is neither EXIT_SUCCESS
nor EXIT_UNSUPPORTED. */
#define FAIL_EXIT(status, ...) \
support_exit_failure_impl (status, __FILE__, __LINE__, __VA_ARGS__)
/* Record a test failure, print the failure message and terminate with
exit status 1. */
#define FAIL_EXIT1(...) \
support_exit_failure_impl (1, __FILE__, __LINE__, __VA_ARGS__)
/* Print failure message and terminate with as unsupported test (exit
status of 77). */
#define FAIL_UNSUPPORTED(...) \
support_exit_failure_impl (77, __FILE__, __LINE__, __VA_ARGS__)
/* Record a test failure (but continue executing) if EXPR evaluates to
false. */
#define TEST_VERIFY(expr) \
({ \
if (expr) \
; \
else \
support_test_verify_impl (-1, __FILE__, __LINE__, #expr); \
})
/* Record a test failure and exit if EXPR evaluates to false. */
#define TEST_VERIFY_EXIT(expr) \
({ \
if (expr) \
; \
else \
support_test_verify_impl (1, __FILE__, __LINE__, #expr); \
})
int support_print_failure_impl (const char *file, int line,
const char *format, ...)
__attribute__ ((nonnull (1), format (printf, 3, 4)));
void support_exit_failure_impl (int exit_status,
const char *file, int line,
const char *format, ...)
__attribute__ ((noreturn, nonnull (2), format (printf, 4, 5)));
void support_test_verify_impl (int status, const char *file, int line,
const char *expr);
/* Record a test failure. This function returns and does not
terminate the process. The failure counter is stored in a shared
memory mapping, so that failures reported in child processes are
visible to the parent process and test driver. This function
depends on initialization by an ELF constructor, so it can only be
invoked after the test driver has run. Note that this function
does not support reporting failures from a DSO. */
void support_record_failure (void);
/* Internal function called by the test driver. */
int support_report_failure (int status)
__attribute__ ((weak, warn_unused_result));
/* Internal function used to test the failure recording framework. */
void support_record_failure_reset (void);
__END_DECLS
#endif /* SUPPORT_CHECK_H */
+42
View File
@@ -0,0 +1,42 @@
/* Compare struct addrinfo values against a formatted string.
Copyright (C) 2016-2017 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <support/check_nss.h>
#include <stdio.h>
#include <stdlib.h>
#include <support/check.h>
#include <support/format_nss.h>
#include <support/run_diff.h>
void
check_addrinfo (const char *query_description, struct addrinfo *ai, int ret,
const char *expected)
{
char *formatted = support_format_addrinfo (ai, ret);
if (strcmp (formatted, expected) != 0)
{
support_record_failure ();
printf ("error: addrinfo comparison failure\n");
if (query_description != NULL)
printf ("query: %s\n", query_description);
support_run_diff ("expected", expected,
"actual", formatted);
}
free (formatted);
}
+42
View File
@@ -0,0 +1,42 @@
/* Check that a DNS packet buffer has the expected contents.
Copyright (C) 2016-2017 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <support/check_nss.h>
#include <stdio.h>
#include <stdlib.h>
#include <support/check.h>
#include <support/format_nss.h>
#include <support/run_diff.h>
void
check_dns_packet (const char *query_description,
const unsigned char *buffer, size_t length,
const char *expected)
{
char *formatted = support_format_dns_packet (buffer, length);
if (strcmp (formatted, expected) != 0)
{
support_record_failure ();
printf ("error: packet comparison failure\n");
if (query_description != NULL)
printf ("query: %s\n", query_description);
support_run_diff ("expected", expected, "actual", formatted);
}
free (formatted);
}
+42
View File
@@ -0,0 +1,42 @@
/* Compare struct hostent values against a formatted string.
Copyright (C) 2016-2017 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <support/check_nss.h>
#include <stdio.h>
#include <stdlib.h>
#include <support/check.h>
#include <support/format_nss.h>
#include <support/run_diff.h>
void
check_hostent (const char *query_description, struct hostent *h,
const char *expected)
{
char *formatted = support_format_hostent (h);
if (strcmp (formatted, expected) != 0)
{
support_record_failure ();
printf ("error: hostent comparison failure\n");
if (query_description != NULL)
printf ("query: %s\n", query_description);
support_run_diff ("expected", expected,
"actual", formatted);
}
free (formatted);
}
+42
View File
@@ -0,0 +1,42 @@
/* Compare struct netent values against a formatted string.
Copyright (C) 2016-2017 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <support/check_nss.h>
#include <stdio.h>
#include <stdlib.h>
#include <support/check.h>
#include <support/format_nss.h>
#include <support/run_diff.h>
void
check_netent (const char *query_description, struct netent *e,
const char *expected)
{
char *formatted = support_format_netent (e);
if (strcmp (formatted, expected) != 0)
{
support_record_failure ();
printf ("error: netent comparison failure\n");
if (query_description != NULL)
printf ("query: %s\n", query_description);
support_run_diff ("expected", expected,
"actual", formatted);
}
free (formatted);
}
+42
View File
@@ -0,0 +1,42 @@
/* Test verification functions for NSS- and DNS-related data.
Copyright (C) 2016-2017 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#ifndef SUPPORT_CHECK_NSS_H
#define SUPPORT_CHECK_NSS_H
#include <netdb.h>
#include <sys/cdefs.h>
__BEGIN_DECLS
/* Compare the data structures against the expected values (which have
to be formatted according to the support_format_* functions in
<support/format_nss.h>). If there is a difference, a delayed test
failure is recorded, and a diff is written to standard output. */
void check_addrinfo (const char *query_description,
struct addrinfo *, int ret, const char *expected);
void check_dns_packet (const char *query_description,
const unsigned char *, size_t, const char *expected);
void check_hostent (const char *query_description,
struct hostent *, const char *expected);
void check_netent (const char *query_description,
struct netent *, const char *expected);
__END_DECLS
#endif /* SUPPORT_CHECK_NSS_H */
+55
View File
@@ -0,0 +1,55 @@
/* Time-triggered process termination.
Copyright (C) 2016-2017 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <support/xthread.h>
#include <support/xsignal.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <support/check.h>
#include <time.h>
static void *
delayed_exit_thread (void *seconds_as_ptr)
{
int seconds = (uintptr_t) seconds_as_ptr;
struct timespec delay = { seconds, 0 };
struct timespec remaining = { 0 };
if (nanosleep (&delay, &remaining) != 0)
FAIL_EXIT1 ("nanosleep: %m");
/* Exit the process sucessfully. */
exit (0);
return NULL;
}
void
delayed_exit (int seconds)
{
/* Create the new thread with all signals blocked. */
sigset_t all_blocked;
sigfillset (&all_blocked);
sigset_t old_set;
xpthread_sigmask (SIG_SETMASK, &all_blocked, &old_set);
/* Create a detached thread. */
pthread_t thr = xpthread_create
(NULL, delayed_exit_thread, (void *) (uintptr_t) seconds);
xpthread_detach (thr);
/* Restore the original signal mask. */
xpthread_sigmask (SIG_SETMASK, &old_set, NULL);
}
+41
View File
@@ -0,0 +1,41 @@
/* String formatting functions for NSS- and DNS-related data.
Copyright (C) 2016-2017 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#ifndef SUPPORT_FORMAT_NSS_H
#define SUPPORT_FORMAT_NSS_H
#include <netdb.h>
#include <sys/cdefs.h>
__BEGIN_DECLS
/* The following functions format their arguments as human-readable
strings (which can span multiple lines). The caller must free the
returned buffer. For NULL pointers or failure status arguments,
error variables such as h_errno and errno are included in the
result. */
char *support_format_address_family (int);
char *support_format_addrinfo (struct addrinfo *, int ret);
char *support_format_dns_packet (const unsigned char *buffer, size_t length);
char *support_format_herrno (int);
char *support_format_hostent (struct hostent *);
char *support_format_netent (struct netent *);
__END_DECLS
#endif /* SUPPORT_FORMAT_NSS_H */
+38
View File
@@ -0,0 +1,38 @@
/* Avoid all the buffer overflow messages on stderr.
Copyright (C) 2015-2017 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <support/support.h>
#include <fcntl.h>
#include <paths.h>
#include <stdlib.h>
#include <unistd.h>
void
ignore_stderr (void)
{
int fd = open (_PATH_DEVNULL, O_WRONLY);
if (fd == -1)
close (STDERR_FILENO);
else
{
dup2 (fd, STDERR_FILENO);
close (fd);
}
setenv ("LIBC_FATAL_STDERR_", "1", 1);
}
+65
View File
@@ -0,0 +1,65 @@
/* Entering namespaces for test case isolation.
Copyright (C) 2016-2017 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#ifndef SUPPORT_NAMESPACE_H
#define SUPPORT_NAMESPACE_H
#include <stdbool.h>
#include <sys/cdefs.h>
__BEGIN_DECLS
/* Attempts to become root (or acquire root-like privileges), possibly
with the help of user namespaces. Return true if (restricted) root
privileges could be attained in some way. Print diagnostics to
standard output.
Note that this function generally has to be called before a process
becomes multi-threaded, otherwise it may fail with insufficient
privileges on systems which would support this operation for
single-threaded processes. */
bool support_become_root (void);
/* Return true if this process can perform a chroot operation. In
general, this is only possible if support_become_root has been
called. Note that the actual test is performed in a subprocess,
after fork, so that the file system root of the original process is
not changed. */
bool support_can_chroot (void);
/* Enter a network namespace (and a UTS namespace if possible) and
configure the loopback interface. Return true if a network
namespace could be created. Print diagnostics to standard output.
If a network namespace could be created, but networking in it could
not be configured, terminate the process. It is recommended to
call support_become_root before this function so that the process
has sufficient privileges. */
bool support_enter_network_namespace (void);
/* Return true if support_enter_network_namespace managed to enter a
UTS namespace. */
bool support_in_uts_namespace (void);
/* Invoke CALLBACK (CLOSURE) in a subprocess created using fork.
Terminate the calling process if the subprocess exits with a
non-zero exit status. */
void support_isolate_in_subprocess (void (*callback) (void *), void *closure);
__END_DECLS
#endif
@@ -1,7 +1,6 @@
/* Compute positive difference, sparc 64-bit.
Copyright (C) 2013-2016 Free Software Foundation, Inc.
/* Reporting out-of-memory errors.
Copyright (C) 2016-2017 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by David S. Miller <davem@davemloft.net>.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -17,15 +16,14 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <sysdep.h>
#include <support/support.h>
ENTRY(__fdimf)
fcmps %f1, %f3
fbug 1f
nop
fzeros %f1
fnegs %f1, %f3
1: retl
fsubs %f1, %f3, %f0
END(__fdimf)
weak_alias (__fdimf, fdimf)
#include <stdio.h>
#include <stdlib.h>
void
oom_error (const char *function, size_t size)
{
printf ("%s: unable to allocate %zu bytes: %m\n", function, size);
exit (1);
}
File diff suppressed because it is too large Load Diff
+180
View File
@@ -0,0 +1,180 @@
/* DNS test framework and libresolv redirection.
Copyright (C) 2016-2017 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#ifndef SUPPORT_RESOLV_TEST_H
#define SUPPORT_RESOLV_TEST_H
#include <arpa/nameser.h>
#include <stdbool.h>
#include <sys/cdefs.h>
__BEGIN_DECLS
/* Information about EDNS properties of a DNS query. */
struct resolv_edns_info
{
bool active;
uint8_t extended_rcode;
uint8_t version;
uint16_t flags;
uint16_t payload_size;
};
/* This struct provides context information when the response callback
specified in struct resolv_redirect_config is invoked. */
struct resolv_response_context
{
const unsigned char *query_buffer;
size_t query_length;
int server_index;
bool tcp;
struct resolv_edns_info edns;
};
/* This opaque struct is used to construct responses from within the
response callback function. */
struct resolv_response_builder;
/* This opaque struct collects information about the resolver testing
currently in progress. */
struct resolv_test;
enum
{
/* Maximum number of test servers supported by the framework. */
resolv_max_test_servers = 3,
};
/* Configuration settings specific to individual test servers. */
struct resolv_redirect_server_config
{
bool disable_tcp; /* If true, no TCP server is listening. */
bool disable_udp; /* If true, no UDP server is listening. */
};
/* Instructions for setting up the libresolv redirection. */
struct resolv_redirect_config
{
/* The response_callback function is called for every incoming DNS
packet, over UDP or TCP. It must be specified, the other
configuration settings are optional. */
void (*response_callback) (const struct resolv_response_context *,
struct resolv_response_builder *,
const char *qname,
uint16_t qclass, uint16_t qtype);
/* Per-server configuration. */
struct resolv_redirect_server_config servers[resolv_max_test_servers];
/* Search path entries. The first entry serves as the default
domain name as well. */
const char *search[7];
/* Number of servers to activate in resolv. 0 means the default,
resolv_max_test_servers. */
int nscount;
/* If true, use a single thread to process all UDP queries. This
may results in more predictable ordering of queries and
responses. */
bool single_thread_udp;
};
/* Configure NSS to use, nss_dns only for aplicable databases, and try
to put the process into a network namespace for better isolation.
This may have to be called before resolv_test_start, before the
process creates any threads. Otherwise, initialization is
performed by resolv_test_start implicitly. */
void resolv_test_init (void);
/* Initiate resolver testing. This updates the _res variable as
needed. As a side effect, NSS is reconfigured to use nss_dns only
for aplicable databases, and the process may enter a network
namespace for better isolation. */
struct resolv_test *resolv_test_start (struct resolv_redirect_config);
/* Call this function at the end of resolver testing, to free
resources and report pending errors (if any). */
void resolv_test_end (struct resolv_test *);
/* The remaining facilities in this file are used for constructing
response packets from the response_callback function. */
/* Special settings for constructing responses from the callback. */
struct resolv_response_flags
{
/* 4-bit response code to incorporate into the response. */
unsigned char rcode;
/* If true, the TC (truncation) flag will be set. */
bool tc;
/* Initial section count values. Can be used to artificially
increase the counts, for malformed packet testing.*/
unsigned short qdcount;
unsigned short ancount;
unsigned short nscount;
unsigned short adcount;
};
/* Begin a new response with the requested flags. Must be called
first. */
void resolv_response_init (struct resolv_response_builder *,
struct resolv_response_flags);
/* Switches to the section in the response packet. Only forward
movement is supported. */
void resolv_response_section (struct resolv_response_builder *, ns_sect);
/* Add a question record to the question section. */
void resolv_response_add_question (struct resolv_response_builder *,
const char *name, uint16_t class,
uint16_t type);
/* Starts a new resource record with the specified owner name, class,
type, and TTL. Data is supplied with resolv_response_add_data or
resolv_response_add_name. */
void resolv_response_open_record (struct resolv_response_builder *,
const char *name, uint16_t class,
uint16_t type, uint32_t ttl);
/* Add unstructed bytes to the RDATA part of a resource record. */
void resolv_response_add_data (struct resolv_response_builder *,
const void *, size_t);
/* Add a compressed domain name to the RDATA part of a resource
record. */
void resolv_response_add_name (struct resolv_response_builder *,
const char *name);
/* Mark the end of the constructed record. Must be called last. */
void resolv_response_close_record (struct resolv_response_builder *);
/* Drop this query packet (that is, do not send a response, not even
an empty packet). */
void resolv_response_drop (struct resolv_response_builder *);
/* In TCP mode, close the connection after this packet (if a response
is sent). */
void resolv_response_close (struct resolv_response_builder *);
/* The size of the response packet built so far. */
size_t resolv_response_length (const struct resolv_response_builder *);
__END_DECLS
#endif /* SUPPORT_RESOLV_TEST_H */
+31
View File
@@ -0,0 +1,31 @@
/* Invoke the system diff tool to compare two strings.
Copyright (C) 2016-2017 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#ifndef SUPPORT_RUN_DIFF_H
#define SUPPORT_RUN_DIFF_H
/* Compare the two NUL-terminated strings LEFT and RIGHT using the
diff tool. Label the sides of the diff with LEFT_LABEL and
RIGHT_LABEL, respectively.
This function assumes that LEFT and RIGHT are different
strings. */
void support_run_diff (const char *left_label, const char *left,
const char *right_label, const char *right);
#endif /* SUPPORT_RUN_DIFF_H */
+34
View File
@@ -0,0 +1,34 @@
/* Set signal handler for use in fortify tests.
Copyright (C) 2016-2017 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <support/support.h>
#include <signal.h>
void
set_fortify_handler (void (*handler) (int sig))
{
struct sigaction sa;
sa.sa_handler = handler;
sa.sa_flags = 0;
sigemptyset (&sa.sa_mask);
sigaction (SIGABRT, &sa, NULL);
ignore_stderr ();
}

Some files were not shown because too many files have changed in this diff Show More