• Hugh Dickins's avatar
    kaiser: paranoid_entry pass cr3 need to paranoid_exit · fc8334e6
    Hugh Dickins authored
    
    Neel Natu points out that paranoid_entry() was wrong to assume that
    an entry that did not need swapgs would not need SWITCH_KERNEL_CR3:
    paranoid_entry (used for debug breakpoint, int3, double fault or MCE;
    though I think it's only the MCE case that is cause for concern here)
    can break in at an awkward time, between cr3 switch and swapgs, but
    its handling always needs kernel gs and kernel cr3.
    
    Easy to fix in itself, but paranoid_entry() also needs to convey to
    paranoid_exit() (and my reading of macro idtentry says paranoid_entry
    and paranoid_exit are always paired) how to restore the prior state.
    The swapgs state is already conveyed by %ebx (0 or 1), so extend that
    also to convey when SWITCH_USER_CR3 will be needed (2 or 3).
    
    (Yes, I'd much prefer that 0 meant no swapgs, whereas it's the other
    way round: and a convention shared with error_entry() and error_exit(),
    which I don't want to touch.  Perhaps I should have inverted the bit
    for switch cr3 too, but did not.)
    
    paranoid_exit() would be straightforward, except for TRACE_IRQS: it
    did TRACE_IRQS_IRETQ when doing swapgs, but TRACE_IRQS_IRETQ_DEBUG
    when not: which is it supposed to use when SWITCH_USER_CR3 is split
    apart from that?  As best as I can determine, commit 5963e317
    ("ftrace/x86: Do not change stacks in DEBUG when calling lockdep")
    missed the swapgs case, and should have used TRACE_IRQS_IRETQ_DEBUG
    there too (the discrepancy has nothing to do with the liberal use
    of _NO_STACK and _UNSAFE_STACK hereabouts: TRACE_IRQS_OFF_DEBUG has
    just been used in all cases); discrepancy lovingly preserved across
    several paranoid_exit() cleanups, but I'm now removing it.
    
    Neel further indicates that to use SWITCH_USER_CR3_NO_STACK there in
    paranoid_exit() is now not only unnecessary but unsafe: might corrupt
    syscall entry's unsafe_stack_register_backup of %rax.  Just use
    SWITCH_USER_CR3: and delete SWITCH_USER_CR3_NO_STACK altogether,
    before we make the mistake of using it again.
    
    hughd adds: this commit fixes an issue in the Kaiser-without-PCIDs
    part of the series, and ought to be moved earlier, if you decided
    to make a release of Kaiser-without-PCIDs.
    Signed-off-by: default avatarHugh Dickins <hughd@google.com>
    Acked-by: default avatarJiri Kosina <jkosina@suse.cz>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    fc8334e6
kaiser.h 3.73 KB