Messages in this thread | | | Date | Mon, 9 Nov 2020 12:10:43 +0100 | From | Peter Zijlstra <> | Subject | Re: [PATCH 2/3 v4] ftrace/x86: Allow for arguments to be passed in to ftrace_regs by default |
| |
On Fri, Nov 06, 2020 at 04:42:36PM -0500, Steven Rostedt wrote: > +static __always_inline struct pt_regs * > +arch_ftrace_get_regs(struct ftrace_regs *fregs) > +{ > + /* Only when FL_SAVE_REGS is set, cs will be non zero */ > + if (!fregs->regs.cs) > + return NULL; > + return &fregs->regs; > +} > +#endif > + > #endif /* CONFIG_DYNAMIC_FTRACE */ > #endif /* __ASSEMBLY__ */ > #endif /* CONFIG_FUNCTION_TRACER */ > diff --git a/arch/x86/kernel/ftrace_64.S b/arch/x86/kernel/ftrace_64.S > index ac3d5f22fe64..60e3b64f5ea6 100644 > --- a/arch/x86/kernel/ftrace_64.S > +++ b/arch/x86/kernel/ftrace_64.S > @@ -140,12 +140,19 @@ SYM_FUNC_START(ftrace_caller) > /* save_mcount_regs fills in first two parameters */ > save_mcount_regs > > + /* Stack - skipping return address of ftrace_caller */ > + leaq MCOUNT_REG_SIZE+8(%rsp), %rcx > + movq %rcx, RSP(%rsp) > + > SYM_INNER_LABEL(ftrace_caller_op_ptr, SYM_L_GLOBAL) > /* Load the ftrace_ops into the 3rd parameter */ > movq function_trace_op(%rip), %rdx > > - /* regs go into 4th parameter (but make it NULL) */ > - movq $0, %rcx > + /* regs go into 4th parameter */ > + leaq (%rsp), %rcx > + > + /* Only ops with REGS flag set should have CS register set */ > + movq $0, CS(%rsp) > > SYM_INNER_LABEL(ftrace_call, SYM_L_GLOBAL) > call ftrace_stub
You now seem to be relying on save_mcount_regs() resulting in a cleared CS, however, AFAICT CS is uninitialized stack garbage.
| |