The codebase of the Linux kernel, on which version 6.18 is based, has accepted the implementation of the inter-process communication mechanism Binder, written in Rust. Binder is used in Android to organize interaction between processes and remote method calls (one Android process can invoke a method or function in another Android process, using Binder to identify, call, and pass arguments between processes). The Binder code was rewritten in Rust as part of a project aimed at enhancing security, promoting safe programming practices, and improving the efficiency of memory issue detection in Android (about 70% of all critical vulnerabilities identified in Android are caused by memory handling errors).
Using Rust allowed for the resolution of some issues faced by Binder developers, including errors related to reference counting, deadlocks, and boundary checks, as well as significantly reducing the complexity of error handling. The Rust implementation of Binder functions similarly to the original C version, passes all AOSP (Android Open-Source Project) tests, and can be used to create working builds of Android firmware. Despite its advanced capabilities and support for objects with complex ownership semantics, the Rust driver is smaller than the C variant—5.5 versus 5.8 thousand lines of code.
In the commit description, the author mentions the following motivations for rewriting Binder:
- Binder has been evolving for 15 years, and during this time, its functionality and complexity have significantly increased—the project is at the intersection of all Android components and covers many tasks beyond IPC:
- correct analysis and transformation of transaction contents that may contain multiple objects of different types (e.g., pointers, file descriptors) interacting with each other;
- controlling thread pool sizes in user space and ensuring the assignment of transactions to threads in such a way as to avoid deadlocks when the thread pool is exhausted;
- tracking reference counters of objects shared by multiple processes, correctly forwarding changes to reference counters between processes;
- processing numerous error scenarios while coordinating 13 different locks, 7 link counters, and atomic variables. In doing so, it must perform such tasks as quickly and accurately as possible.
- The old codebase has accumulated significant technical debt, complicating both bug detection and further development. For instance, large functions exceeding a thousand lines of code, questionable error handling methods, and convoluted structures are found in the core.
- Binder is a critical security component of Android, as platform elements operating in isolated sandbox environments, such as the rendering process in Chrome and the SW Codec, have direct access to it. A vulnerability in Binder would allow bypassing isolation. The high complexity combined with technical debt significantly complicates maintaining a high level of security in Binder.
Source: opennet.ru
