freebsd-skq/sys/cddl/dev/dtrace
Ryan Stone cddcb8b4dc On i386, fbt probes are implemented by writing an invalid opcode over
certain instructions in a function prologue or epilogue.  DTrace has a
hook into the invalid opcode fault handler that checks whether the fault
was due to an probe and if so, runs the DTrace magic.

Upon returning from an invalid opcode fault caused by a probe, DTrace must
emulate the instruction that was replaced with the invalid opcode and then
return control to the instruction following the invalid opcode.

There were a pair of related bugs in the emulation for the leave
instruction.  The leave instruction is used to pop off a stack frame prior
to returning from a function.  The emulation for this instruction must
move the trap frame for the invalid opcode fault down the stack to the
bottom of the stack frame that is being removed, and then execute an iret.

At two points in this process, the emulation code was storing values above
the current value of the stack pointer.  This opened up a window in which
if we were two take an interrupt, the trap frame for the interrupt would
overwrite the values stored on the stack, causing the system to panic
later.

The first bug was that at one point the emulation code saves the new value
for $esp above the current stack pointer value.  The fix is to save this
value instead inside of the original trap frame.  At this point we do
not need the original trap frame so this is safe.

The second bug is that when the emulate code loads $esp from the stack, it
points part-way through the new trap frame instead of at its beginning.
The emulation code adjusts the stack pointer to the correct value
immediately afterwards, but this still leaves a one instruction window in
which an interrupt would corrupt this trap frame.  Fix this by adjusting
the stack frame value before loading it into $esp.

This fixes panics in invop_leave on i386 when using fbt return probes.

Reviewed by:	rpaulo, attilio
MFC after:	1 week
2011-11-10 22:03:35 +00:00
..
amd64 Remove pc_cpumask usage from dtrace MD support 2011-06-28 13:14:39 +00:00
i386 On i386, fbt probes are implemented by writing an invalid opcode over 2011-11-10 22:03:35 +00:00
dtrace_anon.c
dtrace_cddl.h Add more compatibility structure members needed by the upcoming fasttrap 2010-08-22 11:04:43 +00:00
dtrace_clone.c
dtrace_debug.c Define dtrace_cmpset_long in terms of atomic_cmpset_long 2011-10-16 22:18:08 +00:00
dtrace_hacks.c
dtrace_ioctl.c Kernel DTrace support for: 2010-08-22 10:53:32 +00:00
dtrace_load.c Make the /dev/dtrace/helper node have the mode 0660. This allows 2010-09-01 12:08:32 +00:00
dtrace_modevent.c
dtrace_sysctl.c
dtrace_test.c
dtrace_unload.c Destroy the helper device when unloading. 2010-08-22 11:05:37 +00:00
dtrace_vtime.c