mm/kmsan/kmsan.h
Source file repositories/reference/linux-study-clean/mm/kmsan/kmsan.h
File Facts
- System
- Linux kernel
- Corpus path
mm/kmsan/kmsan.h- Extension
.h- Size
- 6001 bytes
- Lines
- 188
- Domain
- Core OS
- Bucket
- Memory Management
- Inferred role
- Core OS: implementation source
- Status
- source 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.
- 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/irqflags.hlinux/kmsan.hlinux/mm.hlinux/nmi.hlinux/pgtable.hlinux/printk.hlinux/sched.hlinux/stackdepot.hlinux/stacktrace.h
Detected Declarations
struct shadow_origin_ptrenum kmsan_bug_reasonfunction kmsan_enter_runtimefunction kmsan_enter_runtimefunction kmsan_leave_runtimefunction set_dsh_extra_bitsfunction kmsan_uaf_from_ebfunction kmsan_depth_from_ebfunction kmsan_internal_is_module_addrfunction kmsan_internal_is_vmalloc_addr
Annotated Snippet
struct shadow_origin_ptr {
void *shadow, *origin;
};
struct shadow_origin_ptr kmsan_get_shadow_origin_ptr(void *addr, u64 size,
bool store);
void __init kmsan_init_alloc_meta_for_range(void *start, void *end);
enum kmsan_bug_reason {
REASON_ANY,
REASON_COPY_TO_USER,
REASON_SUBMIT_URB,
};
void kmsan_print_origin(depot_stack_handle_t origin);
/**
* kmsan_report() - Report a use of uninitialized value.
* @origin: Stack ID of the uninitialized value.
* @address: Address at which the memory access happens.
* @size: Memory access size.
* @off_first: Offset (from @address) of the first byte to be reported.
* @off_last: Offset (from @address) of the last byte to be reported.
* @user_addr: When non-NULL, denotes the userspace address to which the kernel
* is leaking data.
* @reason: Error type from enum kmsan_bug_reason.
*
* kmsan_report() prints an error message for a consequent group of bytes
* sharing the same origin. If an uninitialized value is used in a comparison,
* this function is called once without specifying the addresses. When checking
* a memory range, KMSAN may call kmsan_report() multiple times with the same
* @address, @size, @user_addr and @reason, but different @off_first and
* @off_last corresponding to different @origin values.
*/
void kmsan_report(depot_stack_handle_t origin, void *address, int size,
int off_first, int off_last, const void __user *user_addr,
enum kmsan_bug_reason reason);
DECLARE_PER_CPU(struct kmsan_ctx, kmsan_percpu_ctx);
static __always_inline struct kmsan_ctx *kmsan_get_context(void)
{
return in_task() ? ¤t->kmsan_ctx : raw_cpu_ptr(&kmsan_percpu_ctx);
}
/*
* When a compiler hook or KMSAN runtime function is invoked, it may make a
* call to instrumented code and eventually call itself recursively. To avoid
* that, we guard the runtime entry regions with
* kmsan_enter_runtime()/kmsan_leave_runtime() and exit the hook if
* kmsan_in_runtime() is true.
*
* Non-runtime code may occasionally get executed in nested IRQs from the
* runtime code (e.g. when called via smp_call_function_single()). Because some
* KMSAN routines may take locks (e.g. for memory allocation), we conservatively
* bail out instead of calling them. To minimize the effect of this (potentially
* missing initialization events) kmsan_in_runtime() is not checked in
* non-blocking runtime functions.
*/
static __always_inline bool kmsan_in_runtime(void)
{
if ((hardirq_count() >> HARDIRQ_SHIFT) > 1)
return true;
if (in_nmi())
return true;
return kmsan_get_context()->kmsan_in_runtime;
}
static __always_inline void kmsan_enter_runtime(void)
{
struct kmsan_ctx *ctx;
ctx = kmsan_get_context();
KMSAN_WARN_ON(ctx->kmsan_in_runtime++);
}
static __always_inline void kmsan_leave_runtime(void)
{
struct kmsan_ctx *ctx = kmsan_get_context();
KMSAN_WARN_ON(--ctx->kmsan_in_runtime);
}
depot_stack_handle_t kmsan_save_stack_with_flags(gfp_t flags,
unsigned int extra_bits);
/*
* Pack and unpack the origin chain depth and UAF flag to/from the extra bits
* provided by the stack depot.
* The UAF flag is stored in the lowest bit, followed by the depth in the upper
Annotation
- Immediate include surface: `linux/irqflags.h`, `linux/kmsan.h`, `linux/mm.h`, `linux/nmi.h`, `linux/pgtable.h`, `linux/printk.h`, `linux/sched.h`, `linux/stackdepot.h`.
- Detected declarations: `struct shadow_origin_ptr`, `enum kmsan_bug_reason`, `function kmsan_enter_runtime`, `function kmsan_enter_runtime`, `function kmsan_leave_runtime`, `function set_dsh_extra_bits`, `function kmsan_uaf_from_eb`, `function kmsan_depth_from_eb`, `function kmsan_internal_is_module_addr`, `function kmsan_internal_is_vmalloc_addr`.
- Atlas domain: Core OS / Memory Management.
- Implementation status: source 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.