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
|
2008-05-19 23:52:27 +00:00
|
|
|
/*
|
2005-04-16 22:20:36 +00:00
|
|
|
* arch/sparc64/kernel/signal.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 1991, 1992 Linus Torvalds
|
2008-08-01 03:40:46 +00:00
|
|
|
* Copyright (C) 1995, 2008 David S. Miller (davem@davemloft.net)
|
2005-04-16 22:20:36 +00:00
|
|
|
* Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx)
|
|
|
|
* Copyright (C) 1997 Eddie C. Dost (ecd@skynet.be)
|
|
|
|
* Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/signal.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/wait.h>
|
|
|
|
#include <linux/ptrace.h>
|
2022-02-09 18:20:45 +00:00
|
|
|
#include <linux/resume_user_mode.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/unistd.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/tty.h>
|
|
|
|
#include <linux/binfmts.h>
|
|
|
|
#include <linux/bitops.h>
|
2013-09-14 12:02:11 +00:00
|
|
|
#include <linux/context_tracking.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2016-12-24 19:46:01 +00:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <asm/ptrace.h>
|
|
|
|
#include <asm/fpumacro.h>
|
|
|
|
#include <asm/uctx.h>
|
|
|
|
#include <asm/siginfo.h>
|
|
|
|
#include <asm/visasm.h>
|
2012-03-28 17:30:03 +00:00
|
|
|
#include <asm/switch_to.h>
|
|
|
|
#include <asm/cacheflush.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-08-21 00:14:54 +00:00
|
|
|
#include "sigutil.h"
|
2014-05-16 21:26:00 +00:00
|
|
|
#include "systbls.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "entry.h"
|
2008-03-26 08:52:18 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* {set, get}context() needed for 64-bit SparcLinux userland. */
|
|
|
|
asmlinkage void sparc64_set_context(struct pt_regs *regs)
|
|
|
|
{
|
|
|
|
struct ucontext __user *ucp = (struct ucontext __user *)
|
|
|
|
regs->u_regs[UREG_I0];
|
2013-09-14 12:02:11 +00:00
|
|
|
enum ctx_state prev_state = exception_enter();
|
2005-04-16 22:20:36 +00:00
|
|
|
mc_gregset_t __user *grp;
|
|
|
|
unsigned long pc, npc, tstate;
|
|
|
|
unsigned long fp, i7;
|
|
|
|
unsigned char fenab;
|
|
|
|
int err;
|
|
|
|
|
2016-03-01 05:25:32 +00:00
|
|
|
synchronize_user_stack();
|
2005-04-16 22:20:36 +00:00
|
|
|
if (get_thread_wsaved() ||
|
|
|
|
(((unsigned long)ucp) & (sizeof(unsigned long)-1)) ||
|
|
|
|
(!__access_ok(ucp, sizeof(*ucp))))
|
|
|
|
goto do_sigsegv;
|
|
|
|
grp = &ucp->uc_mcontext.mc_gregs;
|
|
|
|
err = __get_user(pc, &((*grp)[MC_PC]));
|
|
|
|
err |= __get_user(npc, &((*grp)[MC_NPC]));
|
|
|
|
if (err || ((pc | npc) & 3))
|
|
|
|
goto do_sigsegv;
|
|
|
|
if (regs->u_regs[UREG_I1]) {
|
|
|
|
sigset_t set;
|
|
|
|
|
|
|
|
if (_NSIG_WORDS == 1) {
|
|
|
|
if (__get_user(set.sig[0], &ucp->uc_sigmask.sig[0]))
|
|
|
|
goto do_sigsegv;
|
|
|
|
} else {
|
|
|
|
if (__copy_from_user(&set, &ucp->uc_sigmask, sizeof(sigset_t)))
|
|
|
|
goto do_sigsegv;
|
|
|
|
}
|
2011-08-11 13:57:02 +00:00
|
|
|
set_current_blocked(&set);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
if (test_thread_flag(TIF_32BIT)) {
|
|
|
|
pc &= 0xffffffff;
|
|
|
|
npc &= 0xffffffff;
|
|
|
|
}
|
|
|
|
regs->tpc = pc;
|
|
|
|
regs->tnpc = npc;
|
|
|
|
err |= __get_user(regs->y, &((*grp)[MC_Y]));
|
|
|
|
err |= __get_user(tstate, &((*grp)[MC_TSTATE]));
|
|
|
|
regs->tstate &= ~(TSTATE_ASI | TSTATE_ICC | TSTATE_XCC);
|
|
|
|
regs->tstate |= (tstate & (TSTATE_ASI | TSTATE_ICC | TSTATE_XCC));
|
|
|
|
err |= __get_user(regs->u_regs[UREG_G1], (&(*grp)[MC_G1]));
|
|
|
|
err |= __get_user(regs->u_regs[UREG_G2], (&(*grp)[MC_G2]));
|
|
|
|
err |= __get_user(regs->u_regs[UREG_G3], (&(*grp)[MC_G3]));
|
|
|
|
err |= __get_user(regs->u_regs[UREG_G4], (&(*grp)[MC_G4]));
|
|
|
|
err |= __get_user(regs->u_regs[UREG_G5], (&(*grp)[MC_G5]));
|
|
|
|
err |= __get_user(regs->u_regs[UREG_G6], (&(*grp)[MC_G6]));
|
2008-08-01 03:40:46 +00:00
|
|
|
|
|
|
|
/* Skip %g7 as that's the thread register in userspace. */
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
err |= __get_user(regs->u_regs[UREG_I0], (&(*grp)[MC_O0]));
|
|
|
|
err |= __get_user(regs->u_regs[UREG_I1], (&(*grp)[MC_O1]));
|
|
|
|
err |= __get_user(regs->u_regs[UREG_I2], (&(*grp)[MC_O2]));
|
|
|
|
err |= __get_user(regs->u_regs[UREG_I3], (&(*grp)[MC_O3]));
|
|
|
|
err |= __get_user(regs->u_regs[UREG_I4], (&(*grp)[MC_O4]));
|
|
|
|
err |= __get_user(regs->u_regs[UREG_I5], (&(*grp)[MC_O5]));
|
|
|
|
err |= __get_user(regs->u_regs[UREG_I6], (&(*grp)[MC_O6]));
|
|
|
|
err |= __get_user(regs->u_regs[UREG_I7], (&(*grp)[MC_O7]));
|
|
|
|
|
|
|
|
err |= __get_user(fp, &(ucp->uc_mcontext.mc_fp));
|
|
|
|
err |= __get_user(i7, &(ucp->uc_mcontext.mc_i7));
|
|
|
|
err |= __put_user(fp,
|
|
|
|
(&(((struct reg_window __user *)(STACK_BIAS+regs->u_regs[UREG_I6]))->ins[6])));
|
|
|
|
err |= __put_user(i7,
|
|
|
|
(&(((struct reg_window __user *)(STACK_BIAS+regs->u_regs[UREG_I6]))->ins[7])));
|
|
|
|
|
|
|
|
err |= __get_user(fenab, &(ucp->uc_mcontext.mc_fpregs.mcfpu_enab));
|
|
|
|
if (fenab) {
|
|
|
|
unsigned long *fpregs = current_thread_info()->fpregs;
|
|
|
|
unsigned long fprs;
|
|
|
|
|
|
|
|
fprs_write(0);
|
|
|
|
err |= __get_user(fprs, &(ucp->uc_mcontext.mc_fpregs.mcfpu_fprs));
|
|
|
|
if (fprs & FPRS_DL)
|
|
|
|
err |= copy_from_user(fpregs,
|
|
|
|
&(ucp->uc_mcontext.mc_fpregs.mcfpu_fregs),
|
|
|
|
(sizeof(unsigned int) * 32));
|
|
|
|
if (fprs & FPRS_DU)
|
|
|
|
err |= copy_from_user(fpregs+16,
|
|
|
|
((unsigned long __user *)&(ucp->uc_mcontext.mc_fpregs.mcfpu_fregs))+16,
|
|
|
|
(sizeof(unsigned int) * 32));
|
|
|
|
err |= __get_user(current_thread_info()->xfsr[0],
|
|
|
|
&(ucp->uc_mcontext.mc_fpregs.mcfpu_fsr));
|
|
|
|
err |= __get_user(current_thread_info()->gsr[0],
|
|
|
|
&(ucp->uc_mcontext.mc_fpregs.mcfpu_gsr));
|
|
|
|
regs->tstate &= ~TSTATE_PEF;
|
|
|
|
}
|
|
|
|
if (err)
|
|
|
|
goto do_sigsegv;
|
2013-09-14 12:02:11 +00:00
|
|
|
out:
|
|
|
|
exception_exit(prev_state);
|
2005-04-16 22:20:36 +00:00
|
|
|
return;
|
|
|
|
do_sigsegv:
|
2019-05-23 15:17:27 +00:00
|
|
|
force_sig(SIGSEGV);
|
2013-09-14 12:02:11 +00:00
|
|
|
goto out;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
asmlinkage void sparc64_get_context(struct pt_regs *regs)
|
|
|
|
{
|
|
|
|
struct ucontext __user *ucp = (struct ucontext __user *)
|
|
|
|
regs->u_regs[UREG_I0];
|
2013-09-14 12:02:11 +00:00
|
|
|
enum ctx_state prev_state = exception_enter();
|
2005-04-16 22:20:36 +00:00
|
|
|
mc_gregset_t __user *grp;
|
|
|
|
mcontext_t __user *mcp;
|
|
|
|
unsigned long fp, i7;
|
|
|
|
unsigned char fenab;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
synchronize_user_stack();
|
|
|
|
if (get_thread_wsaved() || clear_user(ucp, sizeof(*ucp)))
|
|
|
|
goto do_sigsegv;
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
fenab = 0; /* IMO get_context is like any other system call, thus modifies FPU state -jj */
|
|
|
|
#else
|
|
|
|
fenab = (current_thread_info()->fpsaved[0] & FPRS_FEF);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
mcp = &ucp->uc_mcontext;
|
|
|
|
grp = &mcp->mc_gregs;
|
|
|
|
|
|
|
|
/* Skip over the trap instruction, first. */
|
|
|
|
if (test_thread_flag(TIF_32BIT)) {
|
|
|
|
regs->tpc = (regs->tnpc & 0xffffffff);
|
|
|
|
regs->tnpc = (regs->tnpc + 4) & 0xffffffff;
|
|
|
|
} else {
|
|
|
|
regs->tpc = regs->tnpc;
|
|
|
|
regs->tnpc += 4;
|
|
|
|
}
|
|
|
|
err = 0;
|
|
|
|
if (_NSIG_WORDS == 1)
|
|
|
|
err |= __put_user(current->blocked.sig[0],
|
|
|
|
(unsigned long __user *)&ucp->uc_sigmask);
|
|
|
|
else
|
|
|
|
err |= __copy_to_user(&ucp->uc_sigmask, ¤t->blocked,
|
|
|
|
sizeof(sigset_t));
|
|
|
|
|
|
|
|
err |= __put_user(regs->tstate, &((*grp)[MC_TSTATE]));
|
|
|
|
err |= __put_user(regs->tpc, &((*grp)[MC_PC]));
|
|
|
|
err |= __put_user(regs->tnpc, &((*grp)[MC_NPC]));
|
|
|
|
err |= __put_user(regs->y, &((*grp)[MC_Y]));
|
|
|
|
err |= __put_user(regs->u_regs[UREG_G1], &((*grp)[MC_G1]));
|
|
|
|
err |= __put_user(regs->u_regs[UREG_G2], &((*grp)[MC_G2]));
|
|
|
|
err |= __put_user(regs->u_regs[UREG_G3], &((*grp)[MC_G3]));
|
|
|
|
err |= __put_user(regs->u_regs[UREG_G4], &((*grp)[MC_G4]));
|
|
|
|
err |= __put_user(regs->u_regs[UREG_G5], &((*grp)[MC_G5]));
|
|
|
|
err |= __put_user(regs->u_regs[UREG_G6], &((*grp)[MC_G6]));
|
|
|
|
err |= __put_user(regs->u_regs[UREG_G7], &((*grp)[MC_G7]));
|
|
|
|
err |= __put_user(regs->u_regs[UREG_I0], &((*grp)[MC_O0]));
|
|
|
|
err |= __put_user(regs->u_regs[UREG_I1], &((*grp)[MC_O1]));
|
|
|
|
err |= __put_user(regs->u_regs[UREG_I2], &((*grp)[MC_O2]));
|
|
|
|
err |= __put_user(regs->u_regs[UREG_I3], &((*grp)[MC_O3]));
|
|
|
|
err |= __put_user(regs->u_regs[UREG_I4], &((*grp)[MC_O4]));
|
|
|
|
err |= __put_user(regs->u_regs[UREG_I5], &((*grp)[MC_O5]));
|
|
|
|
err |= __put_user(regs->u_regs[UREG_I6], &((*grp)[MC_O6]));
|
|
|
|
err |= __put_user(regs->u_regs[UREG_I7], &((*grp)[MC_O7]));
|
|
|
|
|
|
|
|
err |= __get_user(fp,
|
|
|
|
(&(((struct reg_window __user *)(STACK_BIAS+regs->u_regs[UREG_I6]))->ins[6])));
|
|
|
|
err |= __get_user(i7,
|
|
|
|
(&(((struct reg_window __user *)(STACK_BIAS+regs->u_regs[UREG_I6]))->ins[7])));
|
|
|
|
err |= __put_user(fp, &(mcp->mc_fp));
|
|
|
|
err |= __put_user(i7, &(mcp->mc_i7));
|
|
|
|
|
|
|
|
err |= __put_user(fenab, &(mcp->mc_fpregs.mcfpu_enab));
|
|
|
|
if (fenab) {
|
|
|
|
unsigned long *fpregs = current_thread_info()->fpregs;
|
|
|
|
unsigned long fprs;
|
|
|
|
|
|
|
|
fprs = current_thread_info()->fpsaved[0];
|
|
|
|
if (fprs & FPRS_DL)
|
|
|
|
err |= copy_to_user(&(mcp->mc_fpregs.mcfpu_fregs), fpregs,
|
|
|
|
(sizeof(unsigned int) * 32));
|
|
|
|
if (fprs & FPRS_DU)
|
|
|
|
err |= copy_to_user(
|
|
|
|
((unsigned long __user *)&(mcp->mc_fpregs.mcfpu_fregs))+16, fpregs+16,
|
|
|
|
(sizeof(unsigned int) * 32));
|
|
|
|
err |= __put_user(current_thread_info()->xfsr[0], &(mcp->mc_fpregs.mcfpu_fsr));
|
|
|
|
err |= __put_user(current_thread_info()->gsr[0], &(mcp->mc_fpregs.mcfpu_gsr));
|
|
|
|
err |= __put_user(fprs, &(mcp->mc_fpregs.mcfpu_fprs));
|
|
|
|
}
|
|
|
|
if (err)
|
|
|
|
goto do_sigsegv;
|
2013-09-14 12:02:11 +00:00
|
|
|
out:
|
|
|
|
exception_exit(prev_state);
|
2005-04-16 22:20:36 +00:00
|
|
|
return;
|
|
|
|
do_sigsegv:
|
2019-05-23 15:17:27 +00:00
|
|
|
force_sig(SIGSEGV);
|
2013-09-14 12:02:11 +00:00
|
|
|
goto out;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2016-05-29 04:21:31 +00:00
|
|
|
/* Checks if the fp is valid. We always build rt signal frames which
|
|
|
|
* are 16-byte aligned, therefore we can always enforce that the
|
|
|
|
* restore frame has that property as well.
|
|
|
|
*/
|
|
|
|
static bool invalid_frame_pointer(void __user *fp)
|
|
|
|
{
|
|
|
|
if (((unsigned long) fp) & 15)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
struct rt_signal_frame {
|
|
|
|
struct sparc_stackf ss;
|
|
|
|
siginfo_t info;
|
|
|
|
struct pt_regs regs;
|
|
|
|
__siginfo_fpu_t __user *fpu_save;
|
|
|
|
stack_t stack;
|
|
|
|
sigset_t mask;
|
2011-08-21 00:14:54 +00:00
|
|
|
__siginfo_rwin_t *rwin_save;
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void do_rt_sigreturn(struct pt_regs *regs)
|
|
|
|
{
|
2016-05-29 04:21:31 +00:00
|
|
|
unsigned long tpc, tnpc, tstate, ufp;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct rt_signal_frame __user *sf;
|
|
|
|
__siginfo_fpu_t __user *fpu_save;
|
2011-08-21 00:14:54 +00:00
|
|
|
__siginfo_rwin_t __user *rwin_save;
|
2005-04-16 22:20:36 +00:00
|
|
|
sigset_t set;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
/* Always make any pending restarted system calls return -EINTR */
|
2015-02-12 23:01:14 +00:00
|
|
|
current->restart_block.fn = do_no_restart_syscall;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
synchronize_user_stack ();
|
|
|
|
sf = (struct rt_signal_frame __user *)
|
|
|
|
(regs->u_regs [UREG_FP] + STACK_BIAS);
|
|
|
|
|
|
|
|
/* 1. Make sure we are not getting garbage from the user */
|
2016-05-29 04:21:31 +00:00
|
|
|
if (invalid_frame_pointer(sf))
|
|
|
|
goto segv;
|
|
|
|
|
|
|
|
if (get_user(ufp, &sf->regs.u_regs[UREG_FP]))
|
2005-04-16 22:20:36 +00:00
|
|
|
goto segv;
|
|
|
|
|
2016-05-29 04:21:31 +00:00
|
|
|
if ((ufp + STACK_BIAS) & 0x7)
|
|
|
|
goto segv;
|
|
|
|
|
|
|
|
err = __get_user(tpc, &sf->regs.tpc);
|
2005-04-16 22:20:36 +00:00
|
|
|
err |= __get_user(tnpc, &sf->regs.tnpc);
|
|
|
|
if (test_thread_flag(TIF_32BIT)) {
|
|
|
|
tpc &= 0xffffffff;
|
|
|
|
tnpc &= 0xffffffff;
|
|
|
|
}
|
|
|
|
err |= ((tpc | tnpc) & 3);
|
|
|
|
|
|
|
|
/* 2. Restore the state */
|
|
|
|
err |= __get_user(regs->y, &sf->regs.y);
|
|
|
|
err |= __get_user(tstate, &sf->regs.tstate);
|
|
|
|
err |= copy_from_user(regs->u_regs, sf->regs.u_regs, sizeof(regs->u_regs));
|
|
|
|
|
|
|
|
/* User can only change condition codes and %asi in %tstate. */
|
|
|
|
regs->tstate &= ~(TSTATE_ASI | TSTATE_ICC | TSTATE_XCC);
|
|
|
|
regs->tstate |= (tstate & (TSTATE_ASI | TSTATE_ICC | TSTATE_XCC));
|
|
|
|
|
|
|
|
err |= __get_user(fpu_save, &sf->fpu_save);
|
2011-08-21 00:14:54 +00:00
|
|
|
if (!err && fpu_save)
|
|
|
|
err |= restore_fpu_state(regs, fpu_save);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
err |= __copy_from_user(&set, &sf->mask, sizeof(sigset_t));
|
2012-12-23 08:41:17 +00:00
|
|
|
err |= restore_altstack(&sf->stack);
|
|
|
|
if (err)
|
2005-04-16 22:20:36 +00:00
|
|
|
goto segv;
|
2007-07-17 21:37:54 +00:00
|
|
|
|
2011-08-21 00:14:54 +00:00
|
|
|
err |= __get_user(rwin_save, &sf->rwin_save);
|
|
|
|
if (!err && rwin_save) {
|
|
|
|
if (restore_rwin_state(rwin_save))
|
|
|
|
goto segv;
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
regs->tpc = tpc;
|
|
|
|
regs->tnpc = tnpc;
|
|
|
|
|
2008-05-01 10:30:22 +00:00
|
|
|
/* Prevent syscall restart. */
|
sparc: Fix debugger syscall restart interactions.
So, forever, we've had this ptrace_signal_deliver implementation
which tries to handle all of the nasties that can occur when the
debugger looks at a process about to take a signal. It's meant
to address all of these issues inside of the kernel so that the
debugger need not be mindful of such things.
Problem is, this doesn't work.
The idea was that we should do the syscall restart business first, so
that the debugger captures that state. Otherwise, if the debugger for
example saves the child's state, makes the child execute something
else, then restores the saved state, we won't handle the syscall
restart properly because we lose the "we're in a syscall" state.
The code here worked for most cases, but if the debugger actually
passes the signal through to the child unaltered, it's possible that
we would do a syscall restart when we shouldn't have.
In particular this breaks the case of debugging a process under a gdb
which is being debugged by yet another gdb. gdb uses sigsuspend
to wait for SIGCHLD of the inferior, but if gdb itself is being
debugged by a top-level gdb we get a ptrace_stop(). The top-level gdb
does a PTRACE_CONT with SIGCHLD to let the inferior gdb see the
signal. But ptrace_signal_deliver() assumed the debugger would cancel
out the signal and therefore did a syscall restart, because the return
error was ERESTARTNOHAND.
Fix this by simply making ptrace_signal_deliver() a nop, and providing
a way for the debugger to control system call restarting properly:
1) Report a "in syscall" software bit in regs->{tstate,psr}.
It is set early on in trap entry to a system call and is fully
visible to the debugger via ptrace() and regsets.
2) Test this bit right before doing a syscall restart. We have
to do a final recheck right after get_signal_to_deliver() in
case the debugger cleared the bit during ptrace_stop().
3) Clear the bit in trap return so we don't accidently try to set
that bit in the real register.
As a result we also get a ptrace_{is,clear}_syscall() for sparc32 just
like sparc64 has.
M68K has this same exact bug, and is now the only other user of the
ptrace_signal_deliver hook. It needs to be fixed in the same exact
way as sparc.
Signed-off-by: David S. Miller <davem@davemloft.net>
2008-05-11 09:07:19 +00:00
|
|
|
pt_regs_clear_syscall(regs);
|
2008-05-01 10:30:22 +00:00
|
|
|
|
2011-08-11 13:57:02 +00:00
|
|
|
set_current_blocked(&set);
|
2005-04-16 22:20:36 +00:00
|
|
|
return;
|
|
|
|
segv:
|
2019-05-23 15:17:27 +00:00
|
|
|
force_sig(SIGSEGV);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2012-11-08 04:48:13 +00:00
|
|
|
static inline void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs, unsigned long framesize)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-05-08 01:54:05 +00:00
|
|
|
unsigned long sp = regs->u_regs[UREG_FP] + STACK_BIAS;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-05-08 01:54:05 +00:00
|
|
|
/*
|
|
|
|
* If we are on the alternate signal stack and would overflow it, don't.
|
|
|
|
* Return an always-bogus address instead so we will die with SIGSEGV.
|
|
|
|
*/
|
|
|
|
if (on_sig_stack(sp) && !likely(on_sig_stack(sp - framesize)))
|
|
|
|
return (void __user *) -1L;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* This is the X/Open sanctioned signal stack switching. */
|
2012-11-08 04:48:13 +00:00
|
|
|
sp = sigsp(sp, ksig) - framesize;
|
2010-02-10 00:18:40 +00:00
|
|
|
|
2008-05-08 01:54:05 +00:00
|
|
|
/* Always align the stack frame. This handles two cases. First,
|
|
|
|
* sigaltstack need not be mindful of platform specific stack
|
|
|
|
* alignment. Second, if we took this signal because the stack
|
|
|
|
* is not aligned properly, we'd like to take the signal cleanly
|
|
|
|
* and report that.
|
|
|
|
*/
|
2010-02-10 00:18:40 +00:00
|
|
|
sp &= ~15UL;
|
2008-05-08 01:54:05 +00:00
|
|
|
|
2010-02-10 00:18:40 +00:00
|
|
|
return (void __user *) sp;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2010-09-22 04:41:12 +00:00
|
|
|
static inline int
|
2012-11-08 04:48:13 +00:00
|
|
|
setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct rt_signal_frame __user *sf;
|
2011-08-21 00:14:54 +00:00
|
|
|
int wsaved, err, sf_size;
|
|
|
|
void __user *tail;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* 1. Make sure everything is clean */
|
|
|
|
synchronize_user_stack();
|
|
|
|
save_and_clear_fpu();
|
|
|
|
|
2011-08-21 00:14:54 +00:00
|
|
|
wsaved = get_thread_wsaved();
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-08-21 00:14:54 +00:00
|
|
|
sf_size = sizeof(struct rt_signal_frame);
|
|
|
|
if (current_thread_info()->fpsaved[0] & FPRS_FEF)
|
|
|
|
sf_size += sizeof(__siginfo_fpu_t);
|
|
|
|
if (wsaved)
|
|
|
|
sf_size += sizeof(__siginfo_rwin_t);
|
2005-04-16 22:20:36 +00:00
|
|
|
sf = (struct rt_signal_frame __user *)
|
2012-11-08 04:48:13 +00:00
|
|
|
get_sigframe(ksig, regs, sf_size);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-11-08 04:48:13 +00:00
|
|
|
if (invalid_frame_pointer (sf)) {
|
2018-10-26 03:36:46 +00:00
|
|
|
if (show_unhandled_signals)
|
|
|
|
pr_info("%s[%d] bad frame in setup_rt_frame: %016lx TPC %016lx O7 %016lx\n",
|
|
|
|
current->comm, current->pid, (unsigned long)sf,
|
|
|
|
regs->tpc, regs->u_regs[UREG_I7]);
|
2019-05-21 15:03:48 +00:00
|
|
|
force_sigsegv(ksig->sig);
|
2012-11-08 04:48:13 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-08-21 00:14:54 +00:00
|
|
|
tail = (sf + 1);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* 2. Save the current process state */
|
|
|
|
err = copy_to_user(&sf->regs, regs, sizeof (*regs));
|
|
|
|
|
|
|
|
if (current_thread_info()->fpsaved[0] & FPRS_FEF) {
|
2011-08-21 00:14:54 +00:00
|
|
|
__siginfo_fpu_t __user *fpu_save = tail;
|
|
|
|
tail += sizeof(__siginfo_fpu_t);
|
|
|
|
err |= save_fpu_state(regs, fpu_save);
|
|
|
|
err |= __put_user((u64)fpu_save, &sf->fpu_save);
|
2005-04-16 22:20:36 +00:00
|
|
|
} else {
|
|
|
|
err |= __put_user(0, &sf->fpu_save);
|
|
|
|
}
|
2011-08-21 00:14:54 +00:00
|
|
|
if (wsaved) {
|
|
|
|
__siginfo_rwin_t __user *rwin_save = tail;
|
|
|
|
tail += sizeof(__siginfo_rwin_t);
|
|
|
|
err |= save_rwin_state(wsaved, rwin_save);
|
|
|
|
err |= __put_user((u64)rwin_save, &sf->rwin_save);
|
|
|
|
set_thread_wsaved(0);
|
|
|
|
} else {
|
|
|
|
err |= __put_user(0, &sf->rwin_save);
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Setup sigaltstack */
|
2012-12-23 08:41:17 +00:00
|
|
|
err |= __save_altstack(&sf->stack, regs->u_regs[UREG_FP]);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-11-08 04:48:13 +00:00
|
|
|
err |= copy_to_user(&sf->mask, sigmask_to_save(), sizeof(sigset_t));
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-08-21 00:14:54 +00:00
|
|
|
if (!wsaved) {
|
2021-09-08 22:18:29 +00:00
|
|
|
err |= raw_copy_in_user((u64 __user *)sf,
|
|
|
|
(u64 __user *)(regs->u_regs[UREG_FP] +
|
|
|
|
STACK_BIAS),
|
|
|
|
sizeof(struct reg_window));
|
2011-08-21 00:14:54 +00:00
|
|
|
} else {
|
|
|
|
struct reg_window *rp;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-08-21 00:14:54 +00:00
|
|
|
rp = ¤t_thread_info()->reg_window[wsaved - 1];
|
|
|
|
err |= copy_to_user(sf, rp, sizeof(struct reg_window));
|
|
|
|
}
|
2012-11-08 04:48:13 +00:00
|
|
|
if (ksig->ka.sa.sa_flags & SA_SIGINFO)
|
|
|
|
err |= copy_siginfo_to_user(&sf->info, &ksig->info);
|
2005-04-16 22:20:36 +00:00
|
|
|
else {
|
2012-11-08 04:48:13 +00:00
|
|
|
err |= __put_user(ksig->sig, &sf->info.si_signo);
|
2005-04-16 22:20:36 +00:00
|
|
|
err |= __put_user(SI_NOINFO, &sf->info.si_code);
|
|
|
|
}
|
|
|
|
if (err)
|
2012-11-08 04:48:13 +00:00
|
|
|
return err;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* 3. signal handler back-trampoline and parameters */
|
|
|
|
regs->u_regs[UREG_FP] = ((unsigned long) sf) - STACK_BIAS;
|
2012-11-08 04:48:13 +00:00
|
|
|
regs->u_regs[UREG_I0] = ksig->sig;
|
2005-04-16 22:20:36 +00:00
|
|
|
regs->u_regs[UREG_I1] = (unsigned long) &sf->info;
|
|
|
|
|
|
|
|
/* The sigcontext is passed in this way because of how it
|
|
|
|
* is defined in GLIBC's /usr/include/bits/sigcontext.h
|
|
|
|
* for sparc64. It includes the 128 bytes of siginfo_t.
|
|
|
|
*/
|
|
|
|
regs->u_regs[UREG_I2] = (unsigned long) &sf->info;
|
|
|
|
|
|
|
|
/* 5. signal handler */
|
2012-11-08 04:48:13 +00:00
|
|
|
regs->tpc = (unsigned long) ksig->ka.sa.sa_handler;
|
2005-04-16 22:20:36 +00:00
|
|
|
regs->tnpc = (regs->tpc + 4);
|
|
|
|
if (test_thread_flag(TIF_32BIT)) {
|
|
|
|
regs->tpc &= 0xffffffff;
|
|
|
|
regs->tnpc &= 0xffffffff;
|
|
|
|
}
|
|
|
|
/* 4. return to kernel instructions */
|
2012-11-08 04:48:13 +00:00
|
|
|
regs->u_regs[UREG_I7] = (unsigned long)ksig->ka.ka_restorer;
|
2010-09-22 04:41:12 +00:00
|
|
|
return 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void syscall_restart(unsigned long orig_i0, struct pt_regs *regs,
|
sparc: Fix debugger syscall restart interactions.
So, forever, we've had this ptrace_signal_deliver implementation
which tries to handle all of the nasties that can occur when the
debugger looks at a process about to take a signal. It's meant
to address all of these issues inside of the kernel so that the
debugger need not be mindful of such things.
Problem is, this doesn't work.
The idea was that we should do the syscall restart business first, so
that the debugger captures that state. Otherwise, if the debugger for
example saves the child's state, makes the child execute something
else, then restores the saved state, we won't handle the syscall
restart properly because we lose the "we're in a syscall" state.
The code here worked for most cases, but if the debugger actually
passes the signal through to the child unaltered, it's possible that
we would do a syscall restart when we shouldn't have.
In particular this breaks the case of debugging a process under a gdb
which is being debugged by yet another gdb. gdb uses sigsuspend
to wait for SIGCHLD of the inferior, but if gdb itself is being
debugged by a top-level gdb we get a ptrace_stop(). The top-level gdb
does a PTRACE_CONT with SIGCHLD to let the inferior gdb see the
signal. But ptrace_signal_deliver() assumed the debugger would cancel
out the signal and therefore did a syscall restart, because the return
error was ERESTARTNOHAND.
Fix this by simply making ptrace_signal_deliver() a nop, and providing
a way for the debugger to control system call restarting properly:
1) Report a "in syscall" software bit in regs->{tstate,psr}.
It is set early on in trap entry to a system call and is fully
visible to the debugger via ptrace() and regsets.
2) Test this bit right before doing a syscall restart. We have
to do a final recheck right after get_signal_to_deliver() in
case the debugger cleared the bit during ptrace_stop().
3) Clear the bit in trap return so we don't accidently try to set
that bit in the real register.
As a result we also get a ptrace_{is,clear}_syscall() for sparc32 just
like sparc64 has.
M68K has this same exact bug, and is now the only other user of the
ptrace_signal_deliver hook. It needs to be fixed in the same exact
way as sparc.
Signed-off-by: David S. Miller <davem@davemloft.net>
2008-05-11 09:07:19 +00:00
|
|
|
struct sigaction *sa)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
switch (regs->u_regs[UREG_I0]) {
|
|
|
|
case ERESTART_RESTARTBLOCK:
|
|
|
|
case ERESTARTNOHAND:
|
|
|
|
no_system_call_restart:
|
|
|
|
regs->u_regs[UREG_I0] = EINTR;
|
|
|
|
regs->tstate |= (TSTATE_ICARRY|TSTATE_XCARRY);
|
|
|
|
break;
|
|
|
|
case ERESTARTSYS:
|
|
|
|
if (!(sa->sa_flags & SA_RESTART))
|
|
|
|
goto no_system_call_restart;
|
2020-08-23 22:36:59 +00:00
|
|
|
fallthrough;
|
2005-04-16 22:20:36 +00:00
|
|
|
case ERESTARTNOINTR:
|
|
|
|
regs->u_regs[UREG_I0] = orig_i0;
|
|
|
|
regs->tpc -= 4;
|
|
|
|
regs->tnpc -= 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Note that 'init' is a special process: it doesn't get signals it doesn't
|
|
|
|
* want to handle. Thus you cannot kill init even with a SIGKILL even by
|
|
|
|
* mistake.
|
|
|
|
*/
|
2008-04-24 10:01:48 +00:00
|
|
|
static void do_signal(struct pt_regs *regs, unsigned long orig_i0)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2012-11-08 04:48:13 +00:00
|
|
|
struct ksignal ksig;
|
sparc: Fix debugger syscall restart interactions.
So, forever, we've had this ptrace_signal_deliver implementation
which tries to handle all of the nasties that can occur when the
debugger looks at a process about to take a signal. It's meant
to address all of these issues inside of the kernel so that the
debugger need not be mindful of such things.
Problem is, this doesn't work.
The idea was that we should do the syscall restart business first, so
that the debugger captures that state. Otherwise, if the debugger for
example saves the child's state, makes the child execute something
else, then restores the saved state, we won't handle the syscall
restart properly because we lose the "we're in a syscall" state.
The code here worked for most cases, but if the debugger actually
passes the signal through to the child unaltered, it's possible that
we would do a syscall restart when we shouldn't have.
In particular this breaks the case of debugging a process under a gdb
which is being debugged by yet another gdb. gdb uses sigsuspend
to wait for SIGCHLD of the inferior, but if gdb itself is being
debugged by a top-level gdb we get a ptrace_stop(). The top-level gdb
does a PTRACE_CONT with SIGCHLD to let the inferior gdb see the
signal. But ptrace_signal_deliver() assumed the debugger would cancel
out the signal and therefore did a syscall restart, because the return
error was ERESTARTNOHAND.
Fix this by simply making ptrace_signal_deliver() a nop, and providing
a way for the debugger to control system call restarting properly:
1) Report a "in syscall" software bit in regs->{tstate,psr}.
It is set early on in trap entry to a system call and is fully
visible to the debugger via ptrace() and regsets.
2) Test this bit right before doing a syscall restart. We have
to do a final recheck right after get_signal_to_deliver() in
case the debugger cleared the bit during ptrace_stop().
3) Clear the bit in trap return so we don't accidently try to set
that bit in the real register.
As a result we also get a ptrace_{is,clear}_syscall() for sparc32 just
like sparc64 has.
M68K has this same exact bug, and is now the only other user of the
ptrace_signal_deliver hook. It needs to be fixed in the same exact
way as sparc.
Signed-off-by: David S. Miller <davem@davemloft.net>
2008-05-11 09:07:19 +00:00
|
|
|
int restart_syscall;
|
2012-11-08 04:48:13 +00:00
|
|
|
bool has_handler;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-11-15 04:32:16 +00:00
|
|
|
/* It's a lot of work and synchronization to add a new ptrace
|
|
|
|
* register for GDB to save and restore in order to get
|
|
|
|
* orig_i0 correct for syscall restarts when debugging.
|
|
|
|
*
|
2011-11-15 20:57:00 +00:00
|
|
|
* Although it should be the case that most of the global
|
|
|
|
* registers are volatile across a system call, glibc already
|
|
|
|
* depends upon that fact that we preserve them. So we can't
|
|
|
|
* just use any global register to save away the orig_i0 value.
|
|
|
|
*
|
|
|
|
* In particular %g2, %g3, %g4, and %g5 are all assumed to be
|
|
|
|
* preserved across a system call trap by various pieces of
|
|
|
|
* code in glibc.
|
|
|
|
*
|
|
|
|
* %g7 is used as the "thread register". %g6 is not used in
|
|
|
|
* any fixed manner. %g6 is used as a scratch register and
|
2024-01-03 23:16:05 +00:00
|
|
|
* a compiler temporary, but its value is never used across
|
2011-11-15 20:57:00 +00:00
|
|
|
* a system call. Therefore %g6 is usable for orig_i0 storage.
|
2011-11-15 04:32:16 +00:00
|
|
|
*/
|
2008-05-01 10:30:22 +00:00
|
|
|
if (pt_regs_is_syscall(regs) &&
|
2011-11-15 04:32:16 +00:00
|
|
|
(regs->tstate & (TSTATE_XCARRY | TSTATE_ICARRY)))
|
2011-11-15 20:57:00 +00:00
|
|
|
regs->u_regs[UREG_G6] = orig_i0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-04-26 10:17:12 +00:00
|
|
|
#ifdef CONFIG_COMPAT
|
2005-04-16 22:20:36 +00:00
|
|
|
if (test_thread_flag(TIF_32BIT)) {
|
2012-11-08 04:48:13 +00:00
|
|
|
do_signal32(regs);
|
2006-01-19 10:42:49 +00:00
|
|
|
return;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-11-08 04:48:13 +00:00
|
|
|
has_handler = get_signal(&ksig);
|
sparc: Fix debugger syscall restart interactions.
So, forever, we've had this ptrace_signal_deliver implementation
which tries to handle all of the nasties that can occur when the
debugger looks at a process about to take a signal. It's meant
to address all of these issues inside of the kernel so that the
debugger need not be mindful of such things.
Problem is, this doesn't work.
The idea was that we should do the syscall restart business first, so
that the debugger captures that state. Otherwise, if the debugger for
example saves the child's state, makes the child execute something
else, then restores the saved state, we won't handle the syscall
restart properly because we lose the "we're in a syscall" state.
The code here worked for most cases, but if the debugger actually
passes the signal through to the child unaltered, it's possible that
we would do a syscall restart when we shouldn't have.
In particular this breaks the case of debugging a process under a gdb
which is being debugged by yet another gdb. gdb uses sigsuspend
to wait for SIGCHLD of the inferior, but if gdb itself is being
debugged by a top-level gdb we get a ptrace_stop(). The top-level gdb
does a PTRACE_CONT with SIGCHLD to let the inferior gdb see the
signal. But ptrace_signal_deliver() assumed the debugger would cancel
out the signal and therefore did a syscall restart, because the return
error was ERESTARTNOHAND.
Fix this by simply making ptrace_signal_deliver() a nop, and providing
a way for the debugger to control system call restarting properly:
1) Report a "in syscall" software bit in regs->{tstate,psr}.
It is set early on in trap entry to a system call and is fully
visible to the debugger via ptrace() and regsets.
2) Test this bit right before doing a syscall restart. We have
to do a final recheck right after get_signal_to_deliver() in
case the debugger cleared the bit during ptrace_stop().
3) Clear the bit in trap return so we don't accidently try to set
that bit in the real register.
As a result we also get a ptrace_{is,clear}_syscall() for sparc32 just
like sparc64 has.
M68K has this same exact bug, and is now the only other user of the
ptrace_signal_deliver hook. It needs to be fixed in the same exact
way as sparc.
Signed-off-by: David S. Miller <davem@davemloft.net>
2008-05-11 09:07:19 +00:00
|
|
|
|
2011-11-15 04:32:16 +00:00
|
|
|
restart_syscall = 0;
|
|
|
|
if (pt_regs_is_syscall(regs) &&
|
|
|
|
(regs->tstate & (TSTATE_XCARRY | TSTATE_ICARRY))) {
|
|
|
|
restart_syscall = 1;
|
2011-11-15 20:57:00 +00:00
|
|
|
orig_i0 = regs->u_regs[UREG_G6];
|
2011-11-15 04:32:16 +00:00
|
|
|
}
|
sparc: Fix debugger syscall restart interactions.
So, forever, we've had this ptrace_signal_deliver implementation
which tries to handle all of the nasties that can occur when the
debugger looks at a process about to take a signal. It's meant
to address all of these issues inside of the kernel so that the
debugger need not be mindful of such things.
Problem is, this doesn't work.
The idea was that we should do the syscall restart business first, so
that the debugger captures that state. Otherwise, if the debugger for
example saves the child's state, makes the child execute something
else, then restores the saved state, we won't handle the syscall
restart properly because we lose the "we're in a syscall" state.
The code here worked for most cases, but if the debugger actually
passes the signal through to the child unaltered, it's possible that
we would do a syscall restart when we shouldn't have.
In particular this breaks the case of debugging a process under a gdb
which is being debugged by yet another gdb. gdb uses sigsuspend
to wait for SIGCHLD of the inferior, but if gdb itself is being
debugged by a top-level gdb we get a ptrace_stop(). The top-level gdb
does a PTRACE_CONT with SIGCHLD to let the inferior gdb see the
signal. But ptrace_signal_deliver() assumed the debugger would cancel
out the signal and therefore did a syscall restart, because the return
error was ERESTARTNOHAND.
Fix this by simply making ptrace_signal_deliver() a nop, and providing
a way for the debugger to control system call restarting properly:
1) Report a "in syscall" software bit in regs->{tstate,psr}.
It is set early on in trap entry to a system call and is fully
visible to the debugger via ptrace() and regsets.
2) Test this bit right before doing a syscall restart. We have
to do a final recheck right after get_signal_to_deliver() in
case the debugger cleared the bit during ptrace_stop().
3) Clear the bit in trap return so we don't accidently try to set
that bit in the real register.
As a result we also get a ptrace_{is,clear}_syscall() for sparc32 just
like sparc64 has.
M68K has this same exact bug, and is now the only other user of the
ptrace_signal_deliver hook. It needs to be fixed in the same exact
way as sparc.
Signed-off-by: David S. Miller <davem@davemloft.net>
2008-05-11 09:07:19 +00:00
|
|
|
|
2012-11-08 04:48:13 +00:00
|
|
|
if (has_handler) {
|
sparc: Fix debugger syscall restart interactions.
So, forever, we've had this ptrace_signal_deliver implementation
which tries to handle all of the nasties that can occur when the
debugger looks at a process about to take a signal. It's meant
to address all of these issues inside of the kernel so that the
debugger need not be mindful of such things.
Problem is, this doesn't work.
The idea was that we should do the syscall restart business first, so
that the debugger captures that state. Otherwise, if the debugger for
example saves the child's state, makes the child execute something
else, then restores the saved state, we won't handle the syscall
restart properly because we lose the "we're in a syscall" state.
The code here worked for most cases, but if the debugger actually
passes the signal through to the child unaltered, it's possible that
we would do a syscall restart when we shouldn't have.
In particular this breaks the case of debugging a process under a gdb
which is being debugged by yet another gdb. gdb uses sigsuspend
to wait for SIGCHLD of the inferior, but if gdb itself is being
debugged by a top-level gdb we get a ptrace_stop(). The top-level gdb
does a PTRACE_CONT with SIGCHLD to let the inferior gdb see the
signal. But ptrace_signal_deliver() assumed the debugger would cancel
out the signal and therefore did a syscall restart, because the return
error was ERESTARTNOHAND.
Fix this by simply making ptrace_signal_deliver() a nop, and providing
a way for the debugger to control system call restarting properly:
1) Report a "in syscall" software bit in regs->{tstate,psr}.
It is set early on in trap entry to a system call and is fully
visible to the debugger via ptrace() and regsets.
2) Test this bit right before doing a syscall restart. We have
to do a final recheck right after get_signal_to_deliver() in
case the debugger cleared the bit during ptrace_stop().
3) Clear the bit in trap return so we don't accidently try to set
that bit in the real register.
As a result we also get a ptrace_{is,clear}_syscall() for sparc32 just
like sparc64 has.
M68K has this same exact bug, and is now the only other user of the
ptrace_signal_deliver hook. It needs to be fixed in the same exact
way as sparc.
Signed-off-by: David S. Miller <davem@davemloft.net>
2008-05-11 09:07:19 +00:00
|
|
|
if (restart_syscall)
|
2012-11-08 04:48:13 +00:00
|
|
|
syscall_restart(orig_i0, regs, &ksig.ka.sa);
|
|
|
|
signal_setup_done(setup_rt_frame(&ksig, regs), &ksig, 0);
|
|
|
|
} else {
|
|
|
|
if (restart_syscall) {
|
|
|
|
switch (regs->u_regs[UREG_I0]) {
|
|
|
|
case ERESTARTNOHAND:
|
|
|
|
case ERESTARTSYS:
|
|
|
|
case ERESTARTNOINTR:
|
|
|
|
/* replay the system call when we are done */
|
|
|
|
regs->u_regs[UREG_I0] = orig_i0;
|
|
|
|
regs->tpc -= 4;
|
|
|
|
regs->tnpc -= 4;
|
|
|
|
pt_regs_clear_syscall(regs);
|
2020-08-23 22:36:59 +00:00
|
|
|
fallthrough;
|
2012-11-08 04:48:13 +00:00
|
|
|
case ERESTART_RESTARTBLOCK:
|
|
|
|
regs->u_regs[UREG_G1] = __NR_restart_syscall;
|
|
|
|
regs->tpc -= 4;
|
|
|
|
regs->tnpc -= 4;
|
|
|
|
pt_regs_clear_syscall(regs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
restore_saved_sigmask();
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-24 10:15:22 +00:00
|
|
|
void do_notify_resume(struct pt_regs *regs, unsigned long orig_i0, unsigned long thread_info_flags)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2013-09-14 12:02:11 +00:00
|
|
|
user_exit();
|
2016-10-13 04:36:13 +00:00
|
|
|
if (thread_info_flags & _TIF_UPROBE)
|
|
|
|
uprobe_notify_resume(regs);
|
2020-10-09 21:44:37 +00:00
|
|
|
if (thread_info_flags & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL))
|
2008-04-24 10:01:48 +00:00
|
|
|
do_signal(regs, orig_i0);
|
2020-10-03 16:49:22 +00:00
|
|
|
if (thread_info_flags & _TIF_NOTIFY_RESUME)
|
2022-02-09 18:20:45 +00:00
|
|
|
resume_user_mode_work(regs);
|
2013-09-14 12:02:11 +00:00
|
|
|
user_enter();
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
KEYS: Add a keyctl to install a process's session keyring on its parent [try #6]
Add a keyctl to install a process's session keyring onto its parent. This
replaces the parent's session keyring. Because the COW credential code does
not permit one process to change another process's credentials directly, the
change is deferred until userspace next starts executing again. Normally this
will be after a wait*() syscall.
To support this, three new security hooks have been provided:
cred_alloc_blank() to allocate unset security creds, cred_transfer() to fill in
the blank security creds and key_session_to_parent() - which asks the LSM if
the process may replace its parent's session keyring.
The replacement may only happen if the process has the same ownership details
as its parent, and the process has LINK permission on the session keyring, and
the session keyring is owned by the process, and the LSM permits it.
Note that this requires alteration to each architecture's notify_resume path.
This has been done for all arches barring blackfin, m68k* and xtensa, all of
which need assembly alteration to support TIF_NOTIFY_RESUME. This allows the
replacement to be performed at the point the parent process resumes userspace
execution.
This allows the userspace AFS pioctl emulation to fully emulate newpag() and
the VIOCSETTOK and VIOCSETTOK2 pioctls, all of which require the ability to
alter the parent process's PAG membership. However, since kAFS doesn't use
PAGs per se, but rather dumps the keys into the session keyring, the session
keyring of the parent must be replaced if, for example, VIOCSETTOK is passed
the newpag flag.
This can be tested with the following program:
#include <stdio.h>
#include <stdlib.h>
#include <keyutils.h>
#define KEYCTL_SESSION_TO_PARENT 18
#define OSERROR(X, S) do { if ((long)(X) == -1) { perror(S); exit(1); } } while(0)
int main(int argc, char **argv)
{
key_serial_t keyring, key;
long ret;
keyring = keyctl_join_session_keyring(argv[1]);
OSERROR(keyring, "keyctl_join_session_keyring");
key = add_key("user", "a", "b", 1, keyring);
OSERROR(key, "add_key");
ret = keyctl(KEYCTL_SESSION_TO_PARENT);
OSERROR(ret, "KEYCTL_SESSION_TO_PARENT");
return 0;
}
Compiled and linked with -lkeyutils, you should see something like:
[dhowells@andromeda ~]$ keyctl show
Session Keyring
-3 --alswrv 4043 4043 keyring: _ses
355907932 --alswrv 4043 -1 \_ keyring: _uid.4043
[dhowells@andromeda ~]$ /tmp/newpag
[dhowells@andromeda ~]$ keyctl show
Session Keyring
-3 --alswrv 4043 4043 keyring: _ses
1055658746 --alswrv 4043 4043 \_ user: a
[dhowells@andromeda ~]$ /tmp/newpag hello
[dhowells@andromeda ~]$ keyctl show
Session Keyring
-3 --alswrv 4043 4043 keyring: hello
340417692 --alswrv 4043 4043 \_ user: a
Where the test program creates a new session keyring, sticks a user key named
'a' into it and then installs it on its parent.
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: James Morris <jmorris@namei.org>
2009-09-02 08:14:21 +00:00
|
|
|
|
2021-04-29 19:07:32 +00:00
|
|
|
/*
|
|
|
|
* Compile-time assertions for siginfo_t offsets. Check NSIG* as well, as
|
|
|
|
* changes likely come with new fields that should be added below.
|
|
|
|
*/
|
|
|
|
static_assert(NSIGILL == 11);
|
|
|
|
static_assert(NSIGFPE == 15);
|
2023-06-13 00:10:53 +00:00
|
|
|
static_assert(NSIGSEGV == 10);
|
2021-04-29 19:07:32 +00:00
|
|
|
static_assert(NSIGBUS == 5);
|
|
|
|
static_assert(NSIGTRAP == 6);
|
|
|
|
static_assert(NSIGCHLD == 6);
|
|
|
|
static_assert(NSIGSYS == 2);
|
2021-05-04 16:25:22 +00:00
|
|
|
static_assert(sizeof(siginfo_t) == 128);
|
|
|
|
static_assert(__alignof__(siginfo_t) == 8);
|
2021-04-29 19:07:32 +00:00
|
|
|
static_assert(offsetof(siginfo_t, si_signo) == 0x00);
|
|
|
|
static_assert(offsetof(siginfo_t, si_errno) == 0x04);
|
|
|
|
static_assert(offsetof(siginfo_t, si_code) == 0x08);
|
|
|
|
static_assert(offsetof(siginfo_t, si_pid) == 0x10);
|
|
|
|
static_assert(offsetof(siginfo_t, si_uid) == 0x14);
|
|
|
|
static_assert(offsetof(siginfo_t, si_tid) == 0x10);
|
|
|
|
static_assert(offsetof(siginfo_t, si_overrun) == 0x14);
|
|
|
|
static_assert(offsetof(siginfo_t, si_status) == 0x18);
|
|
|
|
static_assert(offsetof(siginfo_t, si_utime) == 0x20);
|
|
|
|
static_assert(offsetof(siginfo_t, si_stime) == 0x28);
|
|
|
|
static_assert(offsetof(siginfo_t, si_value) == 0x18);
|
|
|
|
static_assert(offsetof(siginfo_t, si_int) == 0x18);
|
|
|
|
static_assert(offsetof(siginfo_t, si_ptr) == 0x18);
|
|
|
|
static_assert(offsetof(siginfo_t, si_addr) == 0x10);
|
|
|
|
static_assert(offsetof(siginfo_t, si_trapno) == 0x18);
|
|
|
|
static_assert(offsetof(siginfo_t, si_addr_lsb) == 0x18);
|
|
|
|
static_assert(offsetof(siginfo_t, si_lower) == 0x20);
|
|
|
|
static_assert(offsetof(siginfo_t, si_upper) == 0x28);
|
|
|
|
static_assert(offsetof(siginfo_t, si_pkey) == 0x20);
|
|
|
|
static_assert(offsetof(siginfo_t, si_perf_data) == 0x18);
|
|
|
|
static_assert(offsetof(siginfo_t, si_perf_type) == 0x20);
|
signal: Deliver SIGTRAP on perf event asynchronously if blocked
With SIGTRAP on perf events, we have encountered termination of
processes due to user space attempting to block delivery of SIGTRAP.
Consider this case:
<set up SIGTRAP on a perf event>
...
sigset_t s;
sigemptyset(&s);
sigaddset(&s, SIGTRAP | <and others>);
sigprocmask(SIG_BLOCK, &s, ...);
...
<perf event triggers>
When the perf event triggers, while SIGTRAP is blocked, force_sig_perf()
will force the signal, but revert back to the default handler, thus
terminating the task.
This makes sense for error conditions, but not so much for explicitly
requested monitoring. However, the expectation is still that signals
generated by perf events are synchronous, which will no longer be the
case if the signal is blocked and delivered later.
To give user space the ability to clearly distinguish synchronous from
asynchronous signals, introduce siginfo_t::si_perf_flags and
TRAP_PERF_FLAG_ASYNC (opted for flags in case more binary information is
required in future).
The resolution to the problem is then to (a) no longer force the signal
(avoiding the terminations), but (b) tell user space via si_perf_flags
if the signal was synchronous or not, so that such signals can be
handled differently (e.g. let user space decide to ignore or consider
the data imprecise).
The alternative of making the kernel ignore SIGTRAP on perf events if
the signal is blocked may work for some usecases, but likely causes
issues in others that then have to revert back to interception of
sigprocmask() (which we want to avoid). [ A concrete example: when using
breakpoint perf events to track data-flow, in a region of code where
signals are blocked, data-flow can no longer be tracked accurately.
When a relevant asynchronous signal is received after unblocking the
signal, the data-flow tracking logic needs to know its state is
imprecise. ]
Fixes: 97ba62b27867 ("perf: Add support for SIGTRAP on perf events")
Reported-by: Dmitry Vyukov <dvyukov@google.com>
Signed-off-by: Marco Elver <elver@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>
Tested-by: Dmitry Vyukov <dvyukov@google.com>
Link: https://lore.kernel.org/r/20220404111204.935357-1-elver@google.com
2022-04-04 11:12:04 +00:00
|
|
|
static_assert(offsetof(siginfo_t, si_perf_flags) == 0x24);
|
2021-04-29 19:07:32 +00:00
|
|
|
static_assert(offsetof(siginfo_t, si_band) == 0x10);
|
|
|
|
static_assert(offsetof(siginfo_t, si_fd) == 0x14);
|