forked from pool/glibc
Andreas Schwab
4d4a3834ee
- ld-show-auxv-colon.patch: elf: Fix missing colon in LD_SHOW_AUXV output (BZ #282539 - x86-string-control-test.patch: x86-64: Use testl to check __x86_string_control - pthread-kill-fail-after-exit.patch: nptl: pthread_kill, pthread_cancel should not fail after exit (BZ #19193) - pthread-kill-race-thread-exit.patch: nptl: Fix race between pthread_kill and thread exit (BZ #12889) - getcwd-attribute-access.patch: posix: Fix attribute access mode on getcwd (BZ #27476) - pthread-kill-return-esrch.patch: nptl: pthread_kill needs to return ESRCH for old programs (BZ #19193) - pthread-mutexattr-getrobust-np-type.patch: nptl: Fix type of pthread_mutexattr_getrobust_np, pthread_mutexattr_setrobust_np (BZ #28036) - setxid-deadlock-blocked-signals.patch: nptl: Avoid setxid deadlock with blocked signals in thread exit (BZ #28361) - pthread-kill-send-specific-thread.patch: nptl: pthread_kill must send signals to a specific thread (BZ #28407) - sysconf-nprocessors-affinity.patch: linux: Revert the use of sched_getaffinity on get_nproc (BZ #28310) - iconv-charmap-close-output.patch: renamed from icon-charmap-close-output.patch OBS-URL: https://build.opensuse.org/request/show/923222 OBS-URL: https://build.opensuse.org/package/show/Base:System/glibc?expand=0&rev=604
161 lines
5.5 KiB
Diff
161 lines
5.5 KiB
Diff
From 40bade26d5bcbda3d21fb598c5063d9df62de966 Mon Sep 17 00:00:00 2001
|
|
From: Florian Weimer <fweimer@redhat.com>
|
|
Date: Fri, 1 Oct 2021 18:16:41 +0200
|
|
Subject: [PATCH] nptl: pthread_kill must send signals to a specific thread [BZ
|
|
#28407]
|
|
|
|
The choice between the kill vs tgkill system calls is not just about
|
|
the TID reuse race, but also about whether the signal is sent to the
|
|
whole process (and any thread in it) or to a specific thread.
|
|
|
|
This was caught by the openposix test suite:
|
|
|
|
LTP: openposix test suite - FAIL: SIGUSR1 is member of new thread pendingset.
|
|
<https://gitlab.com/cki-project/kernel-tests/-/issues/764>
|
|
|
|
Fixes commit 526c3cf11ee9367344b6b15d669e4c3cb461a2be ("nptl: Fix race
|
|
between pthread_kill and thread exit (bug 12889)").
|
|
|
|
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
|
|
Tested-by: Carlos O'Donell <carlos@redhat.com>
|
|
(cherry picked from commit eae81d70574e923ce3c59078b8df857ae192efa6)
|
|
---
|
|
NEWS | 1 +
|
|
nptl/pthread_kill.c | 4 +-
|
|
sysdeps/pthread/Makefile | 1 +
|
|
.../pthread/tst-pthread-raise-blocked-self.c | 92 +++++++++++++++++++
|
|
4 files changed, 95 insertions(+), 3 deletions(-)
|
|
create mode 100644 sysdeps/pthread/tst-pthread-raise-blocked-self.c
|
|
|
|
Index: glibc-2.34/nptl/pthread_kill.c
|
|
===================================================================
|
|
--- glibc-2.34.orig/nptl/pthread_kill.c
|
|
+++ glibc-2.34/nptl/pthread_kill.c
|
|
@@ -40,7 +40,7 @@ __pthread_kill_implementation (pthread_t
|
|
below. POSIX only guarantees delivery of a single signal,
|
|
which may not be the right one.) */
|
|
pid_t tid = INTERNAL_SYSCALL_CALL (gettid);
|
|
- int ret = INTERNAL_SYSCALL_CALL (kill, tid, signo);
|
|
+ int ret = INTERNAL_SYSCALL_CALL (tgkill, __getpid (), tid, signo);
|
|
return INTERNAL_SYSCALL_ERROR_P (ret) ? INTERNAL_SYSCALL_ERRNO (ret) : 0;
|
|
}
|
|
|
|
@@ -59,8 +59,6 @@ __pthread_kill_implementation (pthread_t
|
|
ret = no_tid;
|
|
else
|
|
{
|
|
- /* Using tgkill is a safety measure. pd->exit_lock ensures that
|
|
- the target thread cannot exit. */
|
|
ret = INTERNAL_SYSCALL_CALL (tgkill, __getpid (), pd->tid, signo);
|
|
ret = INTERNAL_SYSCALL_ERROR_P (ret) ? INTERNAL_SYSCALL_ERRNO (ret) : 0;
|
|
}
|
|
Index: glibc-2.34/sysdeps/pthread/Makefile
|
|
===================================================================
|
|
--- glibc-2.34.orig/sysdeps/pthread/Makefile
|
|
+++ glibc-2.34/sysdeps/pthread/Makefile
|
|
@@ -120,6 +120,7 @@ tests += tst-cnd-basic tst-mtx-trylock t
|
|
tst-pt-vfork1 tst-pt-vfork2 tst-vfork1x tst-vfork2x \
|
|
tst-pthread-setuid-loop \
|
|
tst-pthread_cancel-select-loop \
|
|
+ tst-pthread-raise-blocked-self \
|
|
tst-pthread_kill-exiting \
|
|
|
|
tests-time64 := \
|
|
Index: glibc-2.34/sysdeps/pthread/tst-pthread-raise-blocked-self.c
|
|
===================================================================
|
|
--- /dev/null
|
|
+++ glibc-2.34/sysdeps/pthread/tst-pthread-raise-blocked-self.c
|
|
@@ -0,0 +1,92 @@
|
|
+/* Test that raise sends signal to current thread even if blocked.
|
|
+ Copyright (C) 2021 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
|
|
+ <https://www.gnu.org/licenses/>. */
|
|
+
|
|
+#include <signal.h>
|
|
+#include <support/check.h>
|
|
+#include <support/xsignal.h>
|
|
+#include <support/xthread.h>
|
|
+#include <pthread.h>
|
|
+#include <unistd.h>
|
|
+
|
|
+/* Used to create a dummy thread ID distinct from all other thread
|
|
+ IDs. */
|
|
+static void *
|
|
+noop (void *ignored)
|
|
+{
|
|
+ return NULL;
|
|
+}
|
|
+
|
|
+static volatile pthread_t signal_thread;
|
|
+
|
|
+static void
|
|
+signal_handler (int signo)
|
|
+{
|
|
+ signal_thread = pthread_self ();
|
|
+}
|
|
+
|
|
+/* Used to ensure that waiting_thread has launched and can accept
|
|
+ signals. */
|
|
+static pthread_barrier_t barrier;
|
|
+
|
|
+static void *
|
|
+waiting_thread (void *ignored)
|
|
+{
|
|
+ xpthread_barrier_wait (&barrier);
|
|
+ pause ();
|
|
+ return NULL;
|
|
+}
|
|
+
|
|
+static int
|
|
+do_test (void)
|
|
+{
|
|
+ xsignal (SIGUSR1, signal_handler);
|
|
+ xpthread_barrier_init (&barrier, NULL, 2);
|
|
+
|
|
+ /* Distinct thread ID value to */
|
|
+ pthread_t dummy = xpthread_create (NULL, noop, NULL);
|
|
+ signal_thread = dummy;
|
|
+
|
|
+ pthread_t helper = xpthread_create (NULL, waiting_thread, NULL);
|
|
+
|
|
+ /* Make sure that the thread is running. */
|
|
+ xpthread_barrier_wait (&barrier);
|
|
+
|
|
+ /* Block signals on this thread. */
|
|
+ sigset_t set;
|
|
+ sigfillset (&set);
|
|
+ xpthread_sigmask (SIG_BLOCK, &set, NULL);
|
|
+
|
|
+ /* Send the signal to this thread. It must not be delivered. */
|
|
+ raise (SIGUSR1);
|
|
+ TEST_VERIFY (signal_thread == dummy);
|
|
+
|
|
+ /* Wait a bit to give a chance for signal delivery (increases
|
|
+ chances of failure with bug 28407). */
|
|
+ usleep (50 * 1000);
|
|
+
|
|
+ /* Unblocking should cause synchronous delivery of the signal. */
|
|
+ xpthread_sigmask (SIG_UNBLOCK, &set, NULL);
|
|
+ TEST_VERIFY (signal_thread == pthread_self ());
|
|
+
|
|
+ xpthread_cancel (helper);
|
|
+ xpthread_join (helper);
|
|
+ xpthread_join (dummy);
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+#include <support/test-driver.c>
|