mm/kasan/report_generic.c
Source file repositories/reference/linux-study-clean/mm/kasan/report_generic.c
File Facts
- System
- Linux kernel
- Corpus path
mm/kasan/report_generic.c- Extension
.c- Size
- 10505 bytes
- Lines
- 400
- 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.
- 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
linux/bitops.hlinux/ftrace.hlinux/init.hlinux/kernel.hlinux/mm.hlinux/printk.hlinux/sched.hlinux/sched/task_stack.hlinux/slab.hlinux/stackdepot.hlinux/stacktrace.hlinux/string.hlinux/types.hlinux/kasan.hlinux/module.hasm/sections.hkasan.h../slab.h
Detected Declarations
function Copyrightfunction kasan_get_alloc_sizefunction kasan_complete_mode_report_infofunction kasan_metadata_fetch_rowfunction kasan_print_aux_stacksfunction tokenize_frame_descrfunction print_decoded_frame_descrfunction get_address_stack_frame_infofunction kasan_print_address_stack_framefunction __asan_report_load_n_noabortfunction __asan_report_store_n_noabortexport __asan_report_load_n_noabortexport __asan_report_store_n_noabort
Annotated Snippet
if (tok_len + 1 > max_tok_len) {
pr_err("internal error: frame description too long: %s\n",
*frame_descr);
return false;
}
/* Copy token (+ 1 byte for '\0'). */
strscpy(token, *frame_descr, tok_len + 1);
}
/* Advance frame_descr past separator. */
*frame_descr = sep + 1;
if (value != NULL && kstrtoul(token, 10, value)) {
pr_err("internal error: not a valid number: %s\n", token);
return false;
}
return true;
}
static void print_decoded_frame_descr(const char *frame_descr)
{
/*
* We need to parse the following string:
* "n alloc_1 alloc_2 ... alloc_n"
* where alloc_i looks like
* "offset size len name"
* or "offset size len name:line".
*/
char token[64];
unsigned long num_objects;
if (!tokenize_frame_descr(&frame_descr, token, sizeof(token),
&num_objects))
return;
pr_err("\n");
pr_err("This frame has %lu %s:\n", num_objects,
num_objects == 1 ? "object" : "objects");
while (num_objects--) {
unsigned long offset;
unsigned long size;
/* access offset */
if (!tokenize_frame_descr(&frame_descr, token, sizeof(token),
&offset))
return;
/* access size */
if (!tokenize_frame_descr(&frame_descr, token, sizeof(token),
&size))
return;
/* name length (unused) */
if (!tokenize_frame_descr(&frame_descr, NULL, 0, NULL))
return;
/* object name */
if (!tokenize_frame_descr(&frame_descr, token, sizeof(token),
NULL))
return;
/* Strip line number; without filename it's not very helpful. */
strreplace(token, ':', '\0');
/* Finally, print object information. */
pr_err(" [%lu, %lu) '%s'", offset, offset + size, token);
}
}
/* 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,
unsigned long *offset,
const char **frame_descr,
const void **frame_pc)
{
unsigned long aligned_addr;
unsigned long mem_ptr;
const u8 *shadow_bottom;
const u8 *shadow_ptr;
const unsigned long *frame;
BUILD_BUG_ON(IS_ENABLED(CONFIG_STACK_GROWSUP));
aligned_addr = round_down((unsigned long)addr, sizeof(long));
mem_ptr = round_down(aligned_addr, KASAN_GRANULE_SIZE);
shadow_ptr = kasan_mem_to_shadow((void *)aligned_addr);
shadow_bottom = kasan_mem_to_shadow(end_of_stack(current));
while (shadow_ptr >= shadow_bottom && *shadow_ptr != KASAN_STACK_LEFT) {
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/ftrace.h`, `linux/init.h`, `linux/kernel.h`, `linux/mm.h`, `linux/printk.h`, `linux/sched.h`, `linux/sched/task_stack.h`.
- Detected declarations: `function Copyright`, `function kasan_get_alloc_size`, `function kasan_complete_mode_report_info`, `function kasan_metadata_fetch_row`, `function kasan_print_aux_stacks`, `function tokenize_frame_descr`, `function print_decoded_frame_descr`, `function get_address_stack_frame_info`, `function kasan_print_address_stack_frame`, `function __asan_report_load_n_noabort`.
- Atlas domain: Core OS / Memory Management.
- Implementation status: integration implementation candidate.
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.