4 ms·
(Kernel person here. I have nothing to do with Ubuntu or gcc, but I can maybe help fix the problem.) It would be great if this came with an explanation of what
by amluto 6y ago
(Kernel person here. I have nothing to do with Ubuntu or gcc, but I can maybe help fix the problem.) It would be great if this came with an explanation of what broke. CET should not break setjmp.
- mlyle 6y agoI'd imagine the problem is that iPXE is preboot firmware, so the emitted setjmp/longjmp builtins assume a shadow stack that's set up, etc. Ubuntu should not enable the flag when -ffreestanding is set.
- amluto 6y agoI'm not sure what causes gcc to emit the builtin setjmp/longjmp, but I tried compiling this: #include <setjmp.h> void __attribute__((noinline)) test(jmp_buf buf) { __builtin_longjmp(buf, 1); } int main() { jmp_buf buf; if (__builtin_setjmp(buf) == 0) test(buf); return 0; } and ran it on a non-CET machine. It works fine. It does contain a CET fixup, but that CET fixup is smart enough to work regardless of whether CET is enabled. However, gcc does generate non-working code if the setjmp and the longjmp are in different files and only one is compiled with -fcf-protection=full. Ouch. I'll file a bug. edit: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98997 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98997
- mlyle 6y agoThe issue isn't a non-CET machine. The CET becomes NOPs on non-CET machines. The issue is expecting it to work in a freestanding environment.
- amluto 6y agoIt ought to work in a freestanding environment. If it doesn’t, then it’s IMO a gcc bug. I found a GCC bug which may or may not be the ipxe issue. Are you seeing another failure in a freestanding environment? If so, I don’t suppose you either have a reproducer or can point at a problem in the generated code?
- mlyle 6y agoI don't know any specifics. It was my understanding, though, that you needed to be careful mixing CET-aware code and non-CET aware code. Is this wrong? Can you call into the BIOS, EFI drivers, and have interrupt handlers and not worry about any of this at all? It really should be OK freestanding without any additional CET-specific initialization code support and mixed with non-CET code? If so, I stand corrected. (But then, what's all this machinery for marking code that doesn't use endbranch in glibc, ld.so, the kernel, etc, and the legacy code page bitmap for?)
- amluto 6y agoI would say that the issue isn't really mixing CET-aware and non-CET-aware code. The issue is using non-CET-aware code with CET enabled. If you have code that plays games with mismatched CALL and RET or with rewriting the stack (which includes retpolines and possibly 32-bit PIC code), then SHSTK will make it crash. And if you have code that takes pointers to non-IBT functions, then you will crash unless you set up the legacy bitmap. But all of this is moot unless something turns CET on. The actual semantics of when the combination of gcc, ld, and glibc will try to turn CET on are not documented, as far as I can tell. And, to be fair, as my bug report shows, there can also be issues if something has a different ABI when compiled with and without CET enabled. This shouldn't happen, but apparently it did.
- mlyle 6y ago> The actual semantics of when the combination of gcc, ld, and glibc will try to turn CET on are not documented, as far as I can tell. Yes. And a complicating thing is here there's no loader or normal initialization code, because PXE is freestanding and invoked directly by the BIOS/EFI. CET is -probably- off... And yes, are there any dependencies between the init code changes and GCC enabling CET and GCC builtins?
- amluto 6y agoAny CET init code ought to be confined to glibc and/or the kernel or whatever code is untimely loading your program. I hope glibc isn’t involved in iPXE :). CET had better be off for UEFI programs when they’re loaded unless that program has a special header, based on spec that I doubt exists, telling the loader to enable CET.