]> Git Repo - linux.git/commitdiff
ftrace: Check if pages were allocated before calling free_pages()
authorSteven Rostedt (VMware) <[email protected]>
Tue, 30 Mar 2021 13:58:38 +0000 (09:58 -0400)
committerSteven Rostedt (VMware) <[email protected]>
Tue, 30 Mar 2021 13:58:38 +0000 (09:58 -0400)
It is possible that on error pg->size can be zero when getting its order,
which would return a -1 value. It is dangerous to pass in an order of -1
to free_pages(). Check if order is greater than or equal to zero before
calling free_pages().

Link: https://lore.kernel.org/lkml/[email protected]/
Reported-by: Abaci Robot <[email protected]>
Signed-off-by: Steven Rostedt (VMware) <[email protected]>
kernel/trace/ftrace.c

index 4d8e3557554919a9b994ebf0e8c85b0816a526d3..12223132eff4d7959344e948f959f5ecf2b80944 100644 (file)
@@ -3231,7 +3231,8 @@ ftrace_allocate_pages(unsigned long num_to_init)
        pg = start_pg;
        while (pg) {
                order = get_count_order(pg->size / ENTRIES_PER_PAGE);
-               free_pages((unsigned long)pg->records, order);
+               if (order >= 0)
+                       free_pages((unsigned long)pg->records, order);
                start_pg = pg->next;
                kfree(pg);
                pg = start_pg;
@@ -6418,7 +6419,8 @@ void ftrace_release_mod(struct module *mod)
                clear_mod_from_hashes(pg);
 
                order = get_count_order(pg->size / ENTRIES_PER_PAGE);
-               free_pages((unsigned long)pg->records, order);
+               if (order >= 0)
+                       free_pages((unsigned long)pg->records, order);
                tmp_page = pg->next;
                kfree(pg);
                ftrace_number_of_pages -= 1 << order;
@@ -6778,7 +6780,8 @@ void ftrace_free_mem(struct module *mod, void *start_ptr, void *end_ptr)
                if (!pg->index) {
                        *last_pg = pg->next;
                        order = get_count_order(pg->size / ENTRIES_PER_PAGE);
-                       free_pages((unsigned long)pg->records, order);
+                       if (order >= 0)
+                               free_pages((unsigned long)pg->records, order);
                        ftrace_number_of_pages -= 1 << order;
                        ftrace_number_of_groups--;
                        kfree(pg);
This page took 0.057964 seconds and 4 git commands to generate.