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 13/23] tracehook: syscall
Date: Thu, 17 Jul 2008 00:30:29 -0700 (PDT) [thread overview]
Message-ID: <20080717073029.5658015411D@magilla.localdomain> (raw)
In-Reply-To: Roland McGrath's message of Thursday, 17 July 2008 00:25:41 -0700 <20080717072541.F390E15411D@magilla.localdomain>
This adds standard tracehook.h inlines for arch code to call when
TIF_SYSCALL_TRACE has been set. This replaces having each arch
implement the ptrace guts for its syscall tracing support.
Signed-off-by: Roland McGrath <roland@redhat.com>
---
include/linux/tracehook.h | 70 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 70 insertions(+), 0 deletions(-)
diff --git a/include/linux/tracehook.h b/include/linux/tracehook.h
index 8b4c15e..3548694 100644
--- a/include/linux/tracehook.h
+++ b/include/linux/tracehook.h
@@ -66,6 +66,76 @@ static inline int tracehook_expect_breakpoints(struct task_struct *task)
return (task_ptrace(task) & PT_PTRACED) != 0;
}
+/*
+ * ptrace report for syscall entry and exit looks identical.
+ */
+static inline void ptrace_report_syscall(struct pt_regs *regs)
+{
+ int ptrace = task_ptrace(current);
+
+ if (!(ptrace & PT_PTRACED))
+ return;
+
+ ptrace_notify(SIGTRAP | ((ptrace & PT_TRACESYSGOOD) ? 0x80 : 0));
+
+ /*
+ * this isn't the same as continuing with a signal, but it will do
+ * for normal use. strace only continues with a signal if the
+ * stopping signal is not SIGTRAP. -brl
+ */
+ if (current->exit_code) {
+ send_sig(current->exit_code, current, 1);
+ current->exit_code = 0;
+ }
+}
+
+/**
+ * tracehook_report_syscall_entry - task is about to attempt a system call
+ * @regs: user register state of current task
+ *
+ * This will be called if %TIF_SYSCALL_TRACE has been set, when the
+ * current task has just entered the kernel for a system call.
+ * Full user register state is available here. Changing the values
+ * in @regs can affect the system call number and arguments to be tried.
+ * It is safe to block here, preventing the system call from beginning.
+ *
+ * Returns zero normally, or nonzero if the calling arch code should abort
+ * the system call. That must prevent normal entry so no system call is
+ * made. If @task ever returns to user mode after this, its register state
+ * is unspecified, but should be something harmless like an %ENOSYS error
+ * return.
+ *
+ * Called without locks, just after entering kernel mode.
+ */
+static inline __must_check int tracehook_report_syscall_entry(
+ struct pt_regs *regs)
+{
+ ptrace_report_syscall(regs);
+ return 0;
+}
+
+/**
+ * tracehook_report_syscall_exit - task has just finished a system call
+ * @regs: user register state of current task
+ * @step: nonzero if simulating single-step or block-step
+ *
+ * This will be called if %TIF_SYSCALL_TRACE has been set, when the
+ * current task has just finished an attempted system call. Full
+ * user register state is available here. It is safe to block here,
+ * preventing signals from being processed.
+ *
+ * If @step is nonzero, this report is also in lieu of the normal
+ * trap that would follow the system call instruction because
+ * user_enable_block_step() or user_enable_single_step() was used.
+ * In this case, %TIF_SYSCALL_TRACE might not be set.
+ *
+ * Called without locks, just before checking for pending signals.
+ */
+static inline void tracehook_report_syscall_exit(struct pt_regs *regs, int step)
+{
+ ptrace_report_syscall(regs);
+}
+
/**
* tracehook_unsafe_exec - check for exec declared unsafe due to tracing
* @task: current task doing exec
next prev parent reply other threads:[~2008-07-17 7:32 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 ` Roland McGrath [this message]
2008-07-17 7:30 ` [PATCH 14/23] tracehook: get_signal_to_deliver Roland McGrath
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=20080717073029.5658015411D@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®