Re: [RFC PATCH 04/27] x86/cet: Make kernel shadow stack #CP fatal instead of livelocking
From: David Laight
Date: Fri Dec 04 2026 - 04:53:27 EST
On Thu, 03 Dec 2026 21:47:23 -0800
"Andy Lutomirski" <luto@xxxxxxxxxx> wrote:
> On Thu, Dec 3, 2026, at 7:39 PM, K Prateek Nayak wrote:
> > Hello Andy,
> >
>
> >>> All of these should result in cleanly killing the offending task,
> >>> printing a log, *and still working correctly if it happens multiple
> >>> times*, which means we need to be able to escape from #DF context and
> >>> survive the do_exit experience. Which will be great fun.
> >>>
> >>> Maybe this series already handles all of this. Does it?
> >
> > I'm not sure what the right call is for a #CP in kernel mode - that
> > really means someone has messed up the stack / has redirected regs->ip
> > to redirect execution without relying on the CET aware helpers.
> >
> > Since a return address in kernel has been hijacked, I don't think it
> > can be considered safe to allow program to return to the hijacked
> > address and eventually kill the task on exit to usermode right?
>
> ...
>
>
> > For #CP in kernel mode, I'm not too sure - I'll love to hear more form
> > the folks who have dealt with security aspects if the fault handler
> > should attempt some form of recovery - we can match the return address
> > on stack to that on the shadow stack but the integrity of the stack
> > at that point is questionable.
>
>
> I think a decent heuristic should be to handle it like kernel stack overflow -- don't return per se but instead kill the offending task.
>
> However, we have a bitrot situation here. When I wrote the vmap stack code, I made a point of designing it to recover (so we could get logs!) from a stack overflow that got promoted to a double fault. But I just read the code again and it's clearly broken. I asked my friendly LLM to trace the bitrot, and it found:
>
> commit 0d00449c7a28a1514595630735df383dec606812
> Author: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
> Date: Wed Feb 19 09:46:43 2020 +0100
>
> x86: Replace ist_enter() with nmi_enter()
>
> A few exceptions (like #DB and #BP) can happen at any location in the code,
> this then means that tracers should treat events from these exceptions as
> NMI-like. The interrupted context could be holding locks with interrupts
> disabled for instance.
>
> which caused in_interrupt() to return true in the #DF code, which broke recovery -- we'll kit panic("Fatal exception in interrupt"). And then FRED broke it more because rewind_stack_and_make_dead() never got FRED-ified.
>
> I think we want this to get fixed for CET-SS. CET-SS is new and, if something goes wrong, we're going to want to see the logs. I'm inclined to think that any series that enables CET-SS should actually have the property that a #CP that gets promoted to #DF should successfully kill the task and leave the kernel working (unless locks were held, etc, obviously) and allow the log message to be seen.
>
> Paranoid users can turn this off with kernel.panic_on_oops.
Most distributions end up with panic_on_oops set.
It would be nice if is stood a moderate chance of getting the 'oops' text
into /var/log/messages (or equiv.) before killing the system.
Otherwise oops get pretty hard to diagnose.
David
>
> --Andy
>