Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932259AbbBZQO1 (ORCPT ); Thu, 26 Feb 2015 11:14:27 -0500 Received: from cantor2.suse.de ([195.135.220.15]:58760 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753685AbbBZQNV (ORCPT ); Thu, 26 Feb 2015 11:13:21 -0500 From: Petr Mladek To: Masami Hiramatsu , "David S. Miller" , Anil S Keshavamurthy , Ananth N Mavinakayanahalli , Frederic Weisbecker Cc: Ingo Molnar , Steven Rostedt , Jiri Kosina , linux-kernel@vger.kernel.org, Petr Mladek Subject: [PATCH 5/7] kprobes: Do not try to disarm already disarmed Kprobe Date: Thu, 26 Feb 2015 17:13:50 +0100 Message-Id: <1424967232-2923-6-git-send-email-pmladek@suse.cz> X-Mailer: git-send-email 1.8.5.6 In-Reply-To: <1424967232-2923-1-git-send-email-pmladek@suse.cz> References: <1424967232-2923-1-git-send-email-pmladek@suse.cz> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2298 Lines: 70 The global kprobes_all_disarmed flag says that all Kprobes are disarmed even when they are marked as enabled. This is properly handled in register_kprobe() but it is ignored in __disable_kprobe(). This problem gets more serious after we started handling errors from disarm_kprobe(). The second disarming fails and we do not longer set KPROBE_FLAG_DISABLED. It might trigger BUG_ON(!kprobe_disarmed(ap)) in __unregister_kprobe_top() even when Kprobes were globally disarmed. Well, kprobe_disarmed(ap) should return false when the global kprobes_all_disarmed flag is set. But let's solve this separately. This patch fixes __disable_kprobe(), so that it does not disarm when the Kprobe is not armed. Note that I reverted the condition "if (kprobe_disabled(p))" and used "goto out" there. It helped to keep the code nesting on a reasonable level. Signed-off-by: Petr Mladek --- kernel/kprobes.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 1fcb19095b43..54bc2a6960b4 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -1594,22 +1594,25 @@ static struct kprobe *__disable_kprobe(struct kprobe *p) if (unlikely(orig_p == NULL)) return ERR_PTR(-EINVAL); - if (!kprobe_disabled(p)) { - /* Disable probe if it is a child probe */ - if (p != orig_p) - p->flags |= KPROBE_FLAG_DISABLED; + if (kprobe_disabled(p)) + goto out; + + /* Disable probe if it is a child probe */ + if (p != orig_p) + p->flags |= KPROBE_FLAG_DISABLED; - /* Try to disarm and disable this/parent probe */ - if (p == orig_p || aggr_kprobe_disabled(orig_p)) { + /* Try to disarm and disable this/parent probe */ + if (p == orig_p || aggr_kprobe_disabled(orig_p)) { + if (!kprobes_all_disarmed) { err = disarm_kprobe(orig_p, true); if (err) { p->flags &= ~KPROBE_FLAG_DISABLED; return ERR_PTR(err); } - orig_p->flags |= KPROBE_FLAG_DISABLED; } + orig_p->flags |= KPROBE_FLAG_DISABLED; } - +out: return orig_p; } -- 1.8.5.6 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/