On Wed, Dec 6, 2023 at 2:41 PM Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote: > > Anywhoo, the longer a function is, the harder it becomes, since you need > to deal with everything a function does and consider the specuation > window length. So trivial functions like the above that do an immediate > dereference and are (and must be) a valid indirect target (because > EXPORT) are ideal. We discussed this in our weekly meeting, and we would like to ask a few questions: - Could you please describe an example attack that you are thinking of? (i.e. a "full" attack, rather than just Spectre itself). For instance, would it rely on other vulnerabilities? - Is this a kernel rule everybody should follow now? i.e. "no (new?) short, exported symbols that just dereference their pointer args". If so, could this please be documented? Or is it already somewhere? - Are we checking for this in some way already, e.g. via `objtool`? Especially if this is a rule, then it would be nice to have a way to double-check if we are getting rid of (most of) these "dangerous" symbols (or at least not introduce new ones, and not just in Rust but C too). Thanks Peter! > That would be good, but how are you going to do that without duplicating > the horror that is struct task_struct ? As Alice pointed out, `bindgen` "solves" that, but it is nevertheless extra maintenance effort. > Well, I really wish the Rust community would address the C > interoperability in a hurry. Basically make it a requirement for > in-kernel Rust. Yeah, some of us have advocated for more integrated C support within Rust (or within `rustc` at least). > I mean, how hard can it be to have clang parse the C headers and inject > them into the Rust IR as if they're external FFI things. That is what `bindgen` does (it uses Clang as a library), except it does not create Rust IR, it outputs normal Rust code, i.e. similar to C declarations. But note that using Clang does not solve the issue of `#define`s in the general case. That is why we would still need "helpers" like these so that the compiler knows how to expand the macro in a C context, which then can be inlined as LLVM IR or similar (which is what I suspect you were actually thinking about, rather than "Rust IR"?). That "mix the LLVM IRs from Clang and `rustc`" ("local LTO hack") approach is something we have been discussing in the past for performance reasons (i.e. to inline these small C functions that Rust needs, cross-language, even in non-LTO builds). And if it helps to avoid certain attacks around speculation, then even better. So if the LLVM folks do not have any major concerns about it, then I think we should go ahead with that (please see also my reply to comex). GCC is still a question mark, though. Cheers, Miguel