aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMasami Hiramatsu <mhiramat@kernel.org>2018-04-25 08:20:57 -0400
committerSteven Rostedt (VMware) <rostedt@goodmis.org>2018-10-10 22:19:11 -0400
commit3c88ee194c288205733d248b51f0aca516ff4940 (patch)
treeceef87990d31031cf3da6146678096bd86ba4cdf
parent40b53b771806b1770837169cd32d1bf167fbccaf (diff)
x86: ptrace: Add function argument access API
Add regs_get_argument() which returns N th argument of the function call. Note that this chooses most probably assignment, in some case it can be incorrect (e.g. passing data structure or floating point etc.) This is expected to be called from kprobes or ftrace with regs where the top of stack is the return address. Link: http://lkml.kernel.org/r/152465885737.26224.2822487520472783854.stgit@devbox Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
-rw-r--r--arch/Kconfig7
-rw-r--r--arch/x86/Kconfig1
-rw-r--r--arch/x86/include/asm/ptrace.h38
3 files changed, 46 insertions, 0 deletions
diff --git a/arch/Kconfig b/arch/Kconfig
index 6801123932a5..facace0c90fc 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -290,6 +290,13 @@ config HAVE_RSEQ
290 This symbol should be selected by an architecture if it 290 This symbol should be selected by an architecture if it
291 supports an implementation of restartable sequences. 291 supports an implementation of restartable sequences.
292 292
293config HAVE_FUNCTION_ARG_ACCESS_API
294 bool
295 help
296 This symbol should be selected by an architecure if it supports
297 the API needed to access function arguments from pt_regs,
298 declared in asm/ptrace.h
299
293config HAVE_CLK 300config HAVE_CLK
294 bool 301 bool
295 help 302 help
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 1a0be022f91d..972973851779 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -184,6 +184,7 @@ config X86
184 select HAVE_RCU_TABLE_INVALIDATE if HAVE_RCU_TABLE_FREE 184 select HAVE_RCU_TABLE_INVALIDATE if HAVE_RCU_TABLE_FREE
185 select HAVE_REGS_AND_STACK_ACCESS_API 185 select HAVE_REGS_AND_STACK_ACCESS_API
186 select HAVE_RELIABLE_STACKTRACE if X86_64 && (UNWINDER_FRAME_POINTER || UNWINDER_ORC) && STACK_VALIDATION 186 select HAVE_RELIABLE_STACKTRACE if X86_64 && (UNWINDER_FRAME_POINTER || UNWINDER_ORC) && STACK_VALIDATION
187 select HAVE_FUNCTION_ARG_ACCESS_API
187 select HAVE_STACKPROTECTOR if CC_HAS_SANE_STACKPROTECTOR 188 select HAVE_STACKPROTECTOR if CC_HAS_SANE_STACKPROTECTOR
188 select HAVE_STACK_VALIDATION if X86_64 189 select HAVE_STACK_VALIDATION if X86_64
189 select HAVE_RSEQ 190 select HAVE_RSEQ
diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
index 6de1fd3d0097..c2304b25e2fd 100644
--- a/arch/x86/include/asm/ptrace.h
+++ b/arch/x86/include/asm/ptrace.h
@@ -256,6 +256,44 @@ static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
256 return 0; 256 return 0;
257} 257}
258 258
259/**
260 * regs_get_kernel_argument() - get Nth function argument in kernel
261 * @regs: pt_regs of that context
262 * @n: function argument number (start from 0)
263 *
264 * regs_get_argument() returns @n th argument of the function call.
265 * Note that this chooses most probably assignment, in some case
266 * it can be incorrect.
267 * This is expected to be called from kprobes or ftrace with regs
268 * where the top of stack is the return address.
269 */
270static inline unsigned long regs_get_kernel_argument(struct pt_regs *regs,
271 unsigned int n)
272{
273 static const unsigned int argument_offs[] = {
274#ifdef __i386__
275 offsetof(struct pt_regs, ax),
276 offsetof(struct pt_regs, cx),
277 offsetof(struct pt_regs, dx),
278#define NR_REG_ARGUMENTS 3
279#else
280 offsetof(struct pt_regs, di),
281 offsetof(struct pt_regs, si),
282 offsetof(struct pt_regs, dx),
283 offsetof(struct pt_regs, cx),
284 offsetof(struct pt_regs, r8),
285 offsetof(struct pt_regs, r9),
286#define NR_REG_ARGUMENTS 6
287#endif
288 };
289
290 if (n >= NR_REG_ARGUMENTS) {
291 n -= NR_REG_ARGUMENTS - 1;
292 return regs_get_kernel_stack_nth(regs, n);
293 } else
294 return regs_get_register(regs, argument_offs[n]);
295}
296
259#define arch_has_single_step() (1) 297#define arch_has_single_step() (1)
260#ifdef CONFIG_X86_DEBUGCTLMSR 298#ifdef CONFIG_X86_DEBUGCTLMSR
261#define arch_has_block_step() (1) 299#define arch_has_block_step() (1)