kasan: rearrange stack frame info in reports
- Move printing stack frame info before printing page info. - Add object_is_on_stack() check to print_address_description() and add a corresponding WARNING to kasan_print_address_stack_frame(). This looks more in line with the rest of the checks in this function and also allows to avoid complicating code logic wrt line breaks. - Clean up comments related to get_address_stack_frame_info(). Link: https://lkml.kernel.org/r/1ee113a4c111df97d168c820b527cda77a3cac40.1646237226.git.andreyknvl@google.com Signed-off-by: Andrey Konovalov <andreyknvl@google.com> Reviewed-by: Alexander Potapenko <glider@google.com> Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com> Cc: Dmitry Vyukov <dvyukov@google.com> Cc: Marco Elver <elver@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Родитель
038fd2b4cb
Коммит
0f9b35f383
|
@ -259,6 +259,15 @@ static void print_address_description(void *addr, u8 tag)
|
||||||
pr_err("\n");
|
pr_err("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (object_is_on_stack(addr)) {
|
||||||
|
/*
|
||||||
|
* Currently, KASAN supports printing frame information only
|
||||||
|
* for accesses to the task's own stack.
|
||||||
|
*/
|
||||||
|
kasan_print_address_stack_frame(addr);
|
||||||
|
pr_err("\n");
|
||||||
|
}
|
||||||
|
|
||||||
if (is_vmalloc_addr(addr)) {
|
if (is_vmalloc_addr(addr)) {
|
||||||
struct vm_struct *va = find_vm_area(addr);
|
struct vm_struct *va = find_vm_area(addr);
|
||||||
|
|
||||||
|
@ -278,9 +287,6 @@ static void print_address_description(void *addr, u8 tag)
|
||||||
dump_page(page, "kasan: bad access detected");
|
dump_page(page, "kasan: bad access detected");
|
||||||
pr_err("\n");
|
pr_err("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
kasan_print_address_stack_frame(addr);
|
|
||||||
pr_err("\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool meta_row_is_guilty(const void *row, const void *addr)
|
static bool meta_row_is_guilty(const void *row, const void *addr)
|
||||||
|
|
|
@ -211,6 +211,7 @@ static void print_decoded_frame_descr(const char *frame_descr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Returns true only if the address is on the current task's stack. */
|
||||||
static bool __must_check get_address_stack_frame_info(const void *addr,
|
static bool __must_check get_address_stack_frame_info(const void *addr,
|
||||||
unsigned long *offset,
|
unsigned long *offset,
|
||||||
const char **frame_descr,
|
const char **frame_descr,
|
||||||
|
@ -224,13 +225,6 @@ static bool __must_check get_address_stack_frame_info(const void *addr,
|
||||||
|
|
||||||
BUILD_BUG_ON(IS_ENABLED(CONFIG_STACK_GROWSUP));
|
BUILD_BUG_ON(IS_ENABLED(CONFIG_STACK_GROWSUP));
|
||||||
|
|
||||||
/*
|
|
||||||
* NOTE: We currently only support printing frame information for
|
|
||||||
* accesses to the task's own stack.
|
|
||||||
*/
|
|
||||||
if (!object_is_on_stack(addr))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
aligned_addr = round_down((unsigned long)addr, sizeof(long));
|
aligned_addr = round_down((unsigned long)addr, sizeof(long));
|
||||||
mem_ptr = round_down(aligned_addr, KASAN_GRANULE_SIZE);
|
mem_ptr = round_down(aligned_addr, KASAN_GRANULE_SIZE);
|
||||||
shadow_ptr = kasan_mem_to_shadow((void *)aligned_addr);
|
shadow_ptr = kasan_mem_to_shadow((void *)aligned_addr);
|
||||||
|
@ -269,14 +263,13 @@ void kasan_print_address_stack_frame(const void *addr)
|
||||||
const char *frame_descr;
|
const char *frame_descr;
|
||||||
const void *frame_pc;
|
const void *frame_pc;
|
||||||
|
|
||||||
|
if (WARN_ON(!object_is_on_stack(addr)))
|
||||||
|
return;
|
||||||
|
|
||||||
if (!get_address_stack_frame_info(addr, &offset, &frame_descr,
|
if (!get_address_stack_frame_info(addr, &offset, &frame_descr,
|
||||||
&frame_pc))
|
&frame_pc))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/*
|
|
||||||
* get_address_stack_frame_info only returns true if the given addr is
|
|
||||||
* on the current task's stack.
|
|
||||||
*/
|
|
||||||
pr_err("\n");
|
pr_err("\n");
|
||||||
pr_err("addr %px is located in stack of task %s/%d at offset %lu in frame:\n",
|
pr_err("addr %px is located in stack of task %s/%d at offset %lu in frame:\n",
|
||||||
addr, current->comm, task_pid_nr(current), offset);
|
addr, current->comm, task_pid_nr(current), offset);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче