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().
Reported-by: Abaci Robot <[email protected]>
Signed-off-by: Jiapeng Chong <[email protected]>
---
kernel/trace/ftrace.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index b7e29db..74efc33 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -6811,7 +6811,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);
--
1.8.3.1
On Tue, 6 Apr 2021 14:51:45 +0800
Jiapeng Chong <[email protected]> wrote:
> 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().
>
> Reported-by: Abaci Robot <[email protected]>
> Signed-off-by: Jiapeng Chong <[email protected]>
> ---
> kernel/trace/ftrace.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index b7e29db..74efc33 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -6811,7 +6811,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);
This has already been fixed upstream.
-- Steve
> ftrace_number_of_pages -= 1 << order;
> ftrace_number_of_groups--;
> kfree(pg);