[PATCH] ftrace: remove direct reference to mcount in trace code

This is a discussion on [PATCH] ftrace: remove direct reference to mcount in trace code within the Kernel forums, part of the Help category; The mcount record method of ftrace scans objdump for references to mcount. Using mcount as the reference to test if the calls to mcount being replaced are indeed calls to ...

Go Back   Unix Linux Forum > Unix > Linux > Help > Kernel

FixUnix.com - Unix Linux Forums

Unix Content Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-27-2008, 11:30 PM
Default [PATCH] ftrace: remove direct reference to mcount in trace code


The mcount record method of ftrace scans objdump for references to mcount.
Using mcount as the reference to test if the calls to mcount being replaced
are indeed calls to mcount, this use of mcount was also caught as a
location to change. Using a variable that points to the mcount address
moves this reference into the data section that is not scanned, and
we do not use a false location to try and modify.

The warn on code was what was used to detect this bug.

Signed-off-by: Steven Rostedt
---
kernel/trace/ftrace.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)

Index: linux-tip.git/kernel/trace/ftrace.c
================================================== =================
--- linux-tip.git.orig/kernel/trace/ftrace.c 2008-08-27 22:13:39.000000000 -0400
+++ linux-tip.git/kernel/trace/ftrace.c 2008-08-27 22:16:52.000000000 -0400
@@ -37,6 +37,14 @@ int ftrace_enabled __read_mostly;
static int last_ftrace_enabled;

/*
+ * Since MCOUNT_ADDR may point to mcount itself, we do not want
+ * to get it confused by reading a reference in the code as we
+ * are parsing on objcopy output of text. Use a variable for
+ * it instead.
+ */
+static unsigned long mcount_addr = MCOUNT_ADDR;
+
+/*
* ftrace_disabled is set when an anomaly is discovered.
* ftrace_disabled is much stronger than ftrace_enabled.
*/
@@ -594,7 +602,7 @@ ftrace_code_disable(struct dyn_ftrace *r
ip = rec->ip;

nop = ftrace_nop_replace();
- call = ftrace_call_replace(ip, MCOUNT_ADDR);
+ call = ftrace_call_replace(ip, mcount_addr);

failed = ftrace_modify_code(ip, call, nop);
if (failed) {

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Reply With Quote
  #2  
Old 08-28-2008, 04:00 AM
Default Re: [PATCH] ftrace: remove direct reference to mcount in trace code


* Steven Rostedt wrote:

> The mcount record method of ftrace scans objdump for references to
> mcount. Using mcount as the reference to test if the calls to mcount
> being replaced are indeed calls to mcount, this use of mcount was also
> caught as a location to change. Using a variable that points to the
> mcount address moves this reference into the data section that is not
> scanned, and we do not use a false location to try and modify.
>
> The warn on code was what was used to detect this bug.
>
> Signed-off-by: Steven Rostedt


applied to tip/tracing/ftrace - thanks Steve!

Ingo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Reply With Quote
Reply

Thread Tools


All times are GMT -5. The time now is 07:01 PM.

In an effort to better serve ads to our visitors, cookies are used on Fixunix.com. For more information, check out our Privacy Policy.

Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
Ad Management by RedTyger