Skip to content

Commit 6ee9b3d

Browse files
LeviYeoReumakpm00
authored andcommitted
kasan: remove kasan_find_vm_area() to prevent possible deadlock
find_vm_area() couldn't be called in atomic_context. If find_vm_area() is called to reports vm area information, kasan can trigger deadlock like: CPU0 CPU1 vmalloc(); alloc_vmap_area(); spin_lock(&vn->busy.lock) spin_lock_bh(&some_lock); <interrupt occurs> <in softirq> spin_lock(&some_lock); <access invalid address> kasan_report(); print_report(); print_address_description(); kasan_find_vm_area(); find_vm_area(); spin_lock(&vn->busy.lock) // deadlock! To prevent possible deadlock while kasan reports, remove kasan_find_vm_area(). Link: https://lkml.kernel.org/r/[email protected] Fixes: c056a36 ("kasan: print virtual mapping info in reports") Signed-off-by: Yeoreum Yun <[email protected]> Reported-by: Yunseong Kim <[email protected]> Reviewed-by: Andrey Ryabinin <[email protected]> Cc: Alexander Potapenko <[email protected]> Cc: Andrey Konovalov <[email protected]> Cc: Byungchul Park <[email protected]> Cc: Dmitriy Vyukov <[email protected]> Cc: Sebastian Andrzej Siewior <[email protected]> Cc: Steven Rostedt <[email protected]> Cc: Vincenzo Frascino <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent e6d3e65 commit 6ee9b3d

File tree

1 file changed

+2
-43
lines changed

1 file changed

+2
-43
lines changed

mm/kasan/report.c

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -370,36 +370,6 @@ static inline bool init_task_stack_addr(const void *addr)
370370
sizeof(init_thread_union.stack));
371371
}
372372

373-
/*
374-
* This function is invoked with report_lock (a raw_spinlock) held. A
375-
* PREEMPT_RT kernel cannot call find_vm_area() as it will acquire a sleeping
376-
* rt_spinlock.
377-
*
378-
* For !RT kernel, the PROVE_RAW_LOCK_NESTING config option will print a
379-
* lockdep warning for this raw_spinlock -> spinlock dependency. This config
380-
* option is enabled by default to ensure better test coverage to expose this
381-
* kind of RT kernel problem. This lockdep splat, however, can be suppressed
382-
* by using DEFINE_WAIT_OVERRIDE_MAP() if it serves a useful purpose and the
383-
* invalid PREEMPT_RT case has been taken care of.
384-
*/
385-
static inline struct vm_struct *kasan_find_vm_area(void *addr)
386-
{
387-
static DEFINE_WAIT_OVERRIDE_MAP(vmalloc_map, LD_WAIT_SLEEP);
388-
struct vm_struct *va;
389-
390-
if (IS_ENABLED(CONFIG_PREEMPT_RT))
391-
return NULL;
392-
393-
/*
394-
* Suppress lockdep warning and fetch vmalloc area of the
395-
* offending address.
396-
*/
397-
lock_map_acquire_try(&vmalloc_map);
398-
va = find_vm_area(addr);
399-
lock_map_release(&vmalloc_map);
400-
return va;
401-
}
402-
403373
static void print_address_description(void *addr, u8 tag,
404374
struct kasan_report_info *info)
405375
{
@@ -429,19 +399,8 @@ static void print_address_description(void *addr, u8 tag,
429399
}
430400

431401
if (is_vmalloc_addr(addr)) {
432-
struct vm_struct *va = kasan_find_vm_area(addr);
433-
434-
if (va) {
435-
pr_err("The buggy address belongs to the virtual mapping at\n"
436-
" [%px, %px) created by:\n"
437-
" %pS\n",
438-
va->addr, va->addr + va->size, va->caller);
439-
pr_err("\n");
440-
441-
page = vmalloc_to_page(addr);
442-
} else {
443-
pr_err("The buggy address %px belongs to a vmalloc virtual mapping\n", addr);
444-
}
402+
pr_err("The buggy address %px belongs to a vmalloc virtual mapping\n", addr);
403+
page = vmalloc_to_page(addr);
445404
}
446405

447406
if (page) {

0 commit comments

Comments
 (0)