mm/kasan/report.c
Source file repositories/reference/linux-study-clean/mm/kasan/report.c
File Facts
- System
- Linux kernel
- Corpus path
mm/kasan/report.c- Extension
.c- Size
- 18481 bytes
- Lines
- 681
- Domain
- Core OS
- Bucket
- Memory Management
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
kunit/test.hkunit/visibility.hlinux/bitops.hlinux/ftrace.hlinux/init.hlinux/kernel.hlinux/lockdep.hlinux/mm.hlinux/printk.hlinux/sched.hlinux/slab.hlinux/stackdepot.hlinux/stacktrace.hlinux/string.hlinux/types.hlinux/vmalloc.hlinux/kasan.hlinux/module.hlinux/sched/task_stack.hlinux/uaccess.htrace/events/error_report.hasm/sections.hkasan.h../slab.h
Detected Declarations
enum kasan_arg_faultfunction early_kasan_faultfunction kasan_set_multi_shotfunction report_suppressed_swfunction report_suppress_startfunction report_suppress_stopfunction report_enabledfunction kasan_save_enable_multi_shotfunction kasan_restore_multi_shotfunction kasan_kunit_test_suite_startfunction kasan_kunit_test_suite_endfunction kasan_kunit_test_suite_executingfunction kasan_kunit_test_suite_executingfunction fail_non_kasan_kunit_testfunction fail_non_kasan_kunit_testfunction start_reportfunction end_reportfunction print_error_descriptionfunction print_trackfunction describe_object_addrfunction describe_object_stacksfunction describe_objectfunction kernel_or_module_addrfunction init_task_stack_addrfunction print_address_descriptionfunction meta_row_is_guiltyfunction meta_pointer_offsetfunction print_memory_metadatafunction print_reportfunction complete_report_infofunction kasan_report_invalid_freefunction kasan_reportfunction kasan_report_asyncfunction kasan_non_canonical_hook
Annotated Snippet
static inline bool kasan_kunit_test_suite_executing(void) { return false; }
#endif /* CONFIG_KASAN_KUNIT_TEST */
#if IS_ENABLED(CONFIG_KUNIT)
static void fail_non_kasan_kunit_test(void)
{
struct kunit *test;
if (kasan_kunit_test_suite_executing())
return;
test = current->kunit_test;
if (test)
kunit_set_failure(test);
}
#else /* CONFIG_KUNIT */
static inline void fail_non_kasan_kunit_test(void) { }
#endif /* CONFIG_KUNIT */
static DEFINE_RAW_SPINLOCK(report_lock);
static void start_report(unsigned long *flags)
{
fail_non_kasan_kunit_test();
/* Respect the /proc/sys/kernel/traceoff_on_warning interface. */
disable_trace_on_warning();
/* Do not allow LOCKDEP mangling KASAN reports. */
lockdep_off();
/* Make sure we don't end up in loop. */
report_suppress_start();
raw_spin_lock_irqsave(&report_lock, *flags);
pr_err("==================================================================\n");
}
static void end_report(unsigned long *flags, const void *addr, bool is_write)
{
if (addr)
trace_error_report_end(ERROR_DETECTOR_KASAN,
(unsigned long)addr);
pr_err("==================================================================\n");
raw_spin_unlock_irqrestore(&report_lock, *flags);
if (!test_bit(KASAN_BIT_MULTI_SHOT, &kasan_flags))
check_panic_on_warn("KASAN");
switch (kasan_arg_fault) {
case KASAN_ARG_FAULT_DEFAULT:
case KASAN_ARG_FAULT_REPORT:
break;
case KASAN_ARG_FAULT_PANIC:
panic("kasan.fault=panic set ...\n");
break;
case KASAN_ARG_FAULT_PANIC_ON_WRITE:
if (is_write)
panic("kasan.fault=panic_on_write set ...\n");
break;
}
add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
lockdep_on();
report_suppress_stop();
}
static void print_error_description(struct kasan_report_info *info)
{
pr_err("BUG: KASAN: %s in %pS\n", info->bug_type, (void *)info->ip);
if (info->type != KASAN_REPORT_ACCESS) {
pr_err("Free of addr %px by task %s/%d\n",
info->access_addr, current->comm, task_pid_nr(current));
return;
}
if (info->access_size)
pr_err("%s of size %zu at addr %px by task %s/%d\n",
info->is_write ? "Write" : "Read", info->access_size,
info->access_addr, current->comm, task_pid_nr(current));
else
pr_err("%s at addr %px by task %s/%d\n",
info->is_write ? "Write" : "Read",
info->access_addr, current->comm, task_pid_nr(current));
}
static void print_track(struct kasan_track *track, const char *prefix)
{
#ifdef CONFIG_KASAN_EXTRA_INFO
u64 ts_nsec = track->timestamp;
unsigned long rem_usec;
Annotation
- Immediate include surface: `kunit/test.h`, `kunit/visibility.h`, `linux/bitops.h`, `linux/ftrace.h`, `linux/init.h`, `linux/kernel.h`, `linux/lockdep.h`, `linux/mm.h`.
- Detected declarations: `enum kasan_arg_fault`, `function early_kasan_fault`, `function kasan_set_multi_shot`, `function report_suppressed_sw`, `function report_suppress_start`, `function report_suppress_stop`, `function report_enabled`, `function kasan_save_enable_multi_shot`, `function kasan_restore_multi_shot`, `function kasan_kunit_test_suite_start`.
- Atlas domain: Core OS / Memory Management.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.