mm/kasan/common.c
Source file repositories/reference/linux-study-clean/mm/kasan/common.c
File Facts
- System
- Linux kernel
- Corpus path
mm/kasan/common.c- Extension
.c- Size
- 17046 bytes
- Lines
- 631
- 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/export.hlinux/init.hlinux/kasan.hlinux/kernel.hlinux/linkage.hlinux/memblock.hlinux/memory.hlinux/mm.hlinux/module.hlinux/printk.hlinux/sched.hlinux/sched/clock.hlinux/sched/task_stack.hlinux/slab.hlinux/stackdepot.hlinux/stacktrace.hlinux/string.hlinux/types.hlinux/bug.hlinux/vmalloc.hkasan.h../slab.h
Detected Declarations
function kasan_save_stackfunction kasan_set_trackfunction kasan_save_trackfunction kasan_enable_currentfunction kasan_disable_currentfunction __kasan_unpoison_rangefunction kasan_unpoison_task_stackfunction kasan_unpoison_task_stack_belowfunction __kasan_unpoison_pagesfunction __kasan_poison_pagesfunction __kasan_poison_slabfunction __kasan_unpoison_new_objectfunction __kasan_poison_new_objectfunction somewherefunction __kasan_init_slab_objfunction check_slab_allocationfunction poison_slab_objectfunction __kasan_slab_pre_freefunction __kasan_slab_freefunction check_page_allocationfunction __kasan_kfree_largefunction unpoison_slab_objectfunction __kasan_slab_allocfunction poison_kmalloc_redzonefunction __kasan_kmallocfunction poison_kmalloc_large_redzonefunction __kasan_kmalloc_largefunction __kasan_kreallocfunction __kasan_mempool_poison_pagesfunction __kasan_mempool_unpoison_pagesfunction __kasan_mempool_poison_objectfunction __kasan_mempool_unpoison_objectfunction __kasan_check_bytefunction __kasan_unpoison_vmap_areasfunction __kasan_vreallocexport kasan_flag_enabledexport kasan_enable_currentexport kasan_disable_currentexport __kasan_kmalloc
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* This file contains common KASAN code.
*
* Copyright (c) 2014 Samsung Electronics Co., Ltd.
* Author: Andrey Ryabinin <ryabinin.a.a@gmail.com>
*
* Some code borrowed from https://github.com/xairy/kasan-prototype by
* Andrey Konovalov <andreyknvl@gmail.com>
*/
#include <linux/export.h>
#include <linux/init.h>
#include <linux/kasan.h>
#include <linux/kernel.h>
#include <linux/linkage.h>
#include <linux/memblock.h>
#include <linux/memory.h>
#include <linux/mm.h>
#include <linux/module.h>
#include <linux/printk.h>
#include <linux/sched.h>
#include <linux/sched/clock.h>
#include <linux/sched/task_stack.h>
#include <linux/slab.h>
#include <linux/stackdepot.h>
#include <linux/stacktrace.h>
#include <linux/string.h>
#include <linux/types.h>
#include <linux/bug.h>
#include <linux/vmalloc.h>
#include "kasan.h"
#include "../slab.h"
#if defined(CONFIG_ARCH_DEFER_KASAN) || defined(CONFIG_KASAN_HW_TAGS)
/*
* Definition of the unified static key declared in kasan-enabled.h.
* This provides consistent runtime enable/disable across KASAN modes.
*/
DEFINE_STATIC_KEY_FALSE(kasan_flag_enabled);
EXPORT_SYMBOL_GPL(kasan_flag_enabled);
#endif
struct slab *kasan_addr_to_slab(const void *addr)
{
if (virt_addr_valid(addr))
return virt_to_slab(addr);
return NULL;
}
depot_stack_handle_t kasan_save_stack(gfp_t flags, depot_flags_t depot_flags)
{
unsigned long entries[KASAN_STACK_DEPTH];
unsigned int nr_entries;
nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 0);
return stack_depot_save_flags(entries, nr_entries, flags, depot_flags);
}
void kasan_set_track(struct kasan_track *track, depot_stack_handle_t stack)
{
#ifdef CONFIG_KASAN_EXTRA_INFO
u32 cpu = raw_smp_processor_id();
u64 ts_nsec = local_clock();
track->cpu = cpu;
track->timestamp = ts_nsec >> 9;
#endif /* CONFIG_KASAN_EXTRA_INFO */
track->pid = current->pid;
track->stack = stack;
}
void kasan_save_track(struct kasan_track *track, gfp_t flags)
{
depot_stack_handle_t stack;
stack = kasan_save_stack(flags, STACK_DEPOT_FLAG_CAN_ALLOC);
kasan_set_track(track, stack);
}
#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
void kasan_enable_current(void)
{
current->kasan_depth++;
}
EXPORT_SYMBOL(kasan_enable_current);
void kasan_disable_current(void)
{
Annotation
- Immediate include surface: `linux/export.h`, `linux/init.h`, `linux/kasan.h`, `linux/kernel.h`, `linux/linkage.h`, `linux/memblock.h`, `linux/memory.h`, `linux/mm.h`.
- Detected declarations: `function kasan_save_stack`, `function kasan_set_track`, `function kasan_save_track`, `function kasan_enable_current`, `function kasan_disable_current`, `function __kasan_unpoison_range`, `function kasan_unpoison_task_stack`, `function kasan_unpoison_task_stack_below`, `function __kasan_unpoison_pages`, `function __kasan_poison_pages`.
- 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.