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 22:07:57 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2008-04-27 17:26:36 +08:00
|
|
|
/* arch/sparc64/kernel/signal32.c
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Copyright (C) 1991, 1992 Linus Torvalds
|
|
|
|
* Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
|
|
|
|
* 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>
|
|
|
|
#include <linux/unistd.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/tty.h>
|
|
|
|
#include <linux/binfmts.h>
|
|
|
|
#include <linux/compat.h>
|
|
|
|
#include <linux/bitops.h>
|
2008-07-27 16:08:02 +08:00
|
|
|
#include <linux/tracehook.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-12-25 03:46:01 +08:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/ptrace.h>
|
|
|
|
#include <asm/pgtable.h>
|
|
|
|
#include <asm/psrcompat.h>
|
|
|
|
#include <asm/fpumacro.h>
|
|
|
|
#include <asm/visasm.h>
|
2006-10-03 05:17:57 +08:00
|
|
|
#include <asm/compat_signal.h>
|
2012-03-29 01:30:03 +08:00
|
|
|
#include <asm/switch_to.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-08-21 08:14:54 +08:00
|
|
|
#include "sigutil.h"
|
2014-05-17 05:26:00 +08:00
|
|
|
#include "kernel.h"
|
2011-08-21 08:14:54 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* This magic should be in g_upper[0] for all upper parts
|
|
|
|
* to be valid.
|
|
|
|
*/
|
|
|
|
#define SIGINFO_EXTRA_V8PLUS_MAGIC 0x130e269
|
|
|
|
typedef struct {
|
|
|
|
unsigned int g_upper[8];
|
|
|
|
unsigned int o_upper[8];
|
|
|
|
unsigned int asi;
|
|
|
|
} siginfo_extra_v8plus_t;
|
|
|
|
|
2008-04-27 17:26:36 +08:00
|
|
|
struct signal_frame32 {
|
2005-04-17 06:20:36 +08:00
|
|
|
struct sparc_stackf32 ss;
|
|
|
|
__siginfo32_t info;
|
2011-08-21 08:14:54 +08:00
|
|
|
/* __siginfo_fpu_t * */ u32 fpu_save;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned int insns[2];
|
|
|
|
unsigned int extramask[_COMPAT_NSIG_WORDS - 1];
|
|
|
|
unsigned int extra_size; /* Should be sizeof(siginfo_extra_v8plus_t) */
|
|
|
|
/* Only valid if (info.si_regs.psr & (PSR_VERS|PSR_IMPL)) == PSR_V8PLUS */
|
|
|
|
siginfo_extra_v8plus_t v8plus;
|
2011-08-21 08:14:54 +08:00
|
|
|
/* __siginfo_rwin_t * */u32 rwin_save;
|
|
|
|
} __attribute__((aligned(8)));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
struct rt_signal_frame32 {
|
|
|
|
struct sparc_stackf32 ss;
|
|
|
|
compat_siginfo_t info;
|
|
|
|
struct pt_regs32 regs;
|
|
|
|
compat_sigset_t mask;
|
2011-08-21 08:14:54 +08:00
|
|
|
/* __siginfo_fpu_t * */ u32 fpu_save;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned int insns[2];
|
2012-12-23 16:41:17 +08:00
|
|
|
compat_stack_t stack;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned int extra_size; /* Should be sizeof(siginfo_extra_v8plus_t) */
|
|
|
|
/* Only valid if (regs.psr & (PSR_VERS|PSR_IMPL)) == PSR_V8PLUS */
|
|
|
|
siginfo_extra_v8plus_t v8plus;
|
2011-08-21 08:14:54 +08:00
|
|
|
/* __siginfo_rwin_t * */u32 rwin_save;
|
|
|
|
} __attribute__((aligned(8)));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-05-29 12:21:31 +08:00
|
|
|
/* Checks if the fp is valid. We always build 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, int fplen)
|
|
|
|
{
|
|
|
|
if ((((unsigned long) fp) & 15) ||
|
|
|
|
((unsigned long)fp) > 0x100000000ULL - fplen)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-04-27 17:26:36 +08:00
|
|
|
void do_sigreturn32(struct pt_regs *regs)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-04-27 17:26:36 +08:00
|
|
|
struct signal_frame32 __user *sf;
|
2011-08-21 08:14:54 +08:00
|
|
|
compat_uptr_t fpu_save;
|
|
|
|
compat_uptr_t rwin_save;
|
2016-05-29 12:21:31 +08:00
|
|
|
unsigned int psr, ufp;
|
2016-03-11 07:21:43 +08:00
|
|
|
unsigned int pc, npc;
|
2005-04-17 06:20:36 +08:00
|
|
|
sigset_t set;
|
2014-05-17 05:26:01 +08:00
|
|
|
compat_sigset_t seta;
|
2005-04-17 06:20:36 +08:00
|
|
|
int err, i;
|
|
|
|
|
2008-04-27 17:26:36 +08:00
|
|
|
/* Always make any pending restarted system calls return -EINTR */
|
2015-02-13 07:01:14 +08:00
|
|
|
current->restart_block.fn = do_no_restart_syscall;
|
2008-04-27 17:26:36 +08:00
|
|
|
|
|
|
|
synchronize_user_stack();
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
regs->u_regs[UREG_FP] &= 0x00000000ffffffffUL;
|
2008-04-27 17:26:36 +08:00
|
|
|
sf = (struct signal_frame32 __user *) regs->u_regs[UREG_FP];
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* 1. Make sure we are not getting garbage from the user */
|
2016-05-29 12:21:31 +08:00
|
|
|
if (invalid_frame_pointer(sf, sizeof(*sf)))
|
|
|
|
goto segv;
|
|
|
|
|
|
|
|
if (get_user(ufp, &sf->info.si_regs.u_regs[UREG_FP]))
|
|
|
|
goto segv;
|
|
|
|
|
|
|
|
if (ufp & 0x7)
|
2005-04-17 06:20:36 +08:00
|
|
|
goto segv;
|
|
|
|
|
2016-05-29 12:21:31 +08:00
|
|
|
if (__get_user(pc, &sf->info.si_regs.pc) ||
|
2012-04-23 04:51:36 +08:00
|
|
|
__get_user(npc, &sf->info.si_regs.npc))
|
|
|
|
goto segv;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if ((pc | npc) & 3)
|
|
|
|
goto segv;
|
|
|
|
|
|
|
|
if (test_thread_flag(TIF_32BIT)) {
|
|
|
|
pc &= 0xffffffff;
|
|
|
|
npc &= 0xffffffff;
|
|
|
|
}
|
|
|
|
regs->tpc = pc;
|
|
|
|
regs->tnpc = npc;
|
|
|
|
|
|
|
|
/* 2. Restore the state */
|
|
|
|
err = __get_user(regs->y, &sf->info.si_regs.y);
|
|
|
|
err |= __get_user(psr, &sf->info.si_regs.psr);
|
|
|
|
|
|
|
|
for (i = UREG_G1; i <= UREG_I7; i++)
|
|
|
|
err |= __get_user(regs->u_regs[i], &sf->info.si_regs.u_regs[i]);
|
|
|
|
if ((psr & (PSR_VERS|PSR_IMPL)) == PSR_V8PLUS) {
|
|
|
|
err |= __get_user(i, &sf->v8plus.g_upper[0]);
|
|
|
|
if (i == SIGINFO_EXTRA_V8PLUS_MAGIC) {
|
|
|
|
unsigned long asi;
|
|
|
|
|
|
|
|
for (i = UREG_G1; i <= UREG_I7; i++)
|
|
|
|
err |= __get_user(((u32 *)regs->u_regs)[2*i], &sf->v8plus.g_upper[i]);
|
|
|
|
err |= __get_user(asi, &sf->v8plus.asi);
|
|
|
|
regs->tstate &= ~TSTATE_ASI;
|
|
|
|
regs->tstate |= ((asi & 0xffUL) << 24UL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* User can only change condition codes in %tstate. */
|
|
|
|
regs->tstate &= ~(TSTATE_ICC|TSTATE_XCC);
|
|
|
|
regs->tstate |= psr_to_tstate_icc(psr);
|
|
|
|
|
2008-05-01 18:30:22 +08: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 17:07:19 +08:00
|
|
|
pt_regs_clear_syscall(regs);
|
2008-05-01 18:30:22 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
err |= __get_user(fpu_save, &sf->fpu_save);
|
2011-08-21 08:14:54 +08:00
|
|
|
if (!err && fpu_save)
|
|
|
|
err |= restore_fpu_state(regs, compat_ptr(fpu_save));
|
|
|
|
err |= __get_user(rwin_save, &sf->rwin_save);
|
|
|
|
if (!err && rwin_save) {
|
|
|
|
if (restore_rwin_state(compat_ptr(rwin_save)))
|
|
|
|
goto segv;
|
|
|
|
}
|
2014-05-17 05:26:01 +08:00
|
|
|
err |= __get_user(seta.sig[0], &sf->info.si_mask);
|
|
|
|
err |= copy_from_user(&seta.sig[1], &sf->extramask,
|
2005-04-17 06:20:36 +08:00
|
|
|
(_COMPAT_NSIG_WORDS - 1) * sizeof(unsigned int));
|
|
|
|
if (err)
|
|
|
|
goto segv;
|
2014-05-17 05:26:01 +08:00
|
|
|
|
|
|
|
set.sig[0] = seta.sig[0] + (((long)seta.sig[1]) << 32);
|
2011-08-11 21:57:02 +08:00
|
|
|
set_current_blocked(&set);
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
segv:
|
|
|
|
force_sig(SIGSEGV, current);
|
|
|
|
}
|
|
|
|
|
|
|
|
asmlinkage void do_rt_sigreturn32(struct pt_regs *regs)
|
|
|
|
{
|
|
|
|
struct rt_signal_frame32 __user *sf;
|
2016-05-29 12:21:31 +08:00
|
|
|
unsigned int psr, pc, npc, ufp;
|
2011-08-21 08:14:54 +08:00
|
|
|
compat_uptr_t fpu_save;
|
|
|
|
compat_uptr_t rwin_save;
|
2005-04-17 06:20:36 +08:00
|
|
|
sigset_t set;
|
|
|
|
int err, i;
|
|
|
|
|
|
|
|
/* Always make any pending restarted system calls return -EINTR */
|
2015-02-13 07:01:14 +08:00
|
|
|
current->restart_block.fn = do_no_restart_syscall;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
synchronize_user_stack();
|
|
|
|
regs->u_regs[UREG_FP] &= 0x00000000ffffffffUL;
|
|
|
|
sf = (struct rt_signal_frame32 __user *) regs->u_regs[UREG_FP];
|
|
|
|
|
|
|
|
/* 1. Make sure we are not getting garbage from the user */
|
2016-05-29 12:21:31 +08:00
|
|
|
if (invalid_frame_pointer(sf, sizeof(*sf)))
|
2005-04-17 06:20:36 +08:00
|
|
|
goto segv;
|
|
|
|
|
2016-05-29 12:21:31 +08:00
|
|
|
if (get_user(ufp, &sf->regs.u_regs[UREG_FP]))
|
|
|
|
goto segv;
|
|
|
|
|
|
|
|
if (ufp & 0x7)
|
|
|
|
goto segv;
|
|
|
|
|
|
|
|
if (__get_user(pc, &sf->regs.pc) ||
|
2012-04-23 04:51:36 +08:00
|
|
|
__get_user(npc, &sf->regs.npc))
|
|
|
|
goto segv;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if ((pc | npc) & 3)
|
|
|
|
goto segv;
|
|
|
|
|
|
|
|
if (test_thread_flag(TIF_32BIT)) {
|
|
|
|
pc &= 0xffffffff;
|
|
|
|
npc &= 0xffffffff;
|
|
|
|
}
|
|
|
|
regs->tpc = pc;
|
|
|
|
regs->tnpc = npc;
|
|
|
|
|
|
|
|
/* 2. Restore the state */
|
|
|
|
err = __get_user(regs->y, &sf->regs.y);
|
|
|
|
err |= __get_user(psr, &sf->regs.psr);
|
|
|
|
|
|
|
|
for (i = UREG_G1; i <= UREG_I7; i++)
|
|
|
|
err |= __get_user(regs->u_regs[i], &sf->regs.u_regs[i]);
|
|
|
|
if ((psr & (PSR_VERS|PSR_IMPL)) == PSR_V8PLUS) {
|
|
|
|
err |= __get_user(i, &sf->v8plus.g_upper[0]);
|
|
|
|
if (i == SIGINFO_EXTRA_V8PLUS_MAGIC) {
|
|
|
|
unsigned long asi;
|
|
|
|
|
|
|
|
for (i = UREG_G1; i <= UREG_I7; i++)
|
|
|
|
err |= __get_user(((u32 *)regs->u_regs)[2*i], &sf->v8plus.g_upper[i]);
|
|
|
|
err |= __get_user(asi, &sf->v8plus.asi);
|
|
|
|
regs->tstate &= ~TSTATE_ASI;
|
|
|
|
regs->tstate |= ((asi & 0xffUL) << 24UL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* User can only change condition codes in %tstate. */
|
|
|
|
regs->tstate &= ~(TSTATE_ICC|TSTATE_XCC);
|
|
|
|
regs->tstate |= psr_to_tstate_icc(psr);
|
|
|
|
|
2008-05-01 18:30:22 +08: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 17:07:19 +08:00
|
|
|
pt_regs_clear_syscall(regs);
|
2008-05-01 18:30:22 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
err |= __get_user(fpu_save, &sf->fpu_save);
|
2011-08-21 08:14:54 +08:00
|
|
|
if (!err && fpu_save)
|
|
|
|
err |= restore_fpu_state(regs, compat_ptr(fpu_save));
|
2017-09-05 00:28:06 +08:00
|
|
|
err |= get_compat_sigset(&set, &sf->mask);
|
2012-12-23 16:41:17 +08:00
|
|
|
err |= compat_restore_altstack(&sf->stack);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (err)
|
|
|
|
goto segv;
|
|
|
|
|
2011-08-21 08:14:54 +08:00
|
|
|
err |= __get_user(rwin_save, &sf->rwin_save);
|
|
|
|
if (!err && rwin_save) {
|
|
|
|
if (restore_rwin_state(compat_ptr(rwin_save)))
|
|
|
|
goto segv;
|
|
|
|
}
|
|
|
|
|
2011-08-11 21:57:02 +08:00
|
|
|
set_current_blocked(&set);
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
segv:
|
|
|
|
force_sig(SIGSEGV, current);
|
|
|
|
}
|
|
|
|
|
2012-11-08 12:48:13 +08:00
|
|
|
static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs, unsigned long framesize)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned long sp;
|
|
|
|
|
|
|
|
regs->u_regs[UREG_FP] &= 0x00000000ffffffffUL;
|
|
|
|
sp = regs->u_regs[UREG_FP];
|
|
|
|
|
2008-05-08 09:54:05 +08: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-17 06:20:36 +08:00
|
|
|
/* This is the X/Open sanctioned signal stack switching. */
|
2012-11-08 12:48:13 +08:00
|
|
|
sp = sigsp(sp, ksig) - framesize;
|
2010-02-10 08:18:40 +08:00
|
|
|
|
2008-05-08 09:54:05 +08: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 08:18:40 +08:00
|
|
|
sp &= ~15UL;
|
2008-05-08 09:54:05 +08:00
|
|
|
|
2010-02-10 08:18:40 +08:00
|
|
|
return (void __user *) sp;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2010-09-21 14:24:52 +08:00
|
|
|
/* The I-cache flush instruction only works in the primary ASI, which
|
|
|
|
* right now is the nucleus, aka. kernel space.
|
|
|
|
*
|
|
|
|
* Therefore we have to kick the instructions out using the kernel
|
|
|
|
* side linear mapping of the physical address backing the user
|
|
|
|
* instructions.
|
|
|
|
*/
|
|
|
|
static void flush_signal_insns(unsigned long address)
|
|
|
|
{
|
|
|
|
unsigned long pstate, paddr;
|
|
|
|
pte_t *ptep, pte;
|
|
|
|
pgd_t *pgdp;
|
|
|
|
pud_t *pudp;
|
|
|
|
pmd_t *pmdp;
|
|
|
|
|
|
|
|
/* Commit all stores of the instructions we are about to flush. */
|
|
|
|
wmb();
|
|
|
|
|
|
|
|
/* Disable cross-call reception. In this way even a very wide
|
|
|
|
* munmap() on another cpu can't tear down the page table
|
|
|
|
* hierarchy from underneath us, since that can't complete
|
|
|
|
* until the IPI tlb flush returns.
|
|
|
|
*/
|
|
|
|
|
|
|
|
__asm__ __volatile__("rdpr %%pstate, %0" : "=r" (pstate));
|
|
|
|
__asm__ __volatile__("wrpr %0, %1, %%pstate"
|
|
|
|
: : "r" (pstate), "i" (PSTATE_IE));
|
|
|
|
|
|
|
|
pgdp = pgd_offset(current->mm, address);
|
|
|
|
if (pgd_none(*pgdp))
|
|
|
|
goto out_irqs_on;
|
|
|
|
pudp = pud_offset(pgdp, address);
|
|
|
|
if (pud_none(*pudp))
|
|
|
|
goto out_irqs_on;
|
|
|
|
pmdp = pmd_offset(pudp, address);
|
|
|
|
if (pmd_none(*pmdp))
|
|
|
|
goto out_irqs_on;
|
|
|
|
|
|
|
|
ptep = pte_offset_map(pmdp, address);
|
|
|
|
pte = *ptep;
|
|
|
|
if (!pte_present(pte))
|
|
|
|
goto out_unmap;
|
|
|
|
|
|
|
|
paddr = (unsigned long) page_address(pte_page(pte));
|
|
|
|
|
|
|
|
__asm__ __volatile__("flush %0 + %1"
|
|
|
|
: /* no outputs */
|
|
|
|
: "r" (paddr),
|
|
|
|
"r" (address & (PAGE_SIZE - 1))
|
|
|
|
: "memory");
|
|
|
|
|
|
|
|
out_unmap:
|
|
|
|
pte_unmap(ptep);
|
|
|
|
out_irqs_on:
|
|
|
|
__asm__ __volatile__("wrpr %0, 0x0, %%pstate" : : "r" (pstate));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-11-08 12:48:13 +08:00
|
|
|
static int setup_frame32(struct ksignal *ksig, struct pt_regs *regs,
|
|
|
|
sigset_t *oldset)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-04-27 17:26:36 +08:00
|
|
|
struct signal_frame32 __user *sf;
|
2011-08-21 08:14:54 +08:00
|
|
|
int i, err, wsaved;
|
|
|
|
void __user *tail;
|
2005-04-17 06:20:36 +08:00
|
|
|
int sigframe_size;
|
|
|
|
u32 psr;
|
2014-05-17 05:26:01 +08:00
|
|
|
compat_sigset_t seta;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* 1. Make sure everything is clean */
|
|
|
|
synchronize_user_stack();
|
|
|
|
save_and_clear_fpu();
|
|
|
|
|
2011-08-21 08:14:54 +08:00
|
|
|
wsaved = get_thread_wsaved();
|
|
|
|
|
|
|
|
sigframe_size = sizeof(*sf);
|
|
|
|
if (current_thread_info()->fpsaved[0] & FPRS_FEF)
|
|
|
|
sigframe_size += sizeof(__siginfo_fpu_t);
|
|
|
|
if (wsaved)
|
|
|
|
sigframe_size += sizeof(__siginfo_rwin_t);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-04-27 17:26:36 +08:00
|
|
|
sf = (struct signal_frame32 __user *)
|
2012-11-08 12:48:13 +08:00
|
|
|
get_sigframe(ksig, regs, sigframe_size);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-11-08 12:48:13 +08:00
|
|
|
if (invalid_frame_pointer(sf, sigframe_size)) {
|
|
|
|
do_exit(SIGILL);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-08-21 08:14:54 +08:00
|
|
|
tail = (sf + 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* 2. Save the current process state */
|
|
|
|
if (test_thread_flag(TIF_32BIT)) {
|
|
|
|
regs->tpc &= 0xffffffff;
|
|
|
|
regs->tnpc &= 0xffffffff;
|
|
|
|
}
|
|
|
|
err = put_user(regs->tpc, &sf->info.si_regs.pc);
|
|
|
|
err |= __put_user(regs->tnpc, &sf->info.si_regs.npc);
|
|
|
|
err |= __put_user(regs->y, &sf->info.si_regs.y);
|
|
|
|
psr = tstate_to_psr(regs->tstate);
|
|
|
|
if (current_thread_info()->fpsaved[0] & FPRS_FEF)
|
|
|
|
psr |= PSR_EF;
|
|
|
|
err |= __put_user(psr, &sf->info.si_regs.psr);
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
err |= __put_user(regs->u_regs[i], &sf->info.si_regs.u_regs[i]);
|
|
|
|
err |= __put_user(sizeof(siginfo_extra_v8plus_t), &sf->extra_size);
|
|
|
|
err |= __put_user(SIGINFO_EXTRA_V8PLUS_MAGIC, &sf->v8plus.g_upper[0]);
|
|
|
|
for (i = 1; i < 16; i++)
|
|
|
|
err |= __put_user(((u32 *)regs->u_regs)[2*i],
|
|
|
|
&sf->v8plus.g_upper[i]);
|
|
|
|
err |= __put_user((regs->tstate & TSTATE_ASI) >> 24UL,
|
|
|
|
&sf->v8plus.asi);
|
|
|
|
|
|
|
|
if (psr & PSR_EF) {
|
2011-08-21 08:14:54 +08:00
|
|
|
__siginfo_fpu_t __user *fp = tail;
|
|
|
|
tail += sizeof(*fp);
|
|
|
|
err |= save_fpu_state(regs, fp);
|
|
|
|
err |= __put_user((u64)fp, &sf->fpu_save);
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
|
|
|
err |= __put_user(0, &sf->fpu_save);
|
|
|
|
}
|
2011-08-21 08:14:54 +08:00
|
|
|
if (wsaved) {
|
|
|
|
__siginfo_rwin_t __user *rwp = tail;
|
|
|
|
tail += sizeof(*rwp);
|
|
|
|
err |= save_rwin_state(wsaved, rwp);
|
|
|
|
err |= __put_user((u64)rwp, &sf->rwin_save);
|
|
|
|
set_thread_wsaved(0);
|
|
|
|
} else {
|
|
|
|
err |= __put_user(0, &sf->rwin_save);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-05-17 05:26:01 +08:00
|
|
|
/* If these change we need to know - assignments to seta relies on these sizes */
|
|
|
|
BUILD_BUG_ON(_NSIG_WORDS != 1);
|
|
|
|
BUILD_BUG_ON(_COMPAT_NSIG_WORDS != 2);
|
|
|
|
seta.sig[1] = (oldset->sig[0] >> 32);
|
|
|
|
seta.sig[0] = oldset->sig[0];
|
|
|
|
|
|
|
|
err |= __put_user(seta.sig[0], &sf->info.si_mask);
|
|
|
|
err |= __copy_to_user(sf->extramask, &seta.sig[1],
|
2005-04-17 06:20:36 +08:00
|
|
|
(_COMPAT_NSIG_WORDS - 1) * sizeof(unsigned int));
|
|
|
|
|
2011-08-21 08:14:54 +08:00
|
|
|
if (!wsaved) {
|
|
|
|
err |= copy_in_user((u32 __user *)sf,
|
|
|
|
(u32 __user *)(regs->u_regs[UREG_FP]),
|
|
|
|
sizeof(struct reg_window32));
|
|
|
|
} else {
|
|
|
|
struct reg_window *rp;
|
|
|
|
|
|
|
|
rp = ¤t_thread_info()->reg_window[wsaved - 1];
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
err |= __put_user(rp->locals[i], &sf->ss.locals[i]);
|
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
err |= __put_user(rp->ins[i], &sf->ss.ins[i]);
|
|
|
|
err |= __put_user(rp->ins[6], &sf->ss.fp);
|
|
|
|
err |= __put_user(rp->ins[7], &sf->ss.callers_pc);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
if (err)
|
2012-11-08 12:48:13 +08:00
|
|
|
return err;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* 3. signal handler back-trampoline and parameters */
|
|
|
|
regs->u_regs[UREG_FP] = (unsigned long) sf;
|
2012-11-08 12:48:13 +08:00
|
|
|
regs->u_regs[UREG_I0] = ksig->sig;
|
2005-04-17 06:20:36 +08:00
|
|
|
regs->u_regs[UREG_I1] = (unsigned long) &sf->info;
|
|
|
|
regs->u_regs[UREG_I2] = (unsigned long) &sf->info;
|
|
|
|
|
|
|
|
/* 4. signal handler */
|
2012-11-08 12:48:13 +08:00
|
|
|
regs->tpc = (unsigned long) ksig->ka.sa.sa_handler;
|
2005-04-17 06:20:36 +08:00
|
|
|
regs->tnpc = (regs->tpc + 4);
|
|
|
|
if (test_thread_flag(TIF_32BIT)) {
|
|
|
|
regs->tpc &= 0xffffffff;
|
|
|
|
regs->tnpc &= 0xffffffff;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 5. return to kernel instructions */
|
2012-11-08 12:48:13 +08:00
|
|
|
if (ksig->ka.ka_restorer) {
|
|
|
|
regs->u_regs[UREG_I7] = (unsigned long)ksig->ka.ka_restorer;
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
|
|
|
unsigned long address = ((unsigned long)&(sf->insns[0]));
|
|
|
|
|
|
|
|
regs->u_regs[UREG_I7] = (unsigned long) (&(sf->insns[0]) - 2);
|
|
|
|
|
|
|
|
err = __put_user(0x821020d8, &sf->insns[0]); /*mov __NR_sigreturn, %g1*/
|
|
|
|
err |= __put_user(0x91d02010, &sf->insns[1]); /*t 0x10*/
|
|
|
|
if (err)
|
2012-11-08 12:48:13 +08:00
|
|
|
return err;
|
2010-09-21 14:24:52 +08:00
|
|
|
flush_signal_insns(address);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2010-09-22 13:30:13 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2012-11-08 12:48:13 +08:00
|
|
|
static int setup_rt_frame32(struct ksignal *ksig, struct pt_regs *regs,
|
|
|
|
sigset_t *oldset)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct rt_signal_frame32 __user *sf;
|
2011-08-21 08:14:54 +08:00
|
|
|
int i, err, wsaved;
|
|
|
|
void __user *tail;
|
2005-04-17 06:20:36 +08:00
|
|
|
int sigframe_size;
|
|
|
|
u32 psr;
|
|
|
|
|
|
|
|
/* 1. Make sure everything is clean */
|
|
|
|
synchronize_user_stack();
|
|
|
|
save_and_clear_fpu();
|
|
|
|
|
2011-08-21 08:14:54 +08:00
|
|
|
wsaved = get_thread_wsaved();
|
|
|
|
|
|
|
|
sigframe_size = sizeof(*sf);
|
|
|
|
if (current_thread_info()->fpsaved[0] & FPRS_FEF)
|
|
|
|
sigframe_size += sizeof(__siginfo_fpu_t);
|
|
|
|
if (wsaved)
|
|
|
|
sigframe_size += sizeof(__siginfo_rwin_t);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
sf = (struct rt_signal_frame32 __user *)
|
2012-11-08 12:48:13 +08:00
|
|
|
get_sigframe(ksig, regs, sigframe_size);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-11-08 12:48:13 +08:00
|
|
|
if (invalid_frame_pointer(sf, sigframe_size)) {
|
|
|
|
do_exit(SIGILL);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-08-21 08:14:54 +08:00
|
|
|
tail = (sf + 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* 2. Save the current process state */
|
|
|
|
if (test_thread_flag(TIF_32BIT)) {
|
|
|
|
regs->tpc &= 0xffffffff;
|
|
|
|
regs->tnpc &= 0xffffffff;
|
|
|
|
}
|
|
|
|
err = put_user(regs->tpc, &sf->regs.pc);
|
|
|
|
err |= __put_user(regs->tnpc, &sf->regs.npc);
|
|
|
|
err |= __put_user(regs->y, &sf->regs.y);
|
|
|
|
psr = tstate_to_psr(regs->tstate);
|
|
|
|
if (current_thread_info()->fpsaved[0] & FPRS_FEF)
|
|
|
|
psr |= PSR_EF;
|
|
|
|
err |= __put_user(psr, &sf->regs.psr);
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
err |= __put_user(regs->u_regs[i], &sf->regs.u_regs[i]);
|
|
|
|
err |= __put_user(sizeof(siginfo_extra_v8plus_t), &sf->extra_size);
|
|
|
|
err |= __put_user(SIGINFO_EXTRA_V8PLUS_MAGIC, &sf->v8plus.g_upper[0]);
|
|
|
|
for (i = 1; i < 16; i++)
|
|
|
|
err |= __put_user(((u32 *)regs->u_regs)[2*i],
|
|
|
|
&sf->v8plus.g_upper[i]);
|
|
|
|
err |= __put_user((regs->tstate & TSTATE_ASI) >> 24UL,
|
|
|
|
&sf->v8plus.asi);
|
|
|
|
|
|
|
|
if (psr & PSR_EF) {
|
2011-08-21 08:14:54 +08:00
|
|
|
__siginfo_fpu_t __user *fp = tail;
|
|
|
|
tail += sizeof(*fp);
|
|
|
|
err |= save_fpu_state(regs, fp);
|
|
|
|
err |= __put_user((u64)fp, &sf->fpu_save);
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
|
|
|
err |= __put_user(0, &sf->fpu_save);
|
|
|
|
}
|
2011-08-21 08:14:54 +08:00
|
|
|
if (wsaved) {
|
|
|
|
__siginfo_rwin_t __user *rwp = tail;
|
|
|
|
tail += sizeof(*rwp);
|
|
|
|
err |= save_rwin_state(wsaved, rwp);
|
|
|
|
err |= __put_user((u64)rwp, &sf->rwin_save);
|
|
|
|
set_thread_wsaved(0);
|
|
|
|
} else {
|
|
|
|
err |= __put_user(0, &sf->rwin_save);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Update the siginfo structure. */
|
2012-11-08 12:48:13 +08:00
|
|
|
err |= copy_siginfo_to_user32(&sf->info, &ksig->info);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Setup sigaltstack */
|
2012-12-23 16:41:17 +08:00
|
|
|
err |= __compat_save_altstack(&sf->stack, regs->u_regs[UREG_FP]);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-09-05 00:28:06 +08:00
|
|
|
err |= put_compat_sigset(&sf->mask, oldset, sizeof(compat_sigset_t));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-08-21 08:14:54 +08:00
|
|
|
if (!wsaved) {
|
|
|
|
err |= copy_in_user((u32 __user *)sf,
|
|
|
|
(u32 __user *)(regs->u_regs[UREG_FP]),
|
|
|
|
sizeof(struct reg_window32));
|
|
|
|
} else {
|
|
|
|
struct reg_window *rp;
|
|
|
|
|
|
|
|
rp = ¤t_thread_info()->reg_window[wsaved - 1];
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
err |= __put_user(rp->locals[i], &sf->ss.locals[i]);
|
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
err |= __put_user(rp->ins[i], &sf->ss.ins[i]);
|
|
|
|
err |= __put_user(rp->ins[6], &sf->ss.fp);
|
|
|
|
err |= __put_user(rp->ins[7], &sf->ss.callers_pc);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
if (err)
|
2012-11-08 12:48:13 +08:00
|
|
|
return err;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* 3. signal handler back-trampoline and parameters */
|
|
|
|
regs->u_regs[UREG_FP] = (unsigned long) sf;
|
2012-11-08 12:48:13 +08:00
|
|
|
regs->u_regs[UREG_I0] = ksig->sig;
|
2005-04-17 06:20:36 +08:00
|
|
|
regs->u_regs[UREG_I1] = (unsigned long) &sf->info;
|
|
|
|
regs->u_regs[UREG_I2] = (unsigned long) &sf->regs;
|
|
|
|
|
|
|
|
/* 4. signal handler */
|
2012-11-08 12:48:13 +08:00
|
|
|
regs->tpc = (unsigned long) ksig->ka.sa.sa_handler;
|
2005-04-17 06:20:36 +08:00
|
|
|
regs->tnpc = (regs->tpc + 4);
|
|
|
|
if (test_thread_flag(TIF_32BIT)) {
|
|
|
|
regs->tpc &= 0xffffffff;
|
|
|
|
regs->tnpc &= 0xffffffff;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 5. return to kernel instructions */
|
2012-11-08 12:48:13 +08:00
|
|
|
if (ksig->ka.ka_restorer)
|
|
|
|
regs->u_regs[UREG_I7] = (unsigned long)ksig->ka.ka_restorer;
|
2005-04-17 06:20:36 +08:00
|
|
|
else {
|
|
|
|
unsigned long address = ((unsigned long)&(sf->insns[0]));
|
|
|
|
|
|
|
|
regs->u_regs[UREG_I7] = (unsigned long) (&(sf->insns[0]) - 2);
|
|
|
|
|
|
|
|
/* mov __NR_rt_sigreturn, %g1 */
|
|
|
|
err |= __put_user(0x82102065, &sf->insns[0]);
|
|
|
|
|
|
|
|
/* t 0x10 */
|
|
|
|
err |= __put_user(0x91d02010, &sf->insns[1]);
|
|
|
|
if (err)
|
2012-11-08 12:48:13 +08:00
|
|
|
return err;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-09-21 14:24:52 +08:00
|
|
|
flush_signal_insns(address);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2010-09-22 12:41:12 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2012-11-08 12:48:13 +08:00
|
|
|
static inline void handle_signal32(struct ksignal *ksig,
|
|
|
|
struct pt_regs *regs)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-11-08 12:48:13 +08:00
|
|
|
sigset_t *oldset = sigmask_to_save();
|
2010-09-22 12:41:12 +08:00
|
|
|
int err;
|
|
|
|
|
2012-11-08 12:48:13 +08:00
|
|
|
if (ksig->ka.sa.sa_flags & SA_SIGINFO)
|
|
|
|
err = setup_rt_frame32(ksig, regs, oldset);
|
2008-04-20 17:14:23 +08:00
|
|
|
else
|
2012-11-08 12:48:13 +08:00
|
|
|
err = setup_frame32(ksig, regs, oldset);
|
2010-09-22 12:41:12 +08:00
|
|
|
|
2012-11-08 12:48:13 +08:00
|
|
|
signal_setup_done(err, ksig, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void syscall_restart32(unsigned long orig_i0, struct pt_regs *regs,
|
|
|
|
struct sigaction *sa)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
break;
|
|
|
|
case ERESTARTSYS:
|
|
|
|
if (!(sa->sa_flags & SA_RESTART))
|
|
|
|
goto no_system_call_restart;
|
|
|
|
/* fallthrough */
|
|
|
|
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.
|
|
|
|
*/
|
2013-03-02 15:55:16 +08:00
|
|
|
void do_signal32(struct pt_regs * regs)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-11-08 12:48:13 +08:00
|
|
|
struct ksignal ksig;
|
|
|
|
unsigned long orig_i0 = 0;
|
|
|
|
int restart_syscall = 0;
|
|
|
|
bool 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 17:07:19 +08:00
|
|
|
|
2011-11-15 12:32:16 +08:00
|
|
|
if (pt_regs_is_syscall(regs) &&
|
|
|
|
(regs->tstate & (TSTATE_XCARRY | TSTATE_ICARRY))) {
|
|
|
|
restart_syscall = 1;
|
2011-11-16 04:57:00 +08:00
|
|
|
orig_i0 = regs->u_regs[UREG_G6];
|
2011-11-15 12:32:16 +08: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 17:07:19 +08:00
|
|
|
|
2012-11-08 12:48:13 +08: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 17:07:19 +08:00
|
|
|
if (restart_syscall)
|
2012-11-08 12:48:13 +08:00
|
|
|
syscall_restart32(orig_i0, regs, &ksig.ka.sa);
|
|
|
|
handle_signal32(&ksig, regs);
|
|
|
|
} 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);
|
|
|
|
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-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct sigstack32 {
|
|
|
|
u32 the_stack;
|
|
|
|
int cur_status;
|
|
|
|
};
|
|
|
|
|
|
|
|
asmlinkage int do_sys32_sigstack(u32 u_ssptr, u32 u_ossptr, unsigned long sp)
|
|
|
|
{
|
|
|
|
struct sigstack32 __user *ssptr =
|
|
|
|
(struct sigstack32 __user *)((unsigned long)(u_ssptr));
|
|
|
|
struct sigstack32 __user *ossptr =
|
|
|
|
(struct sigstack32 __user *)((unsigned long)(u_ossptr));
|
|
|
|
int ret = -EFAULT;
|
|
|
|
|
|
|
|
/* First see if old state is wanted. */
|
|
|
|
if (ossptr) {
|
|
|
|
if (put_user(current->sas_ss_sp + current->sas_ss_size,
|
|
|
|
&ossptr->the_stack) ||
|
|
|
|
__put_user(on_sig_stack(sp), &ossptr->cur_status))
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now see if we want to update the new state. */
|
|
|
|
if (ssptr) {
|
|
|
|
u32 ss_sp;
|
|
|
|
|
|
|
|
if (get_user(ss_sp, &ssptr->the_stack))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* If the current stack was set with sigaltstack, don't
|
|
|
|
* swap stacks while we are on it.
|
|
|
|
*/
|
|
|
|
ret = -EPERM;
|
|
|
|
if (current->sas_ss_sp && on_sig_stack(sp))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Since we don't know the extent of the stack, and we don't
|
|
|
|
* track onstack-ness, but rather calculate it, we must
|
|
|
|
* presume a size. Ho hum this interface is lossy.
|
|
|
|
*/
|
|
|
|
current->sas_ss_sp = (unsigned long)ss_sp - SIGSTKSZ;
|
|
|
|
current->sas_ss_size = SIGSTKSZ;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|