Use the known valid segment when accessing memory in #UD handler.

Make sure that %eflags.D flag is cleared for hook.
Improve comments.

When #UD dtrace code checks for a registered hook before checking that
the exception was raised from kernel mode, we might run with the user
%ds, trapping on access.  Exception entry from userspace automatically
load valid %ss, which we can use there instead.

Noted and reviewed by:	bde
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
This commit is contained in:
kib 2017-08-19 21:00:02 +00:00
parent fce552fb16
commit 03221989ce

View File

@ -183,12 +183,16 @@ calltrap:
#ifdef KDTRACE_HOOKS
SUPERALIGN_TEXT
IDTVEC(ill)
/* Check if there is no DTrace hook registered. */
cmpl $0,dtrace_invop_jump_addr
/*
* Check if a DTrace hook is registered. The default (data) segment
* cannot be used for this since %ds is not known good until we
* verify that the entry was from kernel mode.
*/
cmpl $0,%ss:dtrace_invop_jump_addr
je norm_ill
/*
* Check if this is a user fault. If so, just handle it as a normal
* Check if this is a user fault. If so, just handle it as a normal
* trap.
*/
cmpl $GSEL_KPL, 4(%esp) /* Check the code segment */
@ -200,7 +204,8 @@ IDTVEC(ill)
* This is a kernel instruction fault that might have been caused
* by a DTrace provider.
*/
pushal /* Push all registers onto the stack. */
pushal
cld
/*
* Set our jump address for the jump back in the event that