kmemcheck简单的测试用例似乎不起作用

时间:2016-09-09 07:24:00

标签: debugging memory-management linux-kernel

我已经在x86_64(内核版本3.18.22)上构建了一个内核,启用了kmemcheck。 相关配置:

# grep KMEMCHECK /boot/config-3.18.22
CONFIG_HAVE_ARCH_KMEMCHECK=y
CONFIG_KMEMCHECK=y
CONFIG_KMEMCHECK_DISABLED_BY_DEFAULT=y
# CONFIG_KMEMCHECK_ENABLED_BY_DEFAULT is not set
# CONFIG_KMEMCHECK_ONESHOT_BY_DEFAULT is not set
CONFIG_KMEMCHECK_QUEUE_SIZE=64
CONFIG_KMEMCHECK_SHADOW_COPY_SHIFT=5
CONFIG_KMEMCHECK_PARTIAL_OK=y
# CONFIG_KMEMCHECK_BITOPS_OK is not set
# 

编写一个快速内核模块来测试kmemcheck捕获未初始化的slab内存访问。有问题的函数运行这个简单的测试用例:

static int slab_test(void)
{
    void *kbuf;
    kbuf = kmalloc(512, GFP_KERNEL);
    if (!kbuf) {
        pr_warn("out of memory!");
        return -ENOMEM;
    }
    pr_info("### slab_test: kbuf=%p\n", kbuf);
    print_hex_dump_bytes("### ", DUMP_PREFIX_ADDRESS, kbuf, 32);
    kfree(kbuf);
    return 0;
}

启用kmemcheck,插入模块并调用上面的函数,记录输出 - 全部通过下面的小包装脚本:

# cat tst.sh 
MOD=kmemchk_test
echo 0 > /proc/sys/kernel/kmemcheck
dmesg -C
rmmod ${MOD} 2>/dev/null
echo 1 > /proc/sys/kernel/kmemcheck
insmod ${MOD}.ko
sleep 1
echo 0 > /proc/sys/kernel/kmemcheck
dmesg > out.txt
# 

我的问题是:kmemcheck似乎根本没有捕获到未初始化的内存访问!这是输出:

# dmesg 
--snip--
kern  :info  : [  +0.000005] ### slab_test: kbuf=ffff88003ccc8000
kern  :debug : [  +0.000003] ### ffff88003ccc8000: 00 8c cc 3c 00 88 ff ff 75 6c 65 2f 6b 6d 65 6d  ...<....ule/kmem
kern  :debug : [  +0.000003] ### ffff88003ccc8010: 63 68 6b 5f 74 65 73 74 00 41 43 54 49 4f 4e 3d  chk_test.ACTION=
# 

知道为什么吗? TIA ..

0 个答案:

没有答案