On Thu, Aug 21, 2025 at 10:15:31PM -0700, Kees Cook wrote: > On Thu, Aug 21, 2025 at 06:09:08PM +0000, Qing Zhao wrote: > > > On Aug 21, 2025, at 10:25, Peter Zijlstra <pet...@infradead.org> wrote:
> > > kCFI changes every function to have a preamble like (with IBT and > > > retpolines and all the modern crap on): > > > > Does “every function” mean all the function in the compilation? Not only > > the function whose address is taken? > > I tried to explain the specific logic on how the set of functions getting > preambles is chosen in this other reply: > https://lore.kernel.org/linux-hardening/202508211258.8DEE293@keescook/ > > If that didn't answer your question, let me know and I'll try again. :) One detail that might be interesting is that ENDBR and the __cfi_\func preamble should be the same condition. The way these features are exposed doesn't make this obvious. And in fact, marking an address taken function with __noendbr will result in a function that has a __cfi_\func preamble, but no ENDBR (clang-20). And while there is both a __noendbr and __nocfi attribute, they are *VERY* different from one another. Where __noendbr inhibits the emission of ENDBR and basically marks the function as impossible to reach with an indirect call, the __nocfi attribute inhibits the CALL modification. Notably, there is no function attribute to inhibit the __cfi_\func preamble (and I'm arguing __noendbr should have that effect). OTOH a function without __cfi_\func preamble but with ENDBR is 'unsafe', but usable with a __nocfi call (typically reserved for calling external code, like firmware). Anyway, we don't currently have means of expressing this to the compiler (also, I don't care much in this case -- I think we should taint the kernel on EFI calls :-).