All of lore.kernel.org
 help / color / mirror / Atom feed
* [BUG] kprobes crashing because of preempt count
@ 2011-06-30 13:23 Steven Rostedt
  2011-06-30 15:51 ` [RFC][PATCH] kprobes: Add separate preempt_disabling for kprobes Steven Rostedt
  2011-07-01  1:12 ` [BUG] kprobes crashing because of preempt count Masami Hiramatsu
  0 siblings, 2 replies; 27+ messages in thread
From: Steven Rostedt @ 2011-06-30 13:23 UTC (permalink / raw)
  To: LKML
  Cc: Masami Hiramatsu, Peter Zijlstra, Frederic Weisbecker,
	Thomas Gleixner, Ingo Molnar

Hi Masami,

While testing some changes in -rt against kprobes, I hit a crash that
exists in mainline. If we stick a probe in a location that reads
preempt_count, we corrupt the kernel itself.

Reason is that the kprobe single step handler disables preemption, sets
up the single step, returns to the code to execute that single step,
takes the trap, enables preemption, and continues.

The issue, is because we disabled preemption in the trap, returned, then
enabled it again in another trap, we just changed what the code sees
that does that single step.

If we add a kprobe on a inc_preempt_count() call:

	[ preempt_count = 0 ]

	ld preempt_count, %eax	<<--- trap

		<trap>
		preempt_disable();
		[ preempt_count = 1]
		setup_singlestep();
		<trap return>

	[ preempt_count = 1 ]

	ld preempt_count, %eax

	[ %eax = 1 ]

		<trap>
		post_kprobe_handler()
			preempt_enable_no_resched();
			[ preempt_count = 0 ]
		<trap return>

	[ %eax = 1 ]

	add %eax,1

	[ %eax = 2 ]

	st %eax, preempt_count

	[ preempt_count = 2 ]


We just caused preempt count to increment twice when it should have only
incremented once, and this screws everything else up.

Do we really need to have preemption disabled throughout this? Is it
because we don't want to migrate or call schedule? Not sure what the
best way to fix this is. Perhaps we add a kprobe_preempt_disable() that
is checked as well?

-- Steve



^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2011-07-03  2:05 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-30 13:23 [BUG] kprobes crashing because of preempt count Steven Rostedt
2011-06-30 15:51 ` [RFC][PATCH] kprobes: Add separate preempt_disabling for kprobes Steven Rostedt
2011-06-30 16:14   ` Frederic Weisbecker
2011-06-30 16:46     ` Steven Rostedt
2011-06-30 19:40   ` Jason Baron
2011-06-30 19:42     ` Steven Rostedt
2011-06-30 21:56   ` Peter Zijlstra
2011-07-01  1:22     ` Masami Hiramatsu
2011-07-01  1:38       ` Steven Rostedt
2011-07-01  1:52         ` Masami Hiramatsu
2011-07-01  5:09   ` Masami Hiramatsu
2011-07-01 11:13     ` Masami Hiramatsu
2011-07-01 12:54       ` Steven Rostedt
2011-07-01 12:19     ` Steven Rostedt
2011-07-01 13:15       ` Masami Hiramatsu
2011-07-01 13:14         ` [RFC PATCH -tip ] [BUGFIX] x86: Remove preempt disabling from kprobes Masami Hiramatsu
2011-07-01 13:43           ` Steven Rostedt
2011-07-01 13:53             ` Steven Rostedt
2011-07-03  2:05               ` Masami Hiramatsu
2011-07-02  6:09           ` Ananth N Mavinakayanahalli
2011-07-01  1:12 ` [BUG] kprobes crashing because of preempt count Masami Hiramatsu
2011-07-01  1:33   ` Steven Rostedt
2011-07-01  2:23     ` Masami Hiramatsu
2011-07-01 11:36   ` Ananth N Mavinakayanahalli
2011-07-01 12:01     ` Masami Hiramatsu
2011-07-01 13:03       ` Ananth N Mavinakayanahalli
2011-07-01 13:19         ` Steven Rostedt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.