mm/kasan/generic.c
Source file repositories/reference/linux-study-clean/mm/kasan/generic.c
File Facts
- System
- Linux kernel
- Corpus path
mm/kasan/generic.c- Extension
.c- Size
- 16228 bytes
- Lines
- 589
- 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/interrupt.hlinux/init.hlinux/kasan.hlinux/kernel.hlinux/kfence.hlinux/kmemleak.hlinux/linkage.hlinux/memblock.hlinux/memory.hlinux/mm.hlinux/module.hlinux/printk.hlinux/sched.hlinux/sched/task_stack.hlinux/slab.hlinux/spinlock.hlinux/stackdepot.hlinux/stacktrace.hlinux/string.hlinux/types.hlinux/vmalloc.hlinux/bug.hkasan.h../slab.h
Detected Declarations
function Copyrightfunction memory_is_poisoned_1function memory_is_poisoned_2_4_8function memory_is_poisoned_16function bytes_is_nonzerofunction memory_is_nonzerofunction memory_is_poisoned_nfunction memory_is_poisonedfunction check_region_inlinefunction kasan_check_rangefunction kasan_byte_accessiblefunction kasan_cache_shrinkfunction kasan_cache_shutdownfunction register_globalfunction __asan_register_globalsfunction __asan_unregister_globalsfunction __asan_loadNfunction __asan_storeNfunction __asan_handle_no_returnfunction __asan_alloca_poisonfunction __asan_allocas_unpoisonfunction optimal_redzonefunction kasan_cache_createfunction slub_debug_orig_sizefunction kasan_init_object_metafunction release_alloc_metafunction release_free_metafunction kasan_metadata_sizefunction kasan_record_aux_stackfunction kasan_save_alloc_infofunction kasan_save_free_infoexport __asan_register_globalsexport __asan_unregister_globalsexport __asan_loadNexport __asan_loadN_noabortexport __asan_storeNexport __asan_storeN_noabortexport __asan_handle_no_returnexport __asan_alloca_poisonexport __asan_allocas_unpoison
Annotated Snippet
switch (size) {
case 1:
return memory_is_poisoned_1(addr);
case 2:
case 4:
case 8:
return memory_is_poisoned_2_4_8(addr, size);
case 16:
return memory_is_poisoned_16(addr);
default:
BUILD_BUG();
}
}
return memory_is_poisoned_n(addr, size);
}
static __always_inline bool check_region_inline(const void *addr,
size_t size, bool write,
unsigned long ret_ip)
{
if (!kasan_enabled())
return true;
if (unlikely(size == 0))
return true;
if (unlikely(addr + size < addr))
return !kasan_report(addr, size, write, ret_ip);
if (unlikely(!addr_has_metadata(addr)))
return !kasan_report(addr, size, write, ret_ip);
if (likely(!memory_is_poisoned(addr, size)))
return true;
return !kasan_report(addr, size, write, ret_ip);
}
bool kasan_check_range(const void *addr, size_t size, bool write,
unsigned long ret_ip)
{
return check_region_inline(addr, size, write, ret_ip);
}
bool kasan_byte_accessible(const void *addr)
{
s8 shadow_byte;
if (!kasan_enabled())
return true;
shadow_byte = READ_ONCE(*(s8 *)kasan_mem_to_shadow(addr));
return shadow_byte >= 0 && shadow_byte < KASAN_GRANULE_SIZE;
}
void kasan_cache_shrink(struct kmem_cache *cache)
{
kasan_quarantine_remove_cache(cache);
}
void kasan_cache_shutdown(struct kmem_cache *cache)
{
if (!__kmem_cache_empty(cache))
kasan_quarantine_remove_cache(cache);
}
static void register_global(struct kasan_global *global)
{
size_t aligned_size = round_up(global->size, KASAN_GRANULE_SIZE);
kasan_unpoison(global->beg, global->size, false);
kasan_poison(global->beg + aligned_size,
global->size_with_redzone - aligned_size,
KASAN_GLOBAL_REDZONE, false);
}
void __asan_register_globals(void *ptr, ssize_t size)
{
int i;
struct kasan_global *globals = ptr;
for (i = 0; i < size; i++)
register_global(&globals[i]);
}
EXPORT_SYMBOL(__asan_register_globals);
void __asan_unregister_globals(void *ptr, ssize_t size)
Annotation
- Immediate include surface: `linux/export.h`, `linux/interrupt.h`, `linux/init.h`, `linux/kasan.h`, `linux/kernel.h`, `linux/kfence.h`, `linux/kmemleak.h`, `linux/linkage.h`.
- Detected declarations: `function Copyright`, `function memory_is_poisoned_1`, `function memory_is_poisoned_2_4_8`, `function memory_is_poisoned_16`, `function bytes_is_nonzero`, `function memory_is_nonzero`, `function memory_is_poisoned_n`, `function memory_is_poisoned`, `function check_region_inline`, `function kasan_check_range`.
- 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.