Skip to content

Commit

Permalink
ftrace: remove direct reference to mcount in trace code
Browse files Browse the repository at this point in the history
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 <srostedt@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
Steven Rostedt authored and Ingo Molnar committed Oct 14, 2008
1 parent e5a81b6 commit 3b47bfc
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion kernel/trace/ftrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,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.
Expand Down Expand Up @@ -577,7 +585,7 @@ ftrace_code_disable(struct dyn_ftrace *rec)
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) {
Expand Down

0 comments on commit 3b47bfc

Please sign in to comment.