Skip to the content.

使用 kernel 中调试工具

KASAN

KASLR

/*
 * See Documentation/x86/x86_64/mm.txt for a description of the memory map.
 *
 * Be very careful vs. KASLR when changing anything here. The KASLR address
 * range must not overlap with anything except the KASAN shadow area, which
 * is correct as KASAN disables KASLR.
 */
#define MAXMEM      (1UL << MAX_PHYSMEM_BITS)

debug

从内核的选项来看,对于 debug 一无所知啊 !

page owner

page owner is for the tracking about who allocated each page.

KASAN

Finding places where the kernel accesses memory that it shouldn’t is the goal for the kernel address sanitizer (KASan).

分析下如下的 config 是做啥的

CONFIG_CONSTRUCTORS=y
CONFIG_GENERIC_CSUM=y
CONFIG_KASAN_SHADOW_OFFSET=0xdffffc0000000000
CONFIG_STACKDEPOT_ALWAYS_INIT=y
CONFIG_KASAN=y
CONFIG_KASAN_GENERIC=y
CONFIG_KASAN_OUTLINE=y
# CONFIG_KASAN_INLINE is not set
CONFIG_KASAN_STACK=y
# CONFIG_KASAN_VMALLOC is not set
# CONFIG_KASAN_MODULE_TEST is not set

# 分析下 CONFIG_VMAP_STACK=y 是做什么的
# 打开 KASAN 之后,这个选项就消失了

kmemleak

Kmemleak provides a way of detecting possible kernel memory leaks in a way similar to a tracing garbage collector, with the difference that the orphan objects are not freed but only reported via /sys/kernel/debug/kmemleak. [^18]

Kernel 调试

基本按照这个操作

通过插入预防错误的方法实现

dump_page(page, "VM_BUG_ON_PAGE(" __stringify(cond)")");\

void dump_page(struct page *page, const char *reason)
{
	__dump_page(page, reason);
	dump_page_owner(page);
}
EXPORT_SYMBOL(dump_page);

以后再去慢慢跟踪吧!

KCSAN

检查下这个 commit,了解下 KCSAN 的原理 b95273f1272398a9f7145de37703f1930244e465

kernel hacking

memtest

本站所有文章转发 CSDN 将按侵权追究法律责任,其它情况随意。