* Re: [PATCH v2 0/5] Usermode Indirect Branch Tracking [not found] <20260605184715.3383415-2-ripatel@wii.dev> @ 2026-06-05 19:34 ` Florian Weimer 2026-06-05 20:32 ` Richard Patel 0 siblings, 1 reply; 3+ messages in thread From: Florian Weimer @ 2026-06-05 19:34 UTC (permalink / raw) To: Richard Patel Cc: x86, H. Peter Anvin, Peter Zijlstra, Rick Edgecombe, Yu-cheng Yu, Dave Hansen, Thomas Gleixner, Ingo Molnar, Borislav Petkov, David Laight, Andy Lutomirski, Kees Cook, Shuah Khan, linux-kselftest, linux-kernel, libc-alpha, linux-api, Arjun Shankar * Richard Patel: > Adds basic support for x86 userspace IBT. > > IBT is part of Intel CET. It requires indirect call and jump targets > to start with an endbr{32,64} instruction, otherwise throwing #CP. > > In summary, this patch does 3 things: > - Config wiring ensuring supervisor XSAVE contains IBT state > - Allow userspace to enable IBT via prctl(PR_CFI_*) for an entire thread > - Enable IBT support (ENDBR instructions) in VDSO > > Unlike the arm64 BTI API: > - does not support mixed usermode (all or nothing) > - does not touch page table code > - not enabled automatically (no ELF GNU note parsing) > - temporarily disables IBT enforcement when handling signals > These can all be cleanly added later. Adding the ELF GNU note parsing can be added later, but perhaps not cleanly. I'm still a bit worried we might have to rev the markup because too many binaries are in circulation that claim compatibility, have never been tested, and are actually broken. If the kernel does not look at the ELF bits, things a slightly simpler. How do you detect that handling a signal is complete and IBT can be re-enabled? Or is it re-enabled before entering the userspace signal handler? > The main question is whether glibc is happy with this prctl syscall API. As far as I can tell, the prctl works for glibc. Re-use of an arch_prctl constant might have been problematic, but the series is not doing that. > There is one notable gap in this patch series, to do with signals: > > 000a: mov rax, 0x100a > 000f: jmp rax > *** signal occurs *** > *** signal handler runs, does sigreturn *** > 100a: nop > > The above sequence does not crash. > > With IBT, it should crash at the nop (because an endr64 is expected there). > The IBT state (WAIT_FOR_ENDBR in IA32_U_CET MSR) is not backed up to the > signal frame though. So, when userland does a sigreturn, the CPU has > forgotten that it was doing an indirect branch before the signal. > (This specifically only occurs with signal handlers that sigreturn.) > > This is because IA32_U_CET is part of XSAVE 'supervisor' state, so > regular XSAVE/XRSTOR can't access it. Doing a manual backup is tricky. That's a bit annoying. Is this restricted to signal handlers, or does it apply to page faults, too? > A related problem is that the signal handler routine is not checked for > endbr preamble. That's not necessarily a problem because its address cannot be directly overwritten in userspace. Not all indirect branches need to be checked, only those that have tweakable targets. In fact, fewer ENDBR64 markers are better (although we wouldn't drop the marker from a signal handler specifically, of course). Thanks, Florian ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2 0/5] Usermode Indirect Branch Tracking 2026-06-05 19:34 ` [PATCH v2 0/5] Usermode Indirect Branch Tracking Florian Weimer @ 2026-06-05 20:32 ` Richard Patel 2026-06-06 13:40 ` Florian Weimer 0 siblings, 1 reply; 3+ messages in thread From: Richard Patel @ 2026-06-05 20:32 UTC (permalink / raw) To: Florian Weimer Cc: x86, H. Peter Anvin, Peter Zijlstra, Rick Edgecombe, Yu-cheng Yu, Dave Hansen, Thomas Gleixner, Ingo Molnar, Borislav Petkov, David Laight, Andy Lutomirski, Kees Cook, Shuah Khan, linux-kselftest, linux-kernel, libc-alpha, linux-api, Arjun Shankar On Fri, Jun 05, 2026 at 09:34:46PM +0200, Florian Weimer wrote: > How do you detect that handling a signal is complete and IBT can be > re-enabled? Or is it re-enabled before entering the userspace signal > handler? Hi Florian, In v1, we backed up the IBT CPU state into the (user-accessible) signal frame from FRED/XSAVE, then restored it: https://lore.kernel.org/lkml/20260517183024.16292-4-ripatel@wii.dev/ In v2, when entering the signal handler, the kernel just context switches to the new user rip, bypassing IBT checks (continues executing if the signal handler does not begin with endbr). IBT stays enabled in both designs, just the IBT state is preserved in v1, and lost in v2. The same thing happens when doing a sigreturn in v2 (e.g. via trampoline), again IBT is not enforced. IBT stays enabled when doing a siglongjmp, though. Some time in the future, ideally: - signal handler is *required* to start with endbr (this is easy) - sigreturn as in my asm example enforces endbr after returning from a signal handler to a in-progres indirect branc - libc (sig)longjmp is made IBT-compatible Btw, I had self-tests for the v1 design, and {signal handle,rt_sigreturn, siglongjmp} with {success case,violation} works flawlessly with Fedora 44 glibc amd64. With glibc i686 I ran into PLT issues, probably my fault. It is quite surprised that siglongjmp was working, btw, since the glibc longjmp code uses 'jmp *reg' (without notrack prefix). I guess you do an endbr64 at the setjmp side? > > The main question is whether glibc is happy with this prctl syscall API. > > As far as I can tell, the prctl works for glibc. Re-use of an > arch_prctl constant might have been problematic, but the series is not > doing that. Nice :-) The alternative would have been to bolt on stuff to ARCH_SHSTK, or create an entirely new arch_prctl. Open to any API. > Adding the ELF GNU note parsing can be added later, but perhaps not > cleanly. I'm still a bit worried we might have to rev the markup > because too many binaries are in circulation that claim compatibility, > have never been tested, and are actually broken. If the kernel does not > look at the ELF bits, things a slightly simpler. Phew, I was hoping you'd say that. If you want, I can sketch out glibc IBT enabling and test it on Debian and Fedora, which IIRC already emit compile with -fcf-protection=branch for all OS packages. > > There is one notable gap in this patch series, to do with signals: > > > > 000a: mov rax, 0x100a > > 000f: jmp rax > > *** signal occurs *** > > *** signal handler runs, does sigreturn *** > > 100a: nop > > > > The above sequence does not crash. > > > > With IBT, it should crash at the nop (because an endr64 is expected there). > > The IBT state (WAIT_FOR_ENDBR in IA32_U_CET MSR) is not backed up to the > > signal frame though. So, when userland does a sigreturn, the CPU has > > forgotten that it was doing an indirect branch before the signal. > > (This specifically only occurs with signal handlers that sigreturn.) > > > > This is because IA32_U_CET is part of XSAVE 'supervisor' state, so > > regular XSAVE/XRSTOR can't access it. Doing a manual backup is tricky. > > That's a bit annoying. Is this restricted to signal handlers, or does > it apply to page faults, too? Only signal handlers, page faults don't reset IBT. > > A related problem is that the signal handler routine is not checked for > > endbr preamble. > > That's not necessarily a problem because its address cannot be directly > overwritten in userspace. Not all indirect branches need to be checked, > only those that have tweakable targets. In fact, fewer ENDBR64 markers > are better (although we wouldn't drop the marker from a signal handler > specifically, of course). Just one concern I have is that people start relying on signal handlers not requiring endbr64, and then a future kernel version breaking them once we enforce it. Really appreciate your review, -Richard ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2 0/5] Usermode Indirect Branch Tracking 2026-06-05 20:32 ` Richard Patel @ 2026-06-06 13:40 ` Florian Weimer 0 siblings, 0 replies; 3+ messages in thread From: Florian Weimer @ 2026-06-06 13:40 UTC (permalink / raw) To: Richard Patel Cc: x86, H. Peter Anvin, Peter Zijlstra, Rick Edgecombe, Yu-cheng Yu, Dave Hansen, Thomas Gleixner, Ingo Molnar, Borislav Petkov, David Laight, Andy Lutomirski, Kees Cook, Shuah Khan, linux-kselftest, linux-kernel, libc-alpha, linux-api, Arjun Shankar * Richard Patel: > On Fri, Jun 05, 2026 at 09:34:46PM +0200, Florian Weimer wrote: > >> How do you detect that handling a signal is complete and IBT can be >> re-enabled? Or is it re-enabled before entering the userspace signal >> handler? > > Hi Florian, > > In v1, we backed up the IBT CPU state into the (user-accessible) signal > frame from FRED/XSAVE, then restored it: > https://lore.kernel.org/lkml/20260517183024.16292-4-ripatel@wii.dev/ > > In v2, when entering the signal handler, the kernel just context switches > to the new user rip, bypassing IBT checks (continues executing if the > signal handler does not begin with endbr). What's the reason for this? > Some time in the future, ideally: > - signal handler is *required* to start with endbr (this is easy) > - sigreturn as in my asm example enforces endbr after returning from a > signal handler to a in-progres indirect branc > - libc (sig)longjmp is made IBT-compatible I think the compiler already emits ENDBR markers for returns-twice functions, which is why longjmp does not use a no-track jump. Other architectures require such a proliferation of markers because they do not support no-track jumps at all. However, longjmp is arguable a corner case. It's not completely safe, like loading a function address from a RELRO GOT and jumping to it. > Btw, I had self-tests for the v1 design, and {signal handle,rt_sigreturn, > siglongjmp} with {success case,violation} works flawlessly with Fedora 44 > glibc amd64. With glibc i686 I ran into PLT issues, probably my fault. There's no IBT support planned for i686, that's why we dropped all marker instructions in Fedora. > It is quite surprised that siglongjmp was working, btw, since the glibc > longjmp code uses 'jmp *reg' (without notrack prefix). I guess you do an > endbr64 at the setjmp side? Yes, compilers generate landing pads for returns-twice functions. Not ideal, but it's the only way to get setjmp working on targets without NOTRACK. >> Adding the ELF GNU note parsing can be added later, but perhaps not >> cleanly. I'm still a bit worried we might have to rev the markup >> because too many binaries are in circulation that claim compatibility, >> have never been tested, and are actually broken. If the kernel does not >> look at the ELF bits, things a slightly simpler. > > Phew, I was hoping you'd say that. > > If you want, I can sketch out glibc IBT enabling and test it on Debian > and Fedora, which IIRC already emit compile with -fcf-protection=branch > for all OS packages. For Fedora, please coordinate with Arjun (Cc:ed), who is going through the motions of enabling SHSTK for real. >> That's not necessarily a problem because its address cannot be directly >> overwritten in userspace. Not all indirect branches need to be checked, >> only those that have tweakable targets. In fact, fewer ENDBR64 markers >> are better (although we wouldn't drop the marker from a signal handler >> specifically, of course). > > Just one concern I have is that people start relying on signal handlers > not requiring endbr64, and then a future kernel version breaking them once > we enforce it. Would software enforcement be a possibility? The kernel could check if the landing pad is there. Thanks, Florian ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-06-06 13:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20260605184715.3383415-2-ripatel@wii.dev>
2026-06-05 19:34 ` [PATCH v2 0/5] Usermode Indirect Branch Tracking Florian Weimer
2026-06-05 20:32 ` Richard Patel
2026-06-06 13:40 ` Florian Weimer
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox