Kernel Electric-Fence: Linux 5.12 Merges KFence For Low-Overhead Memory Safety Feature

Written by Michael Larabel in Linux Kernel on 26 February 2021 at 01:52 PM EST. 6 Comments
LINUX KERNEL
Linus Torvalds just merged a set of patches that includes KFence. Short for the Kernel Electric Fence, KFence is a low-overhead memory safety error detector/validator that is suitable for use in production kernel builds.

While there has long been KASAN as the Kernel Address Sanitizer for a dynamic memory error detector for discovering use-after-free and out-of-bounds bugs within the Linux kernel, KFence aims to provide a lower-overhead solution.

The Kernel Electric-Fence is a sampling-based memory safety error detector for uncovering similar out-of-bounds / use-after-free / invalid-free errors but because it's lower overhead can be used for production kernel builds with "near zero performance overhead". The hope is that KFence can uncover bugs not previously found by KASAN due to the difference focus of production vs. testing/non-production workloads.

KFence can be configured with the new CONFIG_KFENCE Kconfig switch. At boot-time, the kfence.sample_interval parameter can be used for controlling the sampling interval or a value of 0 to disable the functionality. Discovered bugs are reported to the kernel log. There is also a DebugFS interface for run-time statistics.


A KFence report example.


The Kernel Electric-Fence is backed by Google engineers and so far -- like KASAN -- is focused on x86_64 and ARM64 support. KFence has been under review the past number of months while today was merged as part of the latest AKPM patches.
Related News
About The Author
Michael Larabel

Michael Larabel is the principal author of Phoronix.com and founded the site in 2004 with a focus on enriching the Linux hardware experience. Michael has written more than 20,000 articles covering the state of Linux hardware support, Linux performance, graphics drivers, and other topics. Michael is also the lead developer of the Phoronix Test Suite, Phoromatic, and OpenBenchmarking.org automated benchmarking software. He can be followed via Twitter, LinkedIn, or contacted via MichaelLarabel.com.

Popular News This Week