How to enable KASAN in Ubuntu 18.04 for X86_64
末日都过了,还在用 Ubuntu 18.04? 好吧,我觉得应该有很多人都在用。。。废话少说,上游 syzbot 天天查你,这不 KASAN bug 又来了,先来看看怎么使能 KASAN。
直接 menuconfig 按如下路径愣是找不到:
Kernel hacking -> Memory Debugging |
来看下配置说明,在lib/Kconfig.kasan 里:
bool "KASAN: dynamic memory safety error detector" depends on (((HAVE_ARCH_KASAN && CC_HAS_KASAN_GENERIC) || \ (HAVE_ARCH_KASAN_SW_TAGS && CC_HAS_KASAN_SW_TAGS)) && \ CC_HAS_WORKING_NOSANITIZE_ADDRESS) || \ HAVE_ARCH_KASAN_HW_TAGS depends on (SLUB && SYSFS) || (SLAB && !DEBUG_SLAB) select STACKDEPOT_ALWAYS_INIT help
KASAN has three modes: 1. Generic KASAN (supported by many architectures, enabled with CONFIG_KASAN_GENERIC, similar to userspace ASan), 2. Software Tag-Based KASAN (arm64 only, based on software memory tagging, enabled with CONFIG_KASAN_SW_TAGS, similar to userspace HWASan), and 3. Hardware Tag-Based KASAN (arm64 only, based on hardware memory tagging, enabled with CONFIG_KASAN_HW_TAGS).
ok, 我这是 x86_64,就看1就行了。也就是:
(HAVE_ARCH_KASAN && CC_HAS_KASAN_GENERIC) && CC_HAS_WORKING_NOSANITIZE_ADDRESS |
搜了下 .config 没有 CC_HAS_WORKING_NOSANITIZE_ADDRESS
这玩意啊,再看说明:
bool "Generic KASAN" depends on HAVE_ARCH_KASAN && CC_HAS_KASAN_GENERIC depends on CC_HAS_WORKING_NOSANITIZE_ADDRESS select SLUB_DEBUG if SLUB select CONSTRUCTORS help Enables Generic KASAN. Requires GCC 8.3.0+ or Clang.
gcc 版本有要求?赶紧 check 下:
tj@u1804:~/$ gcc --version |
还真是版本问题,可以不用编译安装,已经有打包好的了,具体安装步骤:
- add source
sudo apt install software-properties-common |
- install
sudo apt install gcc-8 |
- enable
tj@u1804:~/$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 80 --slave /usr/bin/g++ g++ /usr/bin/g++-8 |
- verfiy
tj@u1804:~/$ gcc --version |
- delete if needed
sudo update-alternatives --remove gcc /usr/bin/gcc-8 |
menuconfig 看看,果然在那,just 打个*。
版权声明:本站所有文章均采用 CC BY-NC-SA 4.0 CN 许可协议。转载请注明原文链接!