Newshot

Removing binder.c

Original text(via Lobsters)

Removing binder.c

The final talk at Kangrejos 2026 was about the removal of the C implementation of Android's Binder driver, the primary interprocess communication mechanism used on Android devices. Carlos Llamas announced that he had deleted the C code to general applause, and then shared some insights about what went into replacing the C implementation. Alice Ryhl, who has worked on the Rust implementation for some years, added her own thoughts about what the most difficult and interesting parts of the transition were.

Binder was added to the kernel in 2008, Llamas said, as an interprocess communication mechanism for Android devices. Its design originated in BeOS, but it has grown significantly since then. It provides a rich set of operations for allowing processes to communicate with the minimum amount of overhead. It also, therefore, presents a large attack surface for Android. Many complicated chained attacks against Android have involved Binder at one step or another, Llamas explained. Google's internal "red team" (the team dedicated to proactive security research) deemed Binder to be the most vulnerability-dense component in the entire operating system, with more CVEs per line than anywhere else.

Carlos Llamas
Carlos Llamas

That made it an obvious candidate for porting to Rust, Llamas said. Binder was the first user of Rust in the kernel, he added, although Ryhl did not publicly post the first version of what became the Rust implementation until 2023, well after the Rust experiment started in 2021. All told, the effort took more than five years. Binder is used for every single screen touch, permission check, and cross-application message on Android, which runs on more than three billion devices. In total, it works out to hundreds of billions of Binder transactions per second, globally, he added. That scale meant that even the smallest discrepancy between the interface provided by the C version and the one provided by the Rust version would cause problems and regressions for some use case.

One particularly tricky aspect has been performance, Ryhl said. Throughput doesn't matter that much; what matters is the tail latencies. Most screen frames on Android have a Binder transaction in the critical path of the frame, she explained. So, a difference of two microseconds on average is not a real problem, but if Binder is ever twenty milliseconds slower, even once in a while, people will notice and care.

Alice Ryhl
Alice Ryhl

The actual algorithms that the C and Rust implementations use are identical, she continued, so there are no large differences in throughput. But, because Rust handles locking differently, there were problems with the tail latency from lock contention that she had to debug. For example, one user-reported traceback showed Binder attempting to take a mutex that was held by another process. That process was preempted, and did not resume executing for twenty milliseconds, well past the sixteen millisecond budget to render a single frame.

It was a classic case of priority inversion. To solve the problem in Binder, Ryhl moved as many operations out from under the lock as possible, and was able to replace it with a spinlock, which made the problem go away. The equivalent lock in the C implementation was already a spinlock: "I deviated from C Binder, and pow. It has eighteen years of accumulated quirks."

Eventually, however, the Rust implementation was good enough for most use cases. And the C implementation was still producing new vulnerabilities every time someone tried to introduce a new feature. Eventually, Llamas and Ryhl decided to only add new features to the Rust implementation, in order to motivate people to switch and to avoid headaches from the C implementation. That policy has resulted in the Rust version becoming faster than the C version, because Ryhl was able to introduce an algorithmic improvement that reduced the number of needed system calls, a change that had been considered too complex for the C implementation. Now that the C implementation has been deleted, there are more of those coming, she promised.

Another area that proved difficult was dealing with tracepoints. Users aren't supposed to rely on the presence or behavior of most kernel-internal tracepoints, but they do. This meant that Ryhl had to copy the existing tracepoints in Binder as a de facto part of the driver's API. That even extended into some of the data structures involved in the driver. In one case, she said, there was a reference-counted structure that had a slightly different reference count in the Rust implementation, because the Rust code was holding an additional pointer to the structure. That turned out to be a problem for one particular piece of client code, since it relied on checking the reference count via a tracepoint in order to determine when the C implementation had reached a particular state.

There was also a lot of toolchain support needed, Ryhl continued. The Rust implementation had to work with kernel address-space layout randomization (KASLR), control-flow integrity (CFI), and profile-guided optimization. Production Android kernels are built with all of those enabled, and since they impact code generation, the Rust code needed to account for them.

Llamas then went into more detail about the deployment plan that will be used to convert users to the Rust implementation. A major problem with just rolling the Rust implementation out is the existence of vendor hooks: custom tracepoints used to inject vendor-specific behavior into the kernel. The Rust implementation of Binder was not able to reproduce those in every case, and therefore many vendors are stuck on the C implementation until they update their code. That's going to be a slow process.

Old stable versions of the kernel will continue to have the C Binder, and receive security fixes, which gives the various Android vendors a little bit of leeway until they're forced to update. After the conference, the patch removing the C implementation was merged as part of the 7.4 merge window, so that is the version past which the Rust implementation is required. 7.3 is the designated long-term-support release for 2026.

One person asked whether this would pose a problem for people compiling the kernel with GCC. Miguel Ojeda responded that many distributions are using a workaround for the current lack of Rust support in GCC: they are building the C side of the kernel with GCC, and the Rust side with LLVM. He said that he had advised against compiling the kernel in that way, because it is "a complete hack", though people who use it are unlikely to complain about being forced onto Clang. Greg Kroah-Hartman added that it will take months or years to learn about anyone who has problems with the Rust version of the driver, given how slowly Android vendors update their kernels. Furthermore, the removal is a single patch that can be cleanly reverted, if someone needs to continue using the C version.

Llamas thought that it was worth considering what the removal process should look like for other code that gets ported to Rust. He asked what people thought should happen to the C version of converted drivers on long-term-support branches. Ojeda said that the process would be exactly the same as the existing policy for replaced C code. The only difference between Rust and C in long-term-support releases is that the Rust maintainers backport fixes for soundness problems, he said. Kroah-Hartman told Llamas not to worry about code that has been replaced: "Just delete it. I take patches for subsystems that have been deleted. It's fine."

With that declaration, the session, the conference, and the presence of the C Binder driver in the kernel were all over. Binder is the first nontrivial component in the kernel to be ported to Rust, and its journey has revealed several pitfalls that don't apply to new drivers written in Rust from scratch. Still, the most difficult problems were not Rust-specific; they were the compatibility problems that any rewrite would face. Whether any other kernel components will find the hassle of a rewrite worth it, and how long they will take to accomplish it, remains to be seen.

[ Thanks to the Linux Foundation, LWN's travel sponsor, for supporting my travel to Kangrejos. ]

Index entries for this article
ConferenceKangrejos/2026

GCC for C and LLVM for Rust

Posted Nov 2, 2026 1:39 UTC (Mon) by mathstuf (subscriber, #69389) [Link] (1 responses)

Aren't there codegen-affecting flags like CFI and such that are build options in the kernel? I imagine that needs compiler internal logic to match…

GCC for C and LLVM for Rust

Posted Nov 2, 2026 2:15 UTC (Mon) by intelfx (subscriber, #130118) [Link]

Aren't there codegen-affecting flags like CFI and such that are build options in the kernel? I imagine that needs compiler internal logic to match…

Codegen-affecting, yes, but are they ABI-affecting?

CFI is probably relaxed around anything that looks like an global-visibility symbol. What are other codegen-affecting options that involve nontrivial internal logic?

Hello Google?

Posted Oct 30, 2026 20:29 UTC (Fri) by jepsis (subscriber, #130218) [Link] (6 responses)

Hello Google?

Posted Oct 30, 2026 22:01 UTC (Fri) by rahulsundaram (subscriber, #21946) [Link] (2 responses)

Other distributions like RHEL and SLES don't either. Is there a particular reason to single out Google here?

Hello Google?

Posted Oct 30, 2026 22:25 UTC (Fri) by pbonzini (subscriber, #60935) [Link] (1 responses)

Hello Google?

Posted Nov 7, 2026 7:38 UTC (Sat) by anton (subscriber, #25547) [Link]

I just bought a Samsung A27 (not a flagship), and Samsung promises 6 OS upgrades and 6 years of security updates. In this case (and probably others) the clock starts to run when a smartphone model appears globally, so it certainly is a good idea to look at the release year when comparing the update promises of different smart phones.

If I search for 6 years of security updates, my favourite price comparison site lists smartphones from CMF, Honor, Motorola, Nothing, OnePlus, Oppo, Realme, Samsung, Sony, TCL, and Xiaomi, so it's not just Samsung flagships. If you ask for 7 years instead, you get a different set of manufacturers (including Google); for 8 years, you get Fairphone. No one promises 9 or 10 years of security updates.

Hello Google?

Posted Oct 30, 2026 23:06 UTC (Fri) by eean (subscriber, #50420) [Link]

Hello Google?

Posted Oct 31, 2026 12:58 UTC (Sat) by willy (subscriber, #9762) [Link] (1 responses)

Hello Google?

Posted Nov 2, 2026 17:13 UTC (Mon) by pbonzini (subscriber, #60935) [Link]

I previously had a Moto G100, gifted one year after it was released; it only had one more major Android release update, and security fixes (which were already dripping at glacial pace) probably have finished too by now...

The text above was extracted automatically from the source page and may miss images, tables or code blocks. The original is authoritative.

Published by Lobsters
This site only summarises and aggregates; copyright stays with the original author. Headlines and summaries follow the source — where they differ, the original wins.
Read the original ↗