ftrace: Using FTRACE_WARN_ON() to check "freed record" in ftrace_release()
PATCH 1/1 ftrace: Using FTRACE_WARN_ON() to check "freed record" in ftrace_release()
* From Steven Rostedt <[email protected]>
Quoted 8 lines
Quoted 6 lines
Hmm, could you explain this more. I'm thinking that this scenario should not happen, and if it does, it should probably be a bug.
Because when we call
ftrace_free_recwe change therec->ipto point to the next record in the chain. Something is very wrong ifrec->ip>= s &&rec->ip< e and the record is already free.Hello, Steven
Quoted 9 lines
Thanks for your comment.
I got your meaning, and I agree that ifrec->ip>= s &&rec->ip< e, this record is not freed.
But IMHO, "ifrec->ip>= s &&rec->ip< e" is used to select records in the module,
and function of ignore "freed record" is only its side-effect. So, add a special judgement to avoid "freed record" is not a bad idea. And I also agree your suggestion of add aWARN_ON, because this should not happened.
Hi Zhaolei,
Great! Feel free to send another patch ;-)
Note, use FTRACE_WARN_ON() macro. This way it shuts down ftrace if it is hit and helps to avoid further damage later.
--- kernel/trace/ftrace.c | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-)
kernel/trace/ftrace.c +7 -2
@@ -358,9 +358,14 @@ void ftrace_release(void *start, unsigned long size)mutex_lock (&ftrace_lock);do_for_each_ftrace_rec (pg, rec) { -if ((rec->ip >= s) && (rec->ip < e) && - !(rec->flags &FTRACE_FL_FREE )) +if ((rec->ip >= s) && (rec->ip < e)) { +/* +* rec->ip is changed in ftrace_free_rec() +* It should not between s and e if record was freed. +*/ +FTRACE_WARN_ON (rec->flags &FTRACE_FL_FREE );ftrace_free_rec (rec); + } }while_for_each_ftrace_rec ();mutex_unlock (&ftrace_lock); }
Signature · 1 line
1.5.5.3