Re: [PATCH -tip ] [BUGFIX] kprobes: Skip kretprobe hit in NMI context to avoid deadlock
From: Ingo Molnar
Date: Fri Aug 01 2014 - 07:00:40 EST
* Masami Hiramatsu <masami.hiramatsu.pt@xxxxxxxxxxx> wrote:
> Skip kretprobe hit in NMI context, because if an NMI happens
> inside the critical section protected by kretprobe_table.lock
> and another(or same) kretprobe hit, pre_kretprobe_handler
> tries to lock kretprobe_table.lock again.
> Normal interrupts have no problem because they are disabled
> with the lock.
>
> Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@xxxxxxxxxxx>
> Cc: Ananth N Mavinakayanahalli <ananth@xxxxxxxxxx>
> Cc: "David S. Miller" <davem@xxxxxxxxxxxxx>
> ---
> kernel/kprobes.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index 734e9a7..a537029 100644
> --- a/kernel/kprobes.c
> +++ b/kernel/kprobes.c
> @@ -1778,6 +1778,12 @@ static int pre_handler_kretprobe(struct kprobe *p, struct pt_regs *regs)
> unsigned long hash, flags = 0;
> struct kretprobe_instance *ri;
>
> + /* To avoid deadlock, prohibit return probing in NMI context */
> + if (in_nmi()) {
Should be unlikely()?
> + rp->nmissed++;
> + return 0;
In another place in this function we do:
} else {
rp->nmissed++;
raw_spin_unlock_irqrestore(&rp->lock, flags);
}
Is it safe to modify rp-> without locking?
> + }
> +
> /*TODO: consider to only swap the RA after the last pre_handler fired */
Nit: That comment is oddly formatted.
Thanks,
Ingo
--
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/