Messages in this thread Patch in this message | | | Date | Wed, 23 Feb 2022 11:57:26 +0100 | From | Peter Zijlstra <> | Subject | Re: [PATCH 04/29] x86/livepatch: Validate __fentry__ location |
| |
On Wed, Feb 23, 2022 at 11:09:44AM +0100, Peter Zijlstra wrote: > Yes.. so yesterday, when making function-graph tracing not explode, I > ran into a similar issue. Steve suggested something along the lines of > .... this. > > (modified from his actual suggestion to also cover this case) > > Let me go try this...
This one actually works...
--- --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -1578,7 +1578,23 @@ unsigned long ftrace_location_range(unsi */ unsigned long ftrace_location(unsigned long ip) { - return ftrace_location_range(ip, ip); + struct dyn_ftrace *rec; + unsigned long offset; + unsigned long size; + + rec = lookup_rec(ip, ip); + if (!rec) { + if (!kallsyms_lookup_size_offset(ip, &size, &offset)) + goto out; + + rec = lookup_rec(ip - offset, (ip - offset) + size); + } + + if (rec) + return rec->ip; + +out: + return 0; } /** @@ -5110,11 +5126,16 @@ int register_ftrace_direct(unsigned long struct ftrace_func_entry *entry; struct ftrace_hash *free_hash = NULL; struct dyn_ftrace *rec; - int ret = -EBUSY; + int ret = -ENODEV; mutex_lock(&direct_mutex); + ip = ftrace_location(ip); + if (!ip) + goto out_unlock; + /* See if there's a direct function at @ip already */ + ret = -EBUSY; if (ftrace_find_rec_direct(ip)) goto out_unlock; @@ -5222,6 +5243,10 @@ int unregister_ftrace_direct(unsigned lo mutex_lock(&direct_mutex); + ip = ftrace_location(ip); + if (!ip) + goto out_unlock; + entry = find_direct_entry(&ip, NULL); if (!entry) goto out_unlock;
| |