On the correctness of dbe3ed1c078c193be34326728d494c5c4bc115e2

From: H. Peter Anvin
Date: Sun Sep 01 2013 - 08:21:46 EST


A truly ancient commit (v2.6.23), dbe3ed1c078c193be34326728d494c5c4bc115e2:

x86-64: page faults from user mode are always user faults

Randy Dunlap noticed an interesting "crashme" behaviour on his dual
Prescott Xeon setup, where he gets page faults with the error code
having a zero "user" bit, but the register state points back to user
mode.

This may be a CPU microcode buglet triggered by some strange
instruction pattern that crashme generates, and loading a microcode
update seems to possibly have fixed it.

Regardless, we really should trust the register state more than the
error code, since it's really the register state that determines
whether we can actually send a signal, or whether we're in kernel
mode and need to oops/kill the process in the case of a page fault.

... introduced the following code (since slightly modified):

+ /*
+ * User-mode registers count as a user access even for any
+ * potential system fault or CPU buglet.
+ */
+ if (user_mode_vm(regs))
+ error_code |= PF_USER;
+

This has the end result that we treat a user space instruction which
touches a privileged data structure that then page faults (e.g. a
segment load which causes #PF on the GDT) as a user-space fault.

This seems very wrong to me, since such a #PF would indicate a serious
error in the kernel.

If this was a buglet introduced by a specific processor ("Prescott Xeon"
I presume means Nocona) and then even fixed in a patch, I'm concerned
that we are putting the cart before the horse with this change.

I went through the errata sheets for the CPUs of the time, but nothing
jumped out at me as causing this kind of problem, although there is a
mention of a couple of undefined opcodes which ought to #UD being able
to generate a "load to an incorrect address". Kind of a stretch, though.

-hpa
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/