ftrace: return first found result in lookup_rec()
Subsystems (3)
PATCH 1/1 ftrace: return first found result in lookup_rec()
It appears that ip ranges can overlap so. In that case lookup_rec() returns whatever results it got last even if it found nothing in last searched page.
This breaks an obscure livepatch late module patching usecase:
- load livepatch
- load the patched module
- unload livepatch
- try to load livepatch again
To fix this return from lookup_rec() as soon as it found the record containing searched-for ip. This used to be this way prior lookup_rec() introduction.
--- kernel/trace/ftrace.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/trace/ftrace.c +3 -1
@@ -1547,8 +1547,10 @@ static struct dyn_ftrace *lookup_rec(unsigned long start, unsigned long end) rec =bsearch (&key, pg->records, pg->index,sizeof (struct dyn_ftrace ), ftrace_cmp_recs); +if (rec) +return rec; } -return rec; +return NULL ; }/**
Signature · 1 line
2.21.1
Steven Rostedt
maintainerQuoted 25 lines · On Fri, 6 Mar 2020 09:10:35 +0100 Artem Savkov <[email protected]> wrote:
It appears that ip ranges can overlap so. In that case
lookup_rec()returns whatever results it got last even if it found nothing in last searched page.This breaks an obscure livepatch late module patching usecase:
- load livepatch
- load the patched module
- unload livepatch
- try to load livepatch againTo fix this return from
lookup_rec()as soon as it found the record containing searched-for ip. This used to be this way priorlookup_rec()introduction.Fixes 7e16f581a817 ("ftrace: Separate out functionality from ftrace_location_range()")Signed-off-by Artem Savkov <[email protected]>--- kernel/trace/ftrace.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)kernel/trace/ftrace.c +0
-0
kernel/trace/ftrace.c static struct dyn_ftrace *lookup_rec(unsigned long start, unsigned long end) · line 1549
Quoted 3 lines
kernel/trace/ftrace.c +0
-0@@ -1547,8 +1547,10 @@ static struct dyn_ftrace *lookup_rec(unsigned long start, unsigned long end) rec =bsearch (&key, pg->records, pg->index,sizeof (struct dyn_ftrace ), ftrace_cmp_recs);
how about just adding:
if (rec) break;
as that will do the same thing without adding two returns.
-- Steve
Quoted 8 lines
kernel/trace/ftrace.c +3
-1+if (rec) +return rec; } -return rec; +return NULL ; }/**
PATCH v2 1/1 ftrace: return first found result in lookup_rec()
It appears that ip ranges can overlap so. In that case lookup_rec() returns whatever results it got last even if it found nothing in last searched page.
This breaks an obscure livepatch late module patching usecase:
- load livepatch
- load the patched module
- unload livepatch
- try to load livepatch again
To fix this return from lookup_rec() as soon as it found the record containing searched-for ip. This used to be this way prior lookup_rec() introduction.
v2: break instead of two returns
--- kernel/trace/ftrace.c | 2 ++ 1 file changed, 2 insertions(+)
kernel/trace/ftrace.c +2 -0
@@ -1547,6 +1547,8 @@ static struct dyn_ftrace *lookup_rec(unsigned long start, unsigned long end) rec =bsearch (&key, pg->records, pg->index,sizeof (struct dyn_ftrace ), ftrace_cmp_recs); +if (rec) +break ; }return rec; }
Signature · 1 line
2.21.1
Steven Rostedt
maintainerQuoted 10 lines · On Fri, 6 Mar 2020 18:43:17 +0100 Artem Savkov <[email protected]> wrote:
It appears that ip ranges can overlap so. In that case
lookup_rec()returns whatever results it got last even if it found nothing in last searched page.This breaks an obscure livepatch late module patching usecase:
- load livepatch
- load the patched module
- unload livepatch
- try to load livepatch again
Quoted 5 lines
To fix this return from
lookup_rec()as soon as it found the record containing searched-for ip. This used to be this way priorlookup_rec()introduction.v2: break instead of two returns
Thanks Artem, I applied your patch. But just an FYI, it's best to place the "v2" statement below the three dashes "---" so that it doesn't get pulled into the git commit when this patch is applied via a script.
-- Steve
Quoted 20 lines
Fixes 7e16f581a817 ("ftrace: Separate out functionality from ftrace_location_range()")Signed-off-by Artem Savkov <[email protected]>--- kernel/trace/ftrace.c | 2 ++ 1 file changed, 2 insertions(+)kernel/trace/ftrace.c +2
-0@@ -1547,6 +1547,8 @@ static struct dyn_ftrace *lookup_rec(unsigned long start, unsigned long end) rec =bsearch (&key, pg->records, pg->index,sizeof (struct dyn_ftrace ), ftrace_cmp_recs); +if (rec) +break ; }return rec; }