]> git.baikalelectronics.ru Git - kernel.git/commit
x86/entry/64: Prevent clobbering of saved CR2 value
authorThomas Gleixner <tglx@linutronix.de>
Sat, 20 Jul 2019 08:56:41 +0000 (10:56 +0200)
committerThomas Gleixner <tglx@linutronix.de>
Sat, 20 Jul 2019 12:28:41 +0000 (14:28 +0200)
commitef69b547e39d78962b20a7db213539f6c889dd71
tree10b6187c53250f34e55a4a0ec146eea7d852bf98
parent8e5ac7aa41a344021a42ebee6d8e0629f3a84105
x86/entry/64: Prevent clobbering of saved CR2 value

The recent fix for CR2 corruption introduced a new way to reliably corrupt
the saved CR2 value.

CR2 is saved early in the entry code in RDX, which is the third argument to
the fault handling functions. But it missed that between saving and
invoking the fault handler enter_from_user_mode() can be called. RDX is a
caller saved register so the invoked function can freely clobber it with
the obvious consequences.

The TRACE_IRQS_OFF call is safe as it calls through the thunk which
preserves RDX, but TRACE_IRQS_OFF_DEBUG is not because it also calls into
C-code outside of the thunk.

Store CR2 in R12 instead which is a callee saved register and move R12 to
RDX just before calling the fault handler.

Fixes: f374b3bf3a3e ("x86/mm, tracing: Fix CR2 corruption")
Reported-by: Sean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/alpine.DEB.2.21.1907201020540.1782@nanos.tec.linutronix.de
arch/x86/entry/entry_64.S