• Jiri Slaby's avatar
    x86/syscall: Sanitize syscall table de-references under speculation fix · 5fed0b35
    Jiri Slaby authored
    In 4.4.118, we have commit c8961332 (x86/syscall: Sanitize syscall
    table de-references under speculation), which is a backport of upstream
    commit 2fbd7af5. But it fixed only the C part of the upstream patch
    -- the IA32 sysentry. So it ommitted completely the assembly part -- the
    64bit sysentry.
    
    Fix that in this patch by explicit array_index_mask_nospec written in
    assembly. The same was used in lib/getuser.S.
    
    However, to have "sbb" working properly, we have to switch from "cmp"
    against (NR_syscalls-1) to (NR_syscalls), otherwise the last syscall
    number would be "and"ed by 0. It is because the original "ja" relies on
    "CF" or "ZF", but we rely only on "CF" in "sbb". That means: switch to
    "jae" conditional jump too.
    
    Final note: use rcx for mask as this is exactly what is overwritten by
    the 4th syscall argument (r10) right after.
    Reported-by: default avatarJan Beulich <JBeulich@suse.com>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Dan Williams <dan.j.williams@intel.com>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: linux-arch@vger.kernel.org
    Cc: kernel-hardening@lists.openwall.com
    Cc: gregkh@linuxfoundation.org
    Cc: Andy Lutomirski <luto@kernel.org>
    Cc: alan@linux.intel.com
    Cc: Jinpu Wang <jinpu.wang@profitbricks.com>
    Signed-off-by: default avatarJiri Slaby <jslaby@suse.cz>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    5fed0b35
entry_64.S 46.1 KB