mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-27 07:20:11 +00:00
d2dc5467c6
This patch filters out the internal NPTL signals (SIGCANCEL/SIGTIMER and SIGSETXID) from signal functions. GLIBC on Linux requires both signals to proper implement pthread cancellation, posix timers, and set*id posix thread synchronization. And not filtering out the internal signal is troublesome: - A conformant program on a architecture that does not filter out the signals might inadvertently disable pthread asynchronous cancellation, set*id synchronization or posix timers. - It might also to security issues if SIGSETXID is masked and set*id functions are called (some threads might have effective user or group id different from the rest). The changes are basically: - Change __is_internal_signal to bool and used on all signal function that has a signal number as input. Also for signal function which accepts signals sets (sigset_t) it assumes that canonical function were used to add/remove signals which lead to some input simplification. - Fix tst-sigset.c to avoid check for SIGCANCEL/SIGTIMER and SIGSETXID. It is rewritten to check each signal indidually and to check realtime signals using canonical macros. - Add generic __clear_internal_signals and __is_internal_signal version since both symbols are used on generic implementations. - Remove superflous sysdeps/nptl/sigfillset.c. - Remove superflous SIGTIMER handling on Linux __is_internal_signal since it is the same of SIGCANCEL. - Remove dangling define and obvious comment on nptl/sigaction.c. Checked on x86_64-linux-gnu. [BZ #22391] * nptl/sigaction.c (__sigaction): Use __is_internal_signal to check for internal nptl signals. * nptl/sigaction.c (__sigaction): Likewise. * signal/sigaddset.c (sigaddset): Likewise. * signal/sigdelset.c (sigdelset): Likewise. * sysdeps/posix/signal.c (__bsd_signal): Likewise. * sysdeps/posix/sigset.c (sigset): Call and check sigaddset return value. * signal/sigfillset.c (sigfillset): User __clear_internal_signals to filter out internal nptl signals. * signal/tst-sigset.c (do_test): Check ech signal indidually and also check realtime signals using standard macros. * sysdeps/generic/internal-signals.h (__clear_internal_signals, __is_internal_signal, __libc_signal_block_all, __libc_signal_block_app, __libc_signal_restore_set): New functions. * sysdeps/nptl/sigfillset.c: Remove file. * sysdeps/unix/sysv/linux/internal-signals.h (__is_internal_signal): Change return to bool. (__clear_internal_signals): Remove SIGTIMER clean since it is equal to SIGCANEL on Linux. * sysdeps/unix/sysv/linux/sigtimedwait.c (__sigtimedwait): Assume signal set was constructed using standard functions. Reported-by: Yury Norov <ynorov@caviumnetworks.com>
92 lines
2.7 KiB
C
92 lines
2.7 KiB
C
/* Special use of signals internally. Linux version.
|
|
Copyright (C) 2014-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/>. */
|
|
|
|
#ifndef __INTERNAL_SIGNALS_H
|
|
# define __INTERNAL_SIGNALS_H
|
|
|
|
#include <signal.h>
|
|
#include <sigsetops.h>
|
|
#include <stdbool.h>
|
|
#include <sysdep.h>
|
|
|
|
/* The signal used for asynchronous cancelation. */
|
|
#define SIGCANCEL __SIGRTMIN
|
|
|
|
|
|
/* Signal needed for the kernel-supported POSIX timer implementation.
|
|
We can reuse the cancellation signal since we can distinguish
|
|
cancellation from timer expirations. */
|
|
#define SIGTIMER SIGCANCEL
|
|
|
|
|
|
/* Signal used to implement the setuid et.al. functions. */
|
|
#define SIGSETXID (__SIGRTMIN + 1)
|
|
|
|
|
|
/* Return is sig is used internally. */
|
|
static inline bool
|
|
__is_internal_signal (int sig)
|
|
{
|
|
return (sig == SIGCANCEL) || (sig == SIGSETXID);
|
|
}
|
|
|
|
/* Remove internal glibc signal from the mask. */
|
|
static inline void
|
|
__clear_internal_signals (sigset_t *set)
|
|
{
|
|
__sigdelset (set, SIGCANCEL);
|
|
__sigdelset (set, SIGSETXID);
|
|
}
|
|
|
|
#define SIGALL_SET \
|
|
((__sigset_t) { .__val = {[0 ... _SIGSET_NWORDS-1 ] = -1 } })
|
|
|
|
/* Block all signals, including internal glibc ones. */
|
|
static inline int
|
|
__libc_signal_block_all (sigset_t *set)
|
|
{
|
|
INTERNAL_SYSCALL_DECL (err);
|
|
return INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_BLOCK, &SIGALL_SET,
|
|
set, _NSIG / 8);
|
|
}
|
|
|
|
/* Block all application signals (excluding internal glibc ones). */
|
|
static inline int
|
|
__libc_signal_block_app (sigset_t *set)
|
|
{
|
|
sigset_t allset = SIGALL_SET;
|
|
__clear_internal_signals (&allset);
|
|
INTERNAL_SYSCALL_DECL (err);
|
|
return INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_BLOCK, &allset, set,
|
|
_NSIG / 8);
|
|
}
|
|
|
|
/* Restore current process signal mask. */
|
|
static inline int
|
|
__libc_signal_restore_set (const sigset_t *set)
|
|
{
|
|
INTERNAL_SYSCALL_DECL (err);
|
|
return INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_SETMASK, set, NULL,
|
|
_NSIG / 8);
|
|
}
|
|
|
|
/* Used to communicate with signal handler. */
|
|
extern struct xid_command *__xidcmd attribute_hidden;
|
|
|
|
#endif
|