mm/kasan/kasan.h

Source file repositories/reference/linux-study-clean/mm/kasan/kasan.h

File Facts

System
Linux kernel
Corpus path
mm/kasan/kasan.h
Extension
.h
Size
20141 bytes
Lines
670
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct kasan_track {
	u32 pid;
	depot_stack_handle_t stack;
#ifdef CONFIG_KASAN_EXTRA_INFO
	u64 cpu:20;
	u64 timestamp:44;
#endif /* CONFIG_KASAN_EXTRA_INFO */
};

enum kasan_report_type {
	KASAN_REPORT_ACCESS,
	KASAN_REPORT_INVALID_FREE,
	KASAN_REPORT_DOUBLE_FREE,
};

struct kasan_report_info {
	/* Filled in by kasan_report_*(). */
	enum kasan_report_type type;
	const void *access_addr;
	size_t access_size;
	bool is_write;
	unsigned long ip;

	/* Filled in by the common reporting code. */
	const void *first_bad_addr;
	struct kmem_cache *cache;
	void *object;
	size_t alloc_size;

	/* Filled in by the mode-specific reporting code. */
	const char *bug_type;
	struct kasan_track alloc_track;
	struct kasan_track free_track;
};

/* Do not change the struct layout: compiler ABI. */
struct kasan_source_location {
	const char *filename;
	int line_no;
	int column_no;
};

/* Do not change the struct layout: compiler ABI. */
struct kasan_global {
	const void *beg;		/* Address of the beginning of the global variable. */
	size_t size;			/* Size of the global variable. */
	size_t size_with_redzone;	/* Size of the variable + size of the redzone. 32 bytes aligned. */
	const void *name;
	const void *module_name;	/* Name of the module where the global variable is declared. */
	unsigned long has_dynamic_init;	/* This is needed for C++. */
#if KASAN_ABI_VERSION >= 4
	struct kasan_source_location *location;
#endif
#if KASAN_ABI_VERSION >= 5
	char *odr_indicator;
#endif
};

/* Structures for keeping alloc and free meta. */

#ifdef CONFIG_KASAN_GENERIC

/*
 * Alloc meta contains the allocation-related information about a slab object.
 * Alloc meta is saved when an object is allocated and is kept until either the
 * object returns to the slab freelist (leaves quarantine for quarantined
 * objects or gets freed for the non-quarantined ones) or reallocated via
 * krealloc or through a mempool.
 * Alloc meta is stored inside of the object's redzone.
 * Alloc meta is considered valid whenever it contains non-zero data.
 */
struct kasan_alloc_meta {
	struct kasan_track alloc_track;
	/* Free track is stored in kasan_free_meta. */
	depot_stack_handle_t aux_stack[2];
};

struct qlist_node {
	struct qlist_node *next;
};

/*
 * Free meta is stored either in the object itself or in the redzone after the
 * object. In the former case, free meta offset is 0. In the latter case, the
 * offset is between 0 and INT_MAX. INT_MAX marks that free meta is not present.
 */
#define KASAN_NO_FREE_META INT_MAX

/*
 * Free meta contains the freeing-related information about a slab object.

Annotation

Implementation Notes