Rust and UB
Rust and UB
Posted Aug 15, 2024 6:33 UTC (Thu) by ralfj (subscriber, #172874)In reply to: Rust and UB by pbonzini
Parent article: Standards for use of unsafe Rust in the kernel
Cross-process (or "cross-privilege-boundary") atomics are a nasty case, but roughly speaking the way they can be implemented without having UB (even in theory) is to ensure that "your side" always uses atomic accesses. If the other process uses non-atomics to access the same memory, then there is UB, but the UB is limited to the other process. When this occurs between kernel and userspace, process isolation ensures that UB in userspace cannot "taint" the kernel, so it's fine.
But this is not an example of "causing UB and getting away with it".
(For Linux specifically, things are more complicated because Rust uses the C++ memory model but Linux implements its own concurrency model, the LKMM. That one *is* technically UB in Rust, just like it is technically UB in C. But this has nothing to do with having synchronization span kernel and userspace.)
