License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 14:07:57 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2005-04-16 22:20:36 +00:00
|
|
|
#ifndef _LINUX_SIGNAL_H
|
|
|
|
#define _LINUX_SIGNAL_H
|
|
|
|
|
2014-10-13 22:53:33 +00:00
|
|
|
#include <linux/bug.h>
|
2017-02-03 22:43:50 +00:00
|
|
|
#include <linux/signal_types.h>
|
2017-06-03 19:00:59 +00:00
|
|
|
#include <linux/string.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-05-20 01:11:53 +00:00
|
|
|
struct task_struct;
|
|
|
|
|
2010-03-10 23:23:59 +00:00
|
|
|
/* for sysctl */
|
|
|
|
extern int print_fatal_signals;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2018-09-25 09:27:20 +00:00
|
|
|
static inline void copy_siginfo(kernel_siginfo_t *to,
|
|
|
|
const kernel_siginfo_t *from)
|
2016-02-08 18:43:50 +00:00
|
|
|
{
|
2017-07-20 02:30:42 +00:00
|
|
|
memcpy(to, from, sizeof(*to));
|
2016-02-08 18:43:50 +00:00
|
|
|
}
|
|
|
|
|
2018-09-25 09:27:20 +00:00
|
|
|
static inline void clear_siginfo(kernel_siginfo_t *info)
|
2017-07-24 20:28:56 +00:00
|
|
|
{
|
|
|
|
memset(info, 0, sizeof(*info));
|
|
|
|
}
|
|
|
|
|
2018-09-25 10:59:31 +00:00
|
|
|
#define SI_EXPANSION_SIZE (sizeof(struct siginfo) - sizeof(struct kernel_siginfo))
|
|
|
|
|
2020-05-05 10:12:54 +00:00
|
|
|
static inline void copy_siginfo_to_external(siginfo_t *to,
|
|
|
|
const kernel_siginfo_t *from)
|
|
|
|
{
|
|
|
|
memcpy(to, from, sizeof(*from));
|
|
|
|
memset(((char *)to) + sizeof(struct kernel_siginfo), 0,
|
|
|
|
SI_EXPANSION_SIZE);
|
|
|
|
}
|
|
|
|
|
2018-09-25 09:27:20 +00:00
|
|
|
int copy_siginfo_to_user(siginfo_t __user *to, const kernel_siginfo_t *from);
|
|
|
|
int copy_siginfo_from_user(kernel_siginfo_t *to, const siginfo_t __user *from);
|
2017-06-03 19:01:01 +00:00
|
|
|
|
2017-07-17 03:36:59 +00:00
|
|
|
enum siginfo_layout {
|
|
|
|
SIL_KILL,
|
|
|
|
SIL_TIMER,
|
|
|
|
SIL_POLL,
|
|
|
|
SIL_FAULT,
|
2018-04-25 01:59:47 +00:00
|
|
|
SIL_FAULT_MCEERR,
|
|
|
|
SIL_FAULT_BNDERR,
|
|
|
|
SIL_FAULT_PKUERR,
|
2017-07-17 03:36:59 +00:00
|
|
|
SIL_CHLD,
|
|
|
|
SIL_RT,
|
|
|
|
SIL_SYS,
|
|
|
|
};
|
|
|
|
|
2018-10-11 01:29:44 +00:00
|
|
|
enum siginfo_layout siginfo_layout(unsigned sig, int si_code);
|
2017-07-17 03:36:59 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Define some primitives to manipulate sigset_t.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __HAVE_ARCH_SIG_BITOPS
|
|
|
|
#include <linux/bitops.h>
|
|
|
|
|
|
|
|
/* We don't use <linux/bitops.h> for these because there is no need to
|
|
|
|
be atomic. */
|
|
|
|
static inline void sigaddset(sigset_t *set, int _sig)
|
|
|
|
{
|
|
|
|
unsigned long sig = _sig - 1;
|
|
|
|
if (_NSIG_WORDS == 1)
|
|
|
|
set->sig[0] |= 1UL << sig;
|
|
|
|
else
|
|
|
|
set->sig[sig / _NSIG_BPW] |= 1UL << (sig % _NSIG_BPW);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void sigdelset(sigset_t *set, int _sig)
|
|
|
|
{
|
|
|
|
unsigned long sig = _sig - 1;
|
|
|
|
if (_NSIG_WORDS == 1)
|
|
|
|
set->sig[0] &= ~(1UL << sig);
|
|
|
|
else
|
|
|
|
set->sig[sig / _NSIG_BPW] &= ~(1UL << (sig % _NSIG_BPW));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int sigismember(sigset_t *set, int _sig)
|
|
|
|
{
|
|
|
|
unsigned long sig = _sig - 1;
|
|
|
|
if (_NSIG_WORDS == 1)
|
|
|
|
return 1 & (set->sig[0] >> sig);
|
|
|
|
else
|
|
|
|
return 1 & (set->sig[sig / _NSIG_BPW] >> (sig % _NSIG_BPW));
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* __HAVE_ARCH_SIG_BITOPS */
|
|
|
|
|
2006-01-08 09:02:48 +00:00
|
|
|
static inline int sigisemptyset(sigset_t *set)
|
|
|
|
{
|
|
|
|
switch (_NSIG_WORDS) {
|
|
|
|
case 4:
|
|
|
|
return (set->sig[3] | set->sig[2] |
|
|
|
|
set->sig[1] | set->sig[0]) == 0;
|
|
|
|
case 2:
|
|
|
|
return (set->sig[1] | set->sig[0]) == 0;
|
|
|
|
case 1:
|
|
|
|
return set->sig[0] == 0;
|
|
|
|
default:
|
2014-10-13 22:53:33 +00:00
|
|
|
BUILD_BUG();
|
2006-01-08 09:02:48 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-14 23:04:10 +00:00
|
|
|
static inline int sigequalsets(const sigset_t *set1, const sigset_t *set2)
|
|
|
|
{
|
|
|
|
switch (_NSIG_WORDS) {
|
|
|
|
case 4:
|
|
|
|
return (set1->sig[3] == set2->sig[3]) &&
|
|
|
|
(set1->sig[2] == set2->sig[2]) &&
|
|
|
|
(set1->sig[1] == set2->sig[1]) &&
|
|
|
|
(set1->sig[0] == set2->sig[0]);
|
|
|
|
case 2:
|
|
|
|
return (set1->sig[1] == set2->sig[1]) &&
|
|
|
|
(set1->sig[0] == set2->sig[0]);
|
|
|
|
case 1:
|
|
|
|
return set1->sig[0] == set2->sig[0];
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
#define sigmask(sig) (1UL << ((sig) - 1))
|
|
|
|
|
|
|
|
#ifndef __HAVE_ARCH_SIG_SETOPS
|
|
|
|
#include <linux/string.h>
|
|
|
|
|
|
|
|
#define _SIG_SET_BINOP(name, op) \
|
|
|
|
static inline void name(sigset_t *r, const sigset_t *a, const sigset_t *b) \
|
|
|
|
{ \
|
|
|
|
unsigned long a0, a1, a2, a3, b0, b1, b2, b3; \
|
|
|
|
\
|
|
|
|
switch (_NSIG_WORDS) { \
|
2014-10-13 22:53:33 +00:00
|
|
|
case 4: \
|
2005-04-16 22:20:36 +00:00
|
|
|
a3 = a->sig[3]; a2 = a->sig[2]; \
|
|
|
|
b3 = b->sig[3]; b2 = b->sig[2]; \
|
|
|
|
r->sig[3] = op(a3, b3); \
|
|
|
|
r->sig[2] = op(a2, b2); \
|
2020-08-23 22:36:59 +00:00
|
|
|
fallthrough; \
|
2014-10-13 22:53:33 +00:00
|
|
|
case 2: \
|
2005-04-16 22:20:36 +00:00
|
|
|
a1 = a->sig[1]; b1 = b->sig[1]; \
|
|
|
|
r->sig[1] = op(a1, b1); \
|
2020-08-23 22:36:59 +00:00
|
|
|
fallthrough; \
|
2014-10-13 22:53:33 +00:00
|
|
|
case 1: \
|
2005-04-16 22:20:36 +00:00
|
|
|
a0 = a->sig[0]; b0 = b->sig[0]; \
|
|
|
|
r->sig[0] = op(a0, b0); \
|
|
|
|
break; \
|
2014-10-13 22:53:33 +00:00
|
|
|
default: \
|
|
|
|
BUILD_BUG(); \
|
2005-04-16 22:20:36 +00:00
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define _sig_or(x,y) ((x) | (y))
|
|
|
|
_SIG_SET_BINOP(sigorsets, _sig_or)
|
|
|
|
|
|
|
|
#define _sig_and(x,y) ((x) & (y))
|
|
|
|
_SIG_SET_BINOP(sigandsets, _sig_and)
|
|
|
|
|
2011-04-27 20:01:27 +00:00
|
|
|
#define _sig_andn(x,y) ((x) & ~(y))
|
|
|
|
_SIG_SET_BINOP(sigandnsets, _sig_andn)
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#undef _SIG_SET_BINOP
|
|
|
|
#undef _sig_or
|
|
|
|
#undef _sig_and
|
2011-04-27 20:01:27 +00:00
|
|
|
#undef _sig_andn
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#define _SIG_SET_OP(name, op) \
|
|
|
|
static inline void name(sigset_t *set) \
|
|
|
|
{ \
|
|
|
|
switch (_NSIG_WORDS) { \
|
2014-10-13 22:53:33 +00:00
|
|
|
case 4: set->sig[3] = op(set->sig[3]); \
|
|
|
|
set->sig[2] = op(set->sig[2]); \
|
2020-08-23 22:36:59 +00:00
|
|
|
fallthrough; \
|
2014-10-13 22:53:33 +00:00
|
|
|
case 2: set->sig[1] = op(set->sig[1]); \
|
2020-08-23 22:36:59 +00:00
|
|
|
fallthrough; \
|
2014-10-13 22:53:33 +00:00
|
|
|
case 1: set->sig[0] = op(set->sig[0]); \
|
2005-04-16 22:20:36 +00:00
|
|
|
break; \
|
2014-10-13 22:53:33 +00:00
|
|
|
default: \
|
|
|
|
BUILD_BUG(); \
|
2005-04-16 22:20:36 +00:00
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define _sig_not(x) (~(x))
|
|
|
|
_SIG_SET_OP(signotset, _sig_not)
|
|
|
|
|
|
|
|
#undef _SIG_SET_OP
|
|
|
|
#undef _sig_not
|
|
|
|
|
|
|
|
static inline void sigemptyset(sigset_t *set)
|
|
|
|
{
|
|
|
|
switch (_NSIG_WORDS) {
|
|
|
|
default:
|
|
|
|
memset(set, 0, sizeof(sigset_t));
|
|
|
|
break;
|
|
|
|
case 2: set->sig[1] = 0;
|
2020-08-23 22:36:59 +00:00
|
|
|
fallthrough;
|
2005-04-16 22:20:36 +00:00
|
|
|
case 1: set->sig[0] = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void sigfillset(sigset_t *set)
|
|
|
|
{
|
|
|
|
switch (_NSIG_WORDS) {
|
|
|
|
default:
|
|
|
|
memset(set, -1, sizeof(sigset_t));
|
|
|
|
break;
|
|
|
|
case 2: set->sig[1] = -1;
|
2020-08-23 22:36:59 +00:00
|
|
|
fallthrough;
|
2005-04-16 22:20:36 +00:00
|
|
|
case 1: set->sig[0] = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Some extensions for manipulating the low 32 signals in particular. */
|
|
|
|
|
|
|
|
static inline void sigaddsetmask(sigset_t *set, unsigned long mask)
|
|
|
|
{
|
|
|
|
set->sig[0] |= mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void sigdelsetmask(sigset_t *set, unsigned long mask)
|
|
|
|
{
|
|
|
|
set->sig[0] &= ~mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int sigtestsetmask(sigset_t *set, unsigned long mask)
|
|
|
|
{
|
|
|
|
return (set->sig[0] & mask) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void siginitset(sigset_t *set, unsigned long mask)
|
|
|
|
{
|
|
|
|
set->sig[0] = mask;
|
|
|
|
switch (_NSIG_WORDS) {
|
|
|
|
default:
|
|
|
|
memset(&set->sig[1], 0, sizeof(long)*(_NSIG_WORDS-1));
|
|
|
|
break;
|
|
|
|
case 2: set->sig[1] = 0;
|
include: jhash/signal: Fix fall-through warnings for Clang
In preparation to enable -Wimplicit-fallthrough for Clang, explicitly
add break statements instead of letting the code fall through to the
next case.
This patch adds four break statements that, together, fix almost 40,000
warnings when building Linux 5.10-rc1 with Clang 12.0.0 and this[1] change
reverted. Notice that in order to enable -Wimplicit-fallthrough for Clang,
such change[1] is meant to be reverted at some point. So, this patch helps
to move in that direction.
Something important to mention is that there is currently a discrepancy
between GCC and Clang when dealing with switch fall-through to empty case
statements or to cases that only contain a break/continue/return
statement[2][3][4].
Now that the -Wimplicit-fallthrough option has been globally enabled[5],
any compiler should really warn on missing either a fallthrough annotation
or any of the other case-terminating statements (break/continue/return/
goto) when falling through to the next case statement. Making exceptions
to this introduces variation in case handling which may continue to lead
to bugs, misunderstandings, and a general lack of robustness. The point
of enabling options like -Wimplicit-fallthrough is to prevent human error
and aid developers in spotting bugs before their code is even built/
submitted/committed, therefore eliminating classes of bugs. So, in order
to really accomplish this, we should, and can, move in the direction of
addressing any error-prone scenarios and get rid of the unintentional
fallthrough bug-class in the kernel, entirely, even if there is some minor
redundancy. Better to have explicit case-ending statements than continue to
have exceptions where one must guess as to the right result. The compiler
will eliminate any actual redundancy.
[1] commit e2079e93f562c ("kbuild: Do not enable -Wimplicit-fallthrough for clang for now")
[2] https://github.com/ClangBuiltLinux/linux/issues/636
[3] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91432
[4] https://godbolt.org/z/xgkvIh
[5] commit a035d552a93b ("Makefile: Globally enable fall-through warning")
Co-developed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
2020-09-03 04:25:55 +00:00
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
case 1: ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void siginitsetinv(sigset_t *set, unsigned long mask)
|
|
|
|
{
|
|
|
|
set->sig[0] = ~mask;
|
|
|
|
switch (_NSIG_WORDS) {
|
|
|
|
default:
|
|
|
|
memset(&set->sig[1], -1, sizeof(long)*(_NSIG_WORDS-1));
|
|
|
|
break;
|
|
|
|
case 2: set->sig[1] = -1;
|
include: jhash/signal: Fix fall-through warnings for Clang
In preparation to enable -Wimplicit-fallthrough for Clang, explicitly
add break statements instead of letting the code fall through to the
next case.
This patch adds four break statements that, together, fix almost 40,000
warnings when building Linux 5.10-rc1 with Clang 12.0.0 and this[1] change
reverted. Notice that in order to enable -Wimplicit-fallthrough for Clang,
such change[1] is meant to be reverted at some point. So, this patch helps
to move in that direction.
Something important to mention is that there is currently a discrepancy
between GCC and Clang when dealing with switch fall-through to empty case
statements or to cases that only contain a break/continue/return
statement[2][3][4].
Now that the -Wimplicit-fallthrough option has been globally enabled[5],
any compiler should really warn on missing either a fallthrough annotation
or any of the other case-terminating statements (break/continue/return/
goto) when falling through to the next case statement. Making exceptions
to this introduces variation in case handling which may continue to lead
to bugs, misunderstandings, and a general lack of robustness. The point
of enabling options like -Wimplicit-fallthrough is to prevent human error
and aid developers in spotting bugs before their code is even built/
submitted/committed, therefore eliminating classes of bugs. So, in order
to really accomplish this, we should, and can, move in the direction of
addressing any error-prone scenarios and get rid of the unintentional
fallthrough bug-class in the kernel, entirely, even if there is some minor
redundancy. Better to have explicit case-ending statements than continue to
have exceptions where one must guess as to the right result. The compiler
will eliminate any actual redundancy.
[1] commit e2079e93f562c ("kbuild: Do not enable -Wimplicit-fallthrough for clang for now")
[2] https://github.com/ClangBuiltLinux/linux/issues/636
[3] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91432
[4] https://godbolt.org/z/xgkvIh
[5] commit a035d552a93b ("Makefile: Globally enable fall-through warning")
Co-developed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
2020-09-03 04:25:55 +00:00
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
case 1: ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* __HAVE_ARCH_SIG_SETOPS */
|
|
|
|
|
|
|
|
static inline void init_sigpending(struct sigpending *sig)
|
|
|
|
{
|
|
|
|
sigemptyset(&sig->signal);
|
|
|
|
INIT_LIST_HEAD(&sig->list);
|
|
|
|
}
|
|
|
|
|
2006-03-29 00:11:18 +00:00
|
|
|
extern void flush_sigqueue(struct sigpending *queue);
|
|
|
|
|
2005-05-01 15:59:13 +00:00
|
|
|
/* Test if 'sig' is valid signal. Use this instead of testing _NSIG directly */
|
|
|
|
static inline int valid_signal(unsigned long sig)
|
|
|
|
{
|
|
|
|
return sig <= _NSIG ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
2011-05-18 13:08:03 +00:00
|
|
|
struct timespec;
|
|
|
|
struct pt_regs;
|
2018-07-13 23:40:57 +00:00
|
|
|
enum pid_type;
|
2011-05-18 13:08:03 +00:00
|
|
|
|
signal/timer/event: signalfd core
This patch series implements the new signalfd() system call.
I took part of the original Linus code (and you know how badly it can be
broken :), and I added even more breakage ;) Signals are fetched from the same
signal queue used by the process, so signalfd will compete with standard
kernel delivery in dequeue_signal(). If you want to reliably fetch signals on
the signalfd file, you need to block them with sigprocmask(SIG_BLOCK). This
seems to be working fine on my Dual Opteron machine. I made a quick test
program for it:
http://www.xmailserver.org/signafd-test.c
The signalfd() system call implements signal delivery into a file descriptor
receiver. The signalfd file descriptor if created with the following API:
int signalfd(int ufd, const sigset_t *mask, size_t masksize);
The "ufd" parameter allows to change an existing signalfd sigmask, w/out going
to close/create cycle (Linus idea). Use "ufd" == -1 if you want a brand new
signalfd file.
The "mask" allows to specify the signal mask of signals that we are interested
in. The "masksize" parameter is the size of "mask".
The signalfd fd supports the poll(2) and read(2) system calls. The poll(2)
will return POLLIN when signals are available to be dequeued. As a direct
consequence of supporting the Linux poll subsystem, the signalfd fd can use
used together with epoll(2) too.
The read(2) system call will return a "struct signalfd_siginfo" structure in
the userspace supplied buffer. The return value is the number of bytes copied
in the supplied buffer, or -1 in case of error. The read(2) call can also
return 0, in case the sighand structure to which the signalfd was attached,
has been orphaned. The O_NONBLOCK flag is also supported, and read(2) will
return -EAGAIN in case no signal is available.
If the size of the buffer passed to read(2) is lower than sizeof(struct
signalfd_siginfo), -EINVAL is returned. A read from the signalfd can also
return -ERESTARTSYS in case a signal hits the process. The format of the
struct signalfd_siginfo is, and the valid fields depends of the (->code &
__SI_MASK) value, in the same way a struct siginfo would:
struct signalfd_siginfo {
__u32 signo; /* si_signo */
__s32 err; /* si_errno */
__s32 code; /* si_code */
__u32 pid; /* si_pid */
__u32 uid; /* si_uid */
__s32 fd; /* si_fd */
__u32 tid; /* si_fd */
__u32 band; /* si_band */
__u32 overrun; /* si_overrun */
__u32 trapno; /* si_trapno */
__s32 status; /* si_status */
__s32 svint; /* si_int */
__u64 svptr; /* si_ptr */
__u64 utime; /* si_utime */
__u64 stime; /* si_stime */
__u64 addr; /* si_addr */
};
[akpm@linux-foundation.org: fix signalfd_copyinfo() on i386]
Signed-off-by: Davide Libenzi <davidel@xmailserver.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-05-11 05:23:13 +00:00
|
|
|
extern int next_signal(struct sigpending *pending, sigset_t *mask);
|
2018-09-25 09:27:20 +00:00
|
|
|
extern int do_send_sig_info(int sig, struct kernel_siginfo *info,
|
2018-07-21 15:45:15 +00:00
|
|
|
struct task_struct *p, enum pid_type type);
|
2018-09-25 09:27:20 +00:00
|
|
|
extern int group_send_sig_info(int sig, struct kernel_siginfo *info,
|
2018-07-13 23:40:57 +00:00
|
|
|
struct task_struct *p, enum pid_type type);
|
2018-09-25 09:27:20 +00:00
|
|
|
extern int __group_send_sig_info(int, struct kernel_siginfo *, struct task_struct *);
|
2005-04-16 22:20:36 +00:00
|
|
|
extern int sigprocmask(int, sigset_t *, sigset_t *);
|
2012-04-27 17:58:59 +00:00
|
|
|
extern void set_current_blocked(sigset_t *);
|
|
|
|
extern void __set_current_blocked(const sigset_t *);
|
2007-07-22 09:12:28 +00:00
|
|
|
extern int show_unhandled_signals;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2018-08-22 05:00:54 +00:00
|
|
|
extern bool get_signal(struct ksignal *ksig);
|
2012-11-07 20:11:25 +00:00
|
|
|
extern void signal_setup_done(int failed, struct ksignal *ksig, int stepping);
|
2008-02-08 12:19:12 +00:00
|
|
|
extern void exit_signals(struct task_struct *tsk);
|
2014-06-06 21:37:00 +00:00
|
|
|
extern void kernel_sigaction(int, __sighandler_t);
|
|
|
|
|
2019-08-16 17:33:54 +00:00
|
|
|
#define SIG_KTHREAD ((__force __sighandler_t)2)
|
|
|
|
#define SIG_KTHREAD_KERNEL ((__force __sighandler_t)3)
|
|
|
|
|
2014-06-06 21:37:00 +00:00
|
|
|
static inline void allow_signal(int sig)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Kernel threads handle their own signals. Let the signal code
|
|
|
|
* know it'll be handled, so that they don't get converted to
|
|
|
|
* SIGKILL or just silently dropped.
|
|
|
|
*/
|
2019-08-16 17:33:54 +00:00
|
|
|
kernel_sigaction(sig, SIG_KTHREAD);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void allow_kernel_signal(int sig)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Kernel threads handle their own signals. Let the signal code
|
|
|
|
* know signals sent by the kernel will be handled, so that they
|
|
|
|
* don't get silently dropped.
|
|
|
|
*/
|
|
|
|
kernel_sigaction(sig, SIG_KTHREAD_KERNEL);
|
2014-06-06 21:37:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void disallow_signal(int sig)
|
|
|
|
{
|
|
|
|
kernel_sigaction(sig, SIG_IGN);
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-12-07 04:32:47 +00:00
|
|
|
extern struct kmem_cache *sighand_cachep;
|
|
|
|
|
2018-08-22 05:00:34 +00:00
|
|
|
extern bool unhandled_signal(struct task_struct *tsk, int sig);
|
2007-07-22 09:12:28 +00:00
|
|
|
|
2007-05-09 09:33:37 +00:00
|
|
|
/*
|
|
|
|
* In POSIX a signal is sent either to a specific thread (Linux task)
|
|
|
|
* or to the process as a whole (Linux thread group). How the signal
|
|
|
|
* is sent determines whether it's to one thread or the whole group,
|
|
|
|
* which determines which signal mask(s) are involved in blocking it
|
|
|
|
* from being delivered until later. When the signal is delivered,
|
|
|
|
* either it's caught or ignored by a user handler or it has a default
|
|
|
|
* effect that applies to the whole thread group (POSIX process).
|
|
|
|
*
|
|
|
|
* The possible effects an unblocked signal set to SIG_DFL can have are:
|
|
|
|
* ignore - Nothing Happens
|
|
|
|
* terminate - kill the process, i.e. all threads in the group,
|
|
|
|
* similar to exit_group. The group leader (only) reports
|
|
|
|
* WIFSIGNALED status to its parent.
|
|
|
|
* coredump - write a core dump file describing all threads using
|
|
|
|
* the same mm and then kill all those threads
|
|
|
|
* stop - stop all the threads in the group, i.e. TASK_STOPPED state
|
|
|
|
*
|
|
|
|
* SIGKILL and SIGSTOP cannot be caught, blocked, or ignored.
|
|
|
|
* Other signals when not blocked and set to SIG_DFL behaves as follows.
|
|
|
|
* The job control signals also have other special effects.
|
|
|
|
*
|
|
|
|
* +--------------------+------------------+
|
|
|
|
* | POSIX signal | default action |
|
|
|
|
* +--------------------+------------------+
|
|
|
|
* | SIGHUP | terminate |
|
|
|
|
* | SIGINT | terminate |
|
|
|
|
* | SIGQUIT | coredump |
|
|
|
|
* | SIGILL | coredump |
|
|
|
|
* | SIGTRAP | coredump |
|
|
|
|
* | SIGABRT/SIGIOT | coredump |
|
|
|
|
* | SIGBUS | coredump |
|
|
|
|
* | SIGFPE | coredump |
|
|
|
|
* | SIGKILL | terminate(+) |
|
|
|
|
* | SIGUSR1 | terminate |
|
|
|
|
* | SIGSEGV | coredump |
|
|
|
|
* | SIGUSR2 | terminate |
|
|
|
|
* | SIGPIPE | terminate |
|
|
|
|
* | SIGALRM | terminate |
|
|
|
|
* | SIGTERM | terminate |
|
|
|
|
* | SIGCHLD | ignore |
|
|
|
|
* | SIGCONT | ignore(*) |
|
|
|
|
* | SIGSTOP | stop(*)(+) |
|
|
|
|
* | SIGTSTP | stop(*) |
|
|
|
|
* | SIGTTIN | stop(*) |
|
|
|
|
* | SIGTTOU | stop(*) |
|
|
|
|
* | SIGURG | ignore |
|
|
|
|
* | SIGXCPU | coredump |
|
|
|
|
* | SIGXFSZ | coredump |
|
|
|
|
* | SIGVTALRM | terminate |
|
|
|
|
* | SIGPROF | terminate |
|
|
|
|
* | SIGPOLL/SIGIO | terminate |
|
|
|
|
* | SIGSYS/SIGUNUSED | coredump |
|
|
|
|
* | SIGSTKFLT | terminate |
|
|
|
|
* | SIGWINCH | ignore |
|
|
|
|
* | SIGPWR | terminate |
|
|
|
|
* | SIGRTMIN-SIGRTMAX | terminate |
|
|
|
|
* +--------------------+------------------+
|
|
|
|
* | non-POSIX signal | default action |
|
|
|
|
* +--------------------+------------------+
|
|
|
|
* | SIGEMT | coredump |
|
|
|
|
* +--------------------+------------------+
|
|
|
|
*
|
|
|
|
* (+) For SIGKILL and SIGSTOP the action is "always", not just "default".
|
|
|
|
* (*) Special job control effects:
|
|
|
|
* When SIGCONT is sent, it resumes the process (all threads in the group)
|
|
|
|
* from TASK_STOPPED state and also clears any pending/queued stop signals
|
|
|
|
* (any of those marked with "stop(*)"). This happens regardless of blocking,
|
|
|
|
* catching, or ignoring SIGCONT. When any stop signal is sent, it clears
|
|
|
|
* any pending/queued SIGCONT signals; this happens regardless of blocking,
|
|
|
|
* catching, or ignored the stop signal, though (except for SIGSTOP) the
|
|
|
|
* default action of stopping the process may happen later or never.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef SIGEMT
|
|
|
|
#define SIGEMT_MASK rt_sigmask(SIGEMT)
|
|
|
|
#else
|
|
|
|
#define SIGEMT_MASK 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if SIGRTMIN > BITS_PER_LONG
|
|
|
|
#define rt_sigmask(sig) (1ULL << ((sig)-1))
|
|
|
|
#else
|
|
|
|
#define rt_sigmask(sig) sigmask(sig)
|
|
|
|
#endif
|
2016-05-23 23:24:02 +00:00
|
|
|
|
|
|
|
#define siginmask(sig, mask) \
|
signal: Make siginmask safe when passed a signal of 0
Eric Biggers reported:
> The following commit, which went into v4.20, introduced undefined behavior when
> sys_rt_sigqueueinfo() is called with sig=0:
>
> commit 4ce5f9c9e7546915c559ffae594e6d73f918db00
> Author: Eric W. Biederman <ebiederm@xmission.com>
> Date: Tue Sep 25 12:59:31 2018 +0200
>
> signal: Use a smaller struct siginfo in the kernel
>
> In sig_specific_sicodes(), used from known_siginfo_layout(), the expression
> '1ULL << ((sig)-1)' is undefined as it evaluates to 1ULL << 4294967295.
>
> Reproducer:
>
> #include <signal.h>
> #include <sys/syscall.h>
> #include <unistd.h>
>
> int main(void)
> {
> siginfo_t si = { .si_code = 1 };
> syscall(__NR_rt_sigqueueinfo, 0, 0, &si);
> }
>
> UBSAN report for v5.0-rc1:
>
> UBSAN: Undefined behaviour in kernel/signal.c:2946:7
> shift exponent 4294967295 is too large for 64-bit type 'long unsigned int'
> CPU: 2 PID: 346 Comm: syz_signal Not tainted 5.0.0-rc1 #25
> Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1 04/01/2014
> Call Trace:
> __dump_stack lib/dump_stack.c:77 [inline]
> dump_stack+0x70/0xa5 lib/dump_stack.c:113
> ubsan_epilogue+0xd/0x40 lib/ubsan.c:159
> __ubsan_handle_shift_out_of_bounds+0x12c/0x170 lib/ubsan.c:425
> known_siginfo_layout+0xae/0xe0 kernel/signal.c:2946
> post_copy_siginfo_from_user kernel/signal.c:3009 [inline]
> __copy_siginfo_from_user+0x35/0x60 kernel/signal.c:3035
> __do_sys_rt_sigqueueinfo kernel/signal.c:3553 [inline]
> __se_sys_rt_sigqueueinfo kernel/signal.c:3549 [inline]
> __x64_sys_rt_sigqueueinfo+0x31/0x70 kernel/signal.c:3549
> do_syscall_64+0x4c/0x1b0 arch/x86/entry/common.c:290
> entry_SYSCALL_64_after_hwframe+0x49/0xbe
> RIP: 0033:0x433639
> Code: c4 18 c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 0f 83 7b 27 00 00 c3 66 2e 0f 1f 84 00 00 00 00
> RSP: 002b:00007fffcb289fc8 EFLAGS: 00000246 ORIG_RAX: 0000000000000081
> RAX: ffffffffffffffda RBX: 00000000004002e0 RCX: 0000000000433639
> RDX: 00007fffcb289fd0 RSI: 0000000000000000 RDI: 0000000000000000
> RBP: 00000000006b2018 R08: 000000000000004d R09: 0000000000000000
> R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000401560
> R13: 00000000004015f0 R14: 0000000000000000 R15: 0000000000000000
I have looked at the other callers of siginmask and they all appear to
in locations where sig can not be zero.
I have looked at the code generation of adding an extra test against
zero and gcc was able with a simple decrement instruction to combine
the two tests together. So the at most adding this test cost a single
cpu cycle. In practice that decrement instruction was already present
as part of the mask comparison, so the only change was when the
instruction was executed.
So given that it is cheap, and obviously correct to update siginmask
to verify the signal is not zero. Fix this issue there to avoid any
future problems.
Reported-by: Eric Biggers <ebiggers@kernel.org>
Fixes: 4ce5f9c9e754 ("signal: Use a smaller struct siginfo in the kernel")
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
2019-01-12 17:48:20 +00:00
|
|
|
((sig) > 0 && (sig) < SIGRTMIN && (rt_sigmask(sig) & (mask)))
|
2007-05-09 09:33:37 +00:00
|
|
|
|
|
|
|
#define SIG_KERNEL_ONLY_MASK (\
|
|
|
|
rt_sigmask(SIGKILL) | rt_sigmask(SIGSTOP))
|
|
|
|
|
|
|
|
#define SIG_KERNEL_STOP_MASK (\
|
|
|
|
rt_sigmask(SIGSTOP) | rt_sigmask(SIGTSTP) | \
|
|
|
|
rt_sigmask(SIGTTIN) | rt_sigmask(SIGTTOU) )
|
|
|
|
|
|
|
|
#define SIG_KERNEL_COREDUMP_MASK (\
|
|
|
|
rt_sigmask(SIGQUIT) | rt_sigmask(SIGILL) | \
|
|
|
|
rt_sigmask(SIGTRAP) | rt_sigmask(SIGABRT) | \
|
|
|
|
rt_sigmask(SIGFPE) | rt_sigmask(SIGSEGV) | \
|
|
|
|
rt_sigmask(SIGBUS) | rt_sigmask(SIGSYS) | \
|
|
|
|
rt_sigmask(SIGXCPU) | rt_sigmask(SIGXFSZ) | \
|
|
|
|
SIGEMT_MASK )
|
|
|
|
|
|
|
|
#define SIG_KERNEL_IGNORE_MASK (\
|
|
|
|
rt_sigmask(SIGCONT) | rt_sigmask(SIGCHLD) | \
|
|
|
|
rt_sigmask(SIGWINCH) | rt_sigmask(SIGURG) )
|
|
|
|
|
2017-06-29 14:28:50 +00:00
|
|
|
#define SIG_SPECIFIC_SICODES_MASK (\
|
|
|
|
rt_sigmask(SIGILL) | rt_sigmask(SIGFPE) | \
|
|
|
|
rt_sigmask(SIGSEGV) | rt_sigmask(SIGBUS) | \
|
|
|
|
rt_sigmask(SIGTRAP) | rt_sigmask(SIGCHLD) | \
|
|
|
|
rt_sigmask(SIGPOLL) | rt_sigmask(SIGSYS) | \
|
|
|
|
SIGEMT_MASK )
|
|
|
|
|
2016-05-23 23:24:02 +00:00
|
|
|
#define sig_kernel_only(sig) siginmask(sig, SIG_KERNEL_ONLY_MASK)
|
|
|
|
#define sig_kernel_coredump(sig) siginmask(sig, SIG_KERNEL_COREDUMP_MASK)
|
|
|
|
#define sig_kernel_ignore(sig) siginmask(sig, SIG_KERNEL_IGNORE_MASK)
|
|
|
|
#define sig_kernel_stop(sig) siginmask(sig, SIG_KERNEL_STOP_MASK)
|
2017-06-29 14:28:50 +00:00
|
|
|
#define sig_specific_sicodes(sig) siginmask(sig, SIG_SPECIFIC_SICODES_MASK)
|
2007-05-09 09:33:37 +00:00
|
|
|
|
|
|
|
#define sig_fatal(t, signr) \
|
|
|
|
(!siginmask(signr, SIG_KERNEL_IGNORE_MASK|SIG_KERNEL_STOP_MASK) && \
|
|
|
|
(t)->sighand->action[(signr)-1].sa.sa_handler == SIG_DFL)
|
|
|
|
|
2008-02-06 09:36:44 +00:00
|
|
|
void signals_init(void);
|
|
|
|
|
2012-11-18 20:29:16 +00:00
|
|
|
int restore_altstack(const stack_t __user *);
|
2012-11-20 19:24:26 +00:00
|
|
|
int __save_altstack(stack_t __user *, unsigned long);
|
2012-11-18 20:29:16 +00:00
|
|
|
|
2020-02-16 00:54:56 +00:00
|
|
|
#define unsafe_save_altstack(uss, sp, label) do { \
|
2013-09-01 19:35:01 +00:00
|
|
|
stack_t __user *__uss = uss; \
|
|
|
|
struct task_struct *t = current; \
|
2020-02-16 00:54:56 +00:00
|
|
|
unsafe_put_user((void __user *)t->sas_ss_sp, &__uss->ss_sp, label); \
|
|
|
|
unsafe_put_user(t->sas_ss_flags, &__uss->ss_flags, label); \
|
|
|
|
unsafe_put_user(t->sas_ss_size, &__uss->ss_size, label); \
|
2016-04-14 20:20:04 +00:00
|
|
|
if (t->sas_ss_flags & SS_AUTODISARM) \
|
|
|
|
sas_ss_reset(t); \
|
2013-09-01 19:35:01 +00:00
|
|
|
} while (0);
|
|
|
|
|
2013-04-12 01:29:19 +00:00
|
|
|
#ifdef CONFIG_PROC_FS
|
|
|
|
struct seq_file;
|
|
|
|
extern void render_sigset_t(struct seq_file *, const char *, sigset_t *);
|
|
|
|
#endif
|
|
|
|
|
2020-11-20 20:33:45 +00:00
|
|
|
#ifndef arch_untagged_si_addr
|
|
|
|
/*
|
|
|
|
* Given a fault address and a signal and si_code which correspond to the
|
|
|
|
* _sigfault union member, returns the address that must appear in si_addr if
|
|
|
|
* the signal handler does not have SA_EXPOSE_TAGBITS enabled in sa_flags.
|
|
|
|
*/
|
|
|
|
static inline void __user *arch_untagged_si_addr(void __user *addr,
|
|
|
|
unsigned long sig,
|
|
|
|
unsigned long si_code)
|
|
|
|
{
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif /* _LINUX_SIGNAL_H */
|