mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Roland McGrath <roland@redhat.com>
To: Andrew Morton <akpm@linux-foundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>
Cc: Ingo Molnar <mingo@elte.hu>, linux-kernel@vger.kernel.org
Subject: [PATCH 14/23] tracehook: get_signal_to_deliver
Date: Thu, 17 Jul 2008 00:30:36 -0700 (PDT)	[thread overview]
Message-ID: <20080717073036.D721215411D@magilla.localdomain> (raw)
In-Reply-To: Roland McGrath's message of  Thursday, 17 July 2008 00:25:41 -0700 <20080717072541.F390E15411D@magilla.localdomain>

This defines the tracehook_get_signal() hook to allow tracing code to
slip in before normal signal dequeuing.  This lays the groundwork for
new tracing features that can inject synthetic signals outside the
normal queue or control the disposition of delivered signals.  The
calling convention lets tracehook_get_signal() decide both exactly
what will happen and what signal number to report in the handler/exit.

Signed-off-by: Roland McGrath <roland@redhat.com>
---
 include/linux/tracehook.h |   29 +++++++++++++++++++++++++++++
 kernel/signal.c           |   38 +++++++++++++++++++++++++++-----------
 2 files changed, 56 insertions(+), 11 deletions(-)

diff --git a/include/linux/tracehook.h b/include/linux/tracehook.h
index 3548694..42a0d7b 100644
--- a/include/linux/tracehook.h
+++ b/include/linux/tracehook.h
@@ -422,4 +422,33 @@ static inline int tracehook_consider_fatal_signal(struct task_struct *task,
 	return (task_ptrace(task) & PT_PTRACED) != 0;
 }
 
+/**
+ * tracehook_get_signal - deliver synthetic signal to traced task
+ * @task:		@current
+ * @regs:		task_pt_regs(@current)
+ * @info:		details of synthetic signal
+ * @return_ka:		sigaction for synthetic signal
+ *
+ * Return zero to check for a real pending signal normally.
+ * Return -1 after releasing the siglock to repeat the check.
+ * Return a signal number to induce an artifical signal delivery,
+ * setting *@info and *@return_ka to specify its details and behavior.
+ *
+ * The @return_ka->sa_handler value controls the disposition of the
+ * signal, no matter the signal number.  For %SIG_DFL, the return value
+ * is a representative signal to indicate the behavior (e.g. %SIGTERM
+ * for death, %SIGQUIT for core dump, %SIGSTOP for job control stop,
+ * %SIGTSTP for stop unless in an orphaned pgrp), but the signal number
+ * reported will be @info->si_signo instead.
+ *
+ * Called with @task->sighand->siglock held, before dequeuing pending signals.
+ */
+static inline int tracehook_get_signal(struct task_struct *task,
+				       struct pt_regs *regs,
+				       siginfo_t *info,
+				       struct k_sigaction *return_ka)
+{
+	return 0;
+}
+
 #endif	/* <linux/tracehook.h> */
diff --git a/kernel/signal.c b/kernel/signal.c
index 860afb8..1766c47 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -1779,17 +1779,33 @@ relock:
 		    do_signal_stop(0))
 			goto relock;
 
-		signr = dequeue_signal(current, &current->blocked, info);
-		if (!signr)
-			break; /* will return 0 */
+		/*
+		 * Tracing can induce an artifical signal and choose sigaction.
+		 * The return value in @signr determines the default action,
+		 * but @info->si_signo is the signal number we will report.
+		 */
+		signr = tracehook_get_signal(current, regs, info, return_ka);
+		if (unlikely(signr < 0))
+			goto relock;
+		if (unlikely(signr != 0))
+			ka = return_ka;
+		else {
+			signr = dequeue_signal(current, &current->blocked,
+					       info);
 
-		if (signr != SIGKILL) {
-			signr = ptrace_signal(signr, info, regs, cookie);
 			if (!signr)
-				continue;
+				break; /* will return 0 */
+
+			if (signr != SIGKILL) {
+				signr = ptrace_signal(signr, info,
+						      regs, cookie);
+				if (!signr)
+					continue;
+			}
+
+			ka = &sighand->action[signr-1];
 		}
 
-		ka = &sighand->action[signr-1];
 		if (ka->sa.sa_handler == SIG_IGN) /* Do nothing.  */
 			continue;
 		if (ka->sa.sa_handler != SIG_DFL) {
@@ -1837,7 +1853,7 @@ relock:
 				spin_lock_irq(&sighand->siglock);
 			}
 
-			if (likely(do_signal_stop(signr))) {
+			if (likely(do_signal_stop(info->si_signo))) {
 				/* It released the siglock.  */
 				goto relock;
 			}
@@ -1858,7 +1874,7 @@ relock:
 
 		if (sig_kernel_coredump(signr)) {
 			if (print_fatal_signals)
-				print_fatal_signal(regs, signr);
+				print_fatal_signal(regs, info->si_signo);
 			/*
 			 * If it was able to dump core, this kills all
 			 * other threads in the group and synchronizes with
@@ -1867,13 +1883,13 @@ relock:
 			 * first and our do_group_exit call below will use
 			 * that value and ignore the one we pass it.
 			 */
-			do_coredump((long)signr, signr, regs);
+			do_coredump(info->si_signo, info->si_signo, regs);
 		}
 
 		/*
 		 * Death signals, no core dump.
 		 */
-		do_group_exit(signr);
+		do_group_exit(info->si_signo);
 		/* NOTREACHED */
 	}
 	spin_unlock_irq(&sighand->siglock);

  parent reply	other threads:[~2008-07-17  7:33 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-17  7:25 [PATCH 00/23] tracehook Roland McGrath
2008-07-17  7:27 ` [PATCH 01/23] tracehook: add linux/tracehook.h Roland McGrath
2008-07-17  8:48   ` Alexey Dobriyan
2008-07-17 11:06     ` Petr Tesarik
2008-07-17 21:50       ` Alexey Dobriyan
2008-07-17 13:34     ` Christoph Hellwig
2008-07-18 11:57       ` Petr Tesarik
2008-07-17  7:28 ` [PATCH 02/23] tracehook: exec Roland McGrath
2008-07-21  8:49   ` Christoph Hellwig
2008-07-17  7:28 ` [PATCH 03/23] tracehook: unexport ptrace_notify Roland McGrath
2008-07-17  7:28 ` [PATCH 04/23] tracehook: exit Roland McGrath
2008-07-17  7:29 ` [PATCH 05/23] tracehook: clone Roland McGrath
2008-07-17  7:29 ` [PATCH 06/23] tracehook: vfork-done Roland McGrath
2008-07-17  7:29 ` [PATCH 07/23] tracehook: release_task Roland McGrath
2008-07-17  7:29 ` [PATCH 08/23] tracehook: tracehook_tracer_task Roland McGrath
2008-07-17  7:29 ` [PATCH 09/23] tracehook: tracehook_expect_breakpoints Roland McGrath
2008-07-17  7:30 ` [PATCH 10/23] tracehook: tracehook_signal_handler Roland McGrath
2008-07-17  7:30 ` [PATCH 11/23] tracehook: tracehook_consider_ignored_signal Roland McGrath
2008-07-17  7:30 ` [PATCH 12/23] tracehook: tracehook_consider_fatal_signal Roland McGrath
2008-07-17  7:30 ` [PATCH 13/23] tracehook: syscall Roland McGrath
2008-07-17  7:30 ` Roland McGrath [this message]
2008-07-17  7:30 ` [PATCH 15/23] tracehook: job control Roland McGrath
2008-07-17  7:30 ` [PATCH 16/23] tracehook: death Roland McGrath
2008-07-17  7:30 ` [PATCH 17/23] tracehook: force signal_pending() Roland McGrath
2008-07-17  7:31 ` [PATCH 18/23] tracehook: TIF_NOTIFY_RESUME Roland McGrath
2008-07-17  7:31 ` [PATCH 19/23] tracehook: asm/syscall.h Roland McGrath
2008-07-17  7:31 ` [PATCH 20/23] tracehook: CONFIG_HAVE_ARCH_TRACEHOOK Roland McGrath
2008-07-17  7:31 ` [PATCH 21/23] tracehook: wait_task_inactive Roland McGrath
2008-07-17  7:31 ` [PATCH 22/23] task_current_syscall Roland McGrath
2008-07-17  7:31 ` [PATCH 23/23] /proc/PID/syscall Roland McGrath
2008-07-17 22:56   ` Alexey Dobriyan
2008-07-21  8:19     ` Roland McGrath
2008-07-17  7:39 ` [PATCH 00/23] tracehook Andrew Morton
2008-07-17  8:11   ` Roland McGrath
2008-07-17  8:30     ` Andrew Morton
2008-07-17  8:37       ` Roland McGrath
2008-07-17  8:51 ` Andrew Morton
2008-07-18  8:07   ` Ingo Molnar
2008-07-21  9:59   ` Roland McGrath
2008-07-18  9:20 ` David Miller
2008-07-18 11:24   ` Andi Kleen
2008-07-18 11:32     ` David Miller
2008-07-21 10:54   ` Roland McGrath
2008-07-21 15:18     ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080717073036.D721215411D@magilla.localdomain \
    --to=roland@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®