Home The Kernel Memory Sanitizer (KMSAN)
Post
Cancel

The Kernel Memory Sanitizer (KMSAN)

一、kmsan

1
2
3
4
https://github.com/google/kmsan/blob/master/Documentation/dev-tools/kmsan.rst
KMSAN is a dynamic error detector aimed at finding uses of uninitialized values. It is based on compiler instrumentation, and is quite similar to the userspace MemorySanitizer tool.

An important note is that KMSAN is not intended for production use, because it drastically increases kernel memory footprint and slows the whole system down.

1、插桩 __no_kmsan_checks

2、 metadata shadow byte

Linux 内核的 KMSAN 补丁,有助于捕获未初始化的内存问题

One of the Linux patch series that has been in the works for years in conjunction with Clang compiler side changes and already being responsible for exposing hundreds of kernel bugs is the KernelMemorySanitizer (KMSAN). Sent out today was the latest patch series working on the kernel infrastructure for catching uninitialized memory issues.

KernelMemorySanitizer (KMSAN) 这个补丁已经开发了好几年了,这个补丁配合 Clang 编译器端的修改,而 Clang KMSAN 代码可以追溯到 2018 年。虽然该补丁还未被合入主线,但在两者相互配合下,已经帮助我们找出了内核中数百个错误。

26 日来自 Google 的 Alexander Potapenko,也是 KMSAN 补丁的作者,又发布了一个新的版本,可以用于捕获未初始化的内存问题。Potapenko 指出, "KMSAN has reported more than 300 bugs in the past few years, most of them with the help of syzkaller. Such bugs keep getting introduced into the kernel despite new compiler warnings and other analyses (the 5.16 cycle already resulted in several KMSAN-reported bugs). Mitigations like total stack and heap initialization are unfortunately very far from being deployable. The proposed patchset contains KMSAN runtime implementation together with small changes to other subsystems needed to make KMSAN work."。KMSAN 在过去几年中报告了 300 多个错误,其中大多数是在 syzkaller 的帮助下。尽管有新的编译器警告和其他分析支持,但针对栈和堆初始化的检测还未支持。这次新提交的补丁包含 KMSAN 运行时的实现以及对其他子系统的小改动。这包括了超过四千行新代码。对 KernelMemorySanitizer 感兴趣的人可以阅读 Alexander Potapenko 的这个 2020 年的 PDF slids(https://clangbuiltlinux.github.io/CBL-meetup-2020-slides/glider/Fighting_uninitialized_memory_%40_CBL_Meetup_2020.pdf)

更多介绍请阅读新闻出处,“KMSAN Patches For The Linux Kernel Updated For Catching Uninitialized Memory Problems”: https://www.phoronix.com/scan.php?page=news_item&px=KernelMemorySanitizer-2022。

This post is licensed under CC BY 4.0 by the author.