Automatic Detection of Reference Counting Bugs in Linux Kernel Drivers

Joe Hattori, Naoki Kobayashi, Ken Sakayori · 2026

Read Automatic Detection of Reference Counting Bugs in Linux Kernel Drivers by Joe Hattori, Naoki Kobayashi, Ken Sakayori (2026) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2605-13246.txt.

Introduction

Hattori, Kobayashi and Sakayori build DrvHorn, a tool that hunts reference counting faults in Linux kernel drivers. Such faults miscount live references to resources and can cause leaks or security holes. By modelling the driver interface and slicing programs aggressively, the tool found 545 faults across platform drivers, with 424 previously unknown. The authors submitted fixes, and 45 of their patches were merged into the kernel.

Catalog record

CREATORJoe Hattori, Naoki Kobayashi, Ken Sakayori
YEAR2026
COLLECTIONPAPERS
FORMATTXT
FILE SIZE37344
LICENSEhttp://creativecommons.org/licenses/by/4.0/
RIGHTSCC BY
SOURCEarXiv

Source: https://arxiv.org/abs/2605.13246

Browse the full library · About the Tower of Babel

Full text

The opening of the work, from the library's hosted text:

Automatic Detection of Reference Counting Bugs in Linux Kernel Drivers Joe Hattori, Naoki Kobayashi, Ken Sakayori Abstract Reference counting bugs in Linux kernel drivers can lead to severe resource mismanagement and security vulnerabilities. We introduce DrvHorn , a novel automated tool to detect these bugs by reducing reference counting verification to an assertion checking problem leveraging the Linux driver interface. Through efficient modeling of the Linux kernel and aggressive program slicing, DrvHorn discovered 545 bugs, of which 424 were previously unknown, across all platform drivers in v6.6 Linux kernel, with a lower false positive rate of 29.9% compared to prior studies. To address the root causes of these newly discovered bugs, we submitted patches to the Linux kernel, and 45 of them were merged. 1 Introduction In a monolithic OS kernel like Linux, device drivers operate at the same privilege level as the rest of the kernel, making any bugs in drivers a substantial security risk. This concern is amplified by the size of the driver codebase---approximately 66.5% of the entire kernel, 1 1 1 Based on lines of code in the initial v6.6 release —and by the fact that users can develop and load their own drivers at will. Given the above, static and automated verification of Linux drivers’ bug-freeness is crucial. The Linux kernel is predominantly written in C and reference counts (refcounts) are extensively used to manually manage the lifecycle of kernel objects [ 11 ] . A refcount tracks the number of references to an object, where a positive refcount means the object is in use, and zero means it is no longer used and can be freed. Refcount mechanisms are used extensively across all parts of the kernel, including drivers. Refcount bugs occur when the refcount does not match the actual number of references [ 6 ] . Excessive refcount causes memory leaks, and insufficient refcount leads to use-after-free (UAF). CVE-2023-7192 [ 18 ] is an example of a refcount bug that leaks memory, allowing a local attacker with CAP_NET_ADMIN to perform a DoS attack. Many other refcount bugs with varying impact have also been reported in the Linux kernel [ 17 , 1 ] . We present DrvHorn , a novel tool to automatically detect refcount bugs in Linux drivers 2 2 2 DrvHorn is available at https://github.com/joehattori/drvhorn . By focusing on drivers, DrvHorn achieves scalable refcount bug detection with high accuracy. DrvHorn utilizes the kernel-provided driver interface to reduce refcount verification into an assertion checking problem. DrvHorn can be integrated with arbitrary tools that perform assertion checking on LLVM bitcode. In our evaluation, we employed SeaHorn [ 7 ] , a state-of-the-art CHC-based verification framework, to analyze all platform drivers in x86-64 Linux v6.6. It reported 777 bugs, of which 545 bugs were real, showing a relatively low false positive rate of 29.9% compared to prior studies. Out of the real bugs, 424 were previously unknown, and 45 patches by us were merged into the Linux kernel to address the root causes of these newly discovered bugs. The structure of this paper is as follows. section 2 provides an overview of DrvHorn . section 3 explains the key techniques of our approach. section 4 presents the evaluation results. section 5 discusses the related work, and section 6 concludes the paper with future work. 2 Overview This section provides a brief overview of DrvHorn and illustrates its capabilities with a concrete example. DrvHorn takes two inputs: the Linux kernel source code compiled to LLVM bitcode and the name of the target driver. The tool then analyzes the inputs fully automatically and outputs whether or not there may exist a refcount bug in the initialization phase of the target driver. 3 3 3 Producing a more informative report is left for future work. DrvHorn requires only three kernel modifications: Makefile support for generating the LLVM bitcode, adding a dummy field to struct kref 4 4 4 This is done to prevent LLVM to merge structurally equivalent types , and disabling inlining of refcount APIs such as kref_get and kref_put . Refcount manipulations primarily occur in initialization and cleanup functions. Since the main responsibility of cleanup functions is releasing resources while error paths of initialization functions are prone to missing it, any invalid refcount manipulation in the cleanup path would most likely also exist in the error path of the initialization function. Therefore, DrvHorn focuses on the initialization phase, and our evaluation confirms the effectiveness of this approach by discovering 545 bugs including bugs in cleanup functions 5 5 5 Commit 74adad5 found a refcount bug which also resided in a cleanup function . The analysis of other parts is left for future work. Extending DrvHorn to termination/release functions should require only modest implementation effort because the same modeling, slicing, and assertion-checking pipeline can be reused. The main challenge is that analyzing more driver code and more environment interaction can increase both false positives and false negatives. The practical benefit may also be limited, since many release-function refcount bugs would likely already be reflected in initialization error paths. DrvHorn is neither sound nor complete: it may miss a bug and also report a false bug. However, our evaluation suggests that the false negative/positive rates are small. Figure 1 shows an example of a real-world refcount bug found and fixed by using DrvHorn in commit e386209. bcm_sf2_mdio_register () iterates over child nodes using for_each_available_child_of_node () . Within the loop, of_phy_find_device () increments the refcount of struct phy_device , which is then removed by phy_device_remove () . However, the incremented refcount was not decremented, causing a memory leak that was fixed by adding phy_device_free () . ⬇ # define for_each_available_child_of_node ( parent , child ) \ for ( child = of_get_next_available_child ( parent , NULL ); \ child != NULL ; child = of_get_next_available_child ( parent , child )) static int bcm_sf2_mdio_register ( struct dsa_switch * ds ) { struct device_node * dn , * child ; ... for_each_available_child_of_node ( dn , child ) { ... struct phy_device * phydev = of_phy_find_device ( child ); if ( phydev ) { phy_device_remove ( phydev ); @ \ diffadd {+ phy \ _device \ _free ( phydev );} @ } } ... } Figure 1: Commit e386209 3 Proposed Method Figure 2 shows the overall architecture of DrvHorn . DrvHorn transforms the refcount verification problem into an assertion problem (described in section 3.1 ). This assertion problem can then be solved by arbitrary off-the-shelf solvers such as bounded model checkers and CHC solvers [ 10 , 4 ] , as long as they accept LLVM bitcode input. (A CHC solver SeaHorn was adopted as our backend solver; the reason for this choice is explained in sections 3.4 and 4.3 .) However, naively applying these solvers to the refcount bug detection is infeasible due to the large size and the high complexity of the Linux kernel. To cope with this problem, DrvHorn takes two additional steps: modeling the Linux kernel (described in section 3.2 ) and program slicing (described in section 3.3 ). The modeling phase replaces specific functions and instructions with simpler abstractions that accurately capture the refcount behavior to mitigate the complexity of the Linux kernel. The slicing phase

Read the complete text