Revert "ftrace: Fix possible use-after-free issue in ftrace_location()"
This reverts commit 2c12c9f7ef
.
This commit is contained in:
parent
0f1229f8a4
commit
cf372342bd
1 changed files with 16 additions and 23 deletions
|
@ -1566,15 +1566,12 @@ static struct dyn_ftrace *lookup_rec(unsigned long start, unsigned long end)
|
||||||
unsigned long ftrace_location_range(unsigned long start, unsigned long end)
|
unsigned long ftrace_location_range(unsigned long start, unsigned long end)
|
||||||
{
|
{
|
||||||
struct dyn_ftrace *rec;
|
struct dyn_ftrace *rec;
|
||||||
unsigned long ip = 0;
|
|
||||||
|
|
||||||
rcu_read_lock();
|
|
||||||
rec = lookup_rec(start, end);
|
rec = lookup_rec(start, end);
|
||||||
if (rec)
|
if (rec)
|
||||||
ip = rec->ip;
|
return rec->ip;
|
||||||
rcu_read_unlock();
|
|
||||||
|
|
||||||
return ip;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1587,22 +1584,25 @@ unsigned long ftrace_location_range(unsigned long start, unsigned long end)
|
||||||
*/
|
*/
|
||||||
unsigned long ftrace_location(unsigned long ip)
|
unsigned long ftrace_location(unsigned long ip)
|
||||||
{
|
{
|
||||||
unsigned long loc;
|
struct dyn_ftrace *rec;
|
||||||
unsigned long offset;
|
unsigned long offset;
|
||||||
unsigned long size;
|
unsigned long size;
|
||||||
|
|
||||||
loc = ftrace_location_range(ip, ip);
|
rec = lookup_rec(ip, ip);
|
||||||
if (!loc) {
|
if (!rec) {
|
||||||
if (!kallsyms_lookup_size_offset(ip, &size, &offset))
|
if (!kallsyms_lookup_size_offset(ip, &size, &offset))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
/* map sym+0 to __fentry__ */
|
/* map sym+0 to __fentry__ */
|
||||||
if (!offset)
|
if (!offset)
|
||||||
loc = ftrace_location_range(ip, ip + size - 1);
|
rec = lookup_rec(ip, ip + size - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (rec)
|
||||||
|
return rec->ip;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
return loc;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -6331,8 +6331,6 @@ static int ftrace_process_locs(struct module *mod,
|
||||||
/* We should have used all pages unless we skipped some */
|
/* We should have used all pages unless we skipped some */
|
||||||
if (pg_unuse) {
|
if (pg_unuse) {
|
||||||
WARN_ON(!skipped);
|
WARN_ON(!skipped);
|
||||||
/* Need to synchronize with ftrace_location_range() */
|
|
||||||
synchronize_rcu();
|
|
||||||
ftrace_free_pages(pg_unuse);
|
ftrace_free_pages(pg_unuse);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -6515,9 +6513,6 @@ void ftrace_release_mod(struct module *mod)
|
||||||
out_unlock:
|
out_unlock:
|
||||||
mutex_unlock(&ftrace_lock);
|
mutex_unlock(&ftrace_lock);
|
||||||
|
|
||||||
/* Need to synchronize with ftrace_location_range() */
|
|
||||||
if (tmp_page)
|
|
||||||
synchronize_rcu();
|
|
||||||
for (pg = tmp_page; pg; pg = tmp_page) {
|
for (pg = tmp_page; pg; pg = tmp_page) {
|
||||||
|
|
||||||
/* Needs to be called outside of ftrace_lock */
|
/* Needs to be called outside of ftrace_lock */
|
||||||
|
@ -6840,7 +6835,6 @@ void ftrace_free_mem(struct module *mod, void *start_ptr, void *end_ptr)
|
||||||
unsigned long start = (unsigned long)(start_ptr);
|
unsigned long start = (unsigned long)(start_ptr);
|
||||||
unsigned long end = (unsigned long)(end_ptr);
|
unsigned long end = (unsigned long)(end_ptr);
|
||||||
struct ftrace_page **last_pg = &ftrace_pages_start;
|
struct ftrace_page **last_pg = &ftrace_pages_start;
|
||||||
struct ftrace_page *tmp_page = NULL;
|
|
||||||
struct ftrace_page *pg;
|
struct ftrace_page *pg;
|
||||||
struct dyn_ftrace *rec;
|
struct dyn_ftrace *rec;
|
||||||
struct dyn_ftrace key;
|
struct dyn_ftrace key;
|
||||||
|
@ -6884,8 +6878,12 @@ void ftrace_free_mem(struct module *mod, void *start_ptr, void *end_ptr)
|
||||||
ftrace_update_tot_cnt--;
|
ftrace_update_tot_cnt--;
|
||||||
if (!pg->index) {
|
if (!pg->index) {
|
||||||
*last_pg = pg->next;
|
*last_pg = pg->next;
|
||||||
pg->next = tmp_page;
|
if (pg->records) {
|
||||||
tmp_page = pg;
|
free_pages((unsigned long)pg->records, pg->order);
|
||||||
|
ftrace_number_of_pages -= 1 << pg->order;
|
||||||
|
}
|
||||||
|
ftrace_number_of_groups--;
|
||||||
|
kfree(pg);
|
||||||
pg = container_of(last_pg, struct ftrace_page, next);
|
pg = container_of(last_pg, struct ftrace_page, next);
|
||||||
if (!(*last_pg))
|
if (!(*last_pg))
|
||||||
ftrace_pages = pg;
|
ftrace_pages = pg;
|
||||||
|
@ -6902,11 +6900,6 @@ void ftrace_free_mem(struct module *mod, void *start_ptr, void *end_ptr)
|
||||||
clear_func_from_hashes(func);
|
clear_func_from_hashes(func);
|
||||||
kfree(func);
|
kfree(func);
|
||||||
}
|
}
|
||||||
/* Need to synchronize with ftrace_location_range() */
|
|
||||||
if (tmp_page) {
|
|
||||||
synchronize_rcu();
|
|
||||||
ftrace_free_pages(tmp_page);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void __init ftrace_free_init_mem(void)
|
void __init ftrace_free_init_mem(void)
|
||||||
|
|
Loading…
Reference in a new issue