3 ms·
Your comment is a non sequitur because this bug involves type punning across a syscall boundary. Neither D nor Rust would solve this kind of problem. Likewise f
by wahern 8y ago
Your comment is a non sequitur because this bug involves type punning across a syscall boundary. Neither D nor Rust would solve this kind of problem. Likewise for a host of IP stack bugs that involve type punning over untrusted type identifiers and length headers.
From a safety perspective you want to either box these derived types or copy the headers into properly typed objects so you don't end up with the complex if-else ladders that plague IP stacks. But the cycles to do this--to recursively construct simple boxed types or copy headers--can quickly add up to more than the cost of copying the entire packet as packets move through the pipeline. Engineers [unfortunately] bend over backwards attempting to achieve zero-copy.
We should be using more type safe techniques, and certainly D and Rust make such techniques more ergonomic. But it's fanciful to think that engineers won't recapitulate the same sins[1]. If it were true we'd all be using seL4 and it wouldn't much matter if a language was "safe".
[1] You can this see kind of recapitulation regularly in "high performance" Java and Rust applications where the same type punning patterns are used, replacing pointers with indices into buffer arenas. Po-tay-to, po-tah-to.
- WalterBright 8y agoIt's true that D allows all sorts of dirty tricks, like punning and unsafe casts, but only in code that is not marked as @safe. @safe code is mechanically checkable to be safe. This has the ergonomic feature of drastically reducing the defect surface, in that it saves my time because with C code I constantly am reviewing the array code for possible overflows, in D I don't have to.
- wahern 8y agoThat argument isn't nearly as persuasive in kernel space as it is in user space. Certainly not when performance and bleeding-edge techniques (orthogonal to or even in opposition to the normal idiomatic patterns newer languages emphasize and optimize) are as emphasized as they are in Linux. How many bespoke hash, tree, and queue data structures exist in the Linux kernel, each with purposeful but complex data and execution flow dependencies unique to their context? Every time someone tries to unify two, one more pops up. Point being, the Linux development model--partly because of the nature of the work, partly because of the particular culture--absolutely defies attempts at drawing lines between safe and unsafe so the latter can be isolated. Code that doesn't heavily rely on unsafe techniques, directly or indirectly, wouldn't normally be in the kernel, anyhow. And particularly in a kernel environment even @safe code can do things that violate or exacerbate assumptions elsewhere in the code (e.g. complex RCU protocols), thus Linus' preference to avoid languages with a lot of implicit machinery or non-obvious execution flow. So it's not like @safe code can simply be removed from the equation.