From: Daniel Thompson <daniel.thompson@linaro.org>
To: Jason Wessel <jason.wessel@windriver.com>,
Douglas Anderson <dianders@chromium.org>
Cc: Daniel Thompson <daniel.thompson@linaro.org>,
Peter Zijlstra <peterz@infradead.org>,
sumit.garg@linaro.org, pmladek@suse.com,
sergey.senozhatsky@gmail.com, will@kernel.org,
kgdb-bugreport@lists.sourceforge.net,
linux-kernel@vger.kernel.org, patches@linaro.org
Subject: [RFC PATCH 1/4] kgdb: Honour the kprobe blacklist when setting breakpoints
Date: Fri, 5 Jun 2020 14:21:27 +0100 [thread overview]
Message-ID: <20200605132130.1411255-2-daniel.thompson@linaro.org> (raw)
In-Reply-To: <20200605132130.1411255-1-daniel.thompson@linaro.org>
Currently kgdb has absolutely no safety rails in place to discourage or
prevent a user from placing a breakpoint in dangerous places such as
the debugger's own trap entry/exit and other places where it is not safe
to take synchronous traps.
Modify the default implementation of kgdb_validate_break_address() so
that we honour the kprobe blacklist (if there is one). The resulting
blacklist will include code that kgdb could, in fact, debug but I think
we can assume that anyone with sufficient knowledge to meaningfully
debug that code would trivially be able to find and remove the safety
rail if they need to.
Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org>
---
kernel/debug/debug_core.c | 11 +++++++++++
kernel/debug/kdb/kdb_bp.c | 9 +++++++++
2 files changed, 20 insertions(+)
diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
index ef94e906f05a..81f56d616e04 100644
--- a/kernel/debug/debug_core.c
+++ b/kernel/debug/debug_core.c
@@ -56,6 +56,7 @@
#include <linux/vmacache.h>
#include <linux/rcupdate.h>
#include <linux/irq.h>
+#include <linux/kprobes.h>
#include <asm/cacheflush.h>
#include <asm/byteorder.h>
@@ -188,6 +189,16 @@ int __weak kgdb_validate_break_address(unsigned long addr)
{
struct kgdb_bkpt tmp;
int err;
+
+ /*
+ * Disallow breakpoints that are marked as unsuitable for kprobing.
+ * This check is a little over-zealous because it does include
+ * code that kgdb is entirely capable of debugging but in exchange
+ * we can avoid recursive trapping (and all the problems that brings).
+ */
+ if (within_kprobe_blacklist(addr))
+ return -EINVAL;
+
/* Validate setting the breakpoint and then removing it. If the
* remove fails, the kernel needs to emit a bad message because we
* are deep trouble not being able to put things back the way we
diff --git a/kernel/debug/kdb/kdb_bp.c b/kernel/debug/kdb/kdb_bp.c
index d7ebb2c79cb8..ec4940146612 100644
--- a/kernel/debug/kdb/kdb_bp.c
+++ b/kernel/debug/kdb/kdb_bp.c
@@ -306,6 +306,15 @@ static int kdb_bp(int argc, const char **argv)
if (!template.bp_addr)
return KDB_BADINT;
+ /*
+ * This check is redundant (since the breakpoint machinery should
+ * be doing the same check during kdb_bp_install) but gives the
+ * user immediate feedback.
+ */
+ diag = kgdb_validate_break_address(template.bp_addr);
+ if (diag)
+ return diag;
+
/*
* Find an empty bp structure to allocate
*/
--
2.25.4
next prev parent reply other threads:[~2020-06-05 13:22 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-05 13:21 [RFC PATCH 0/4] kgdb: Honour the kprobe blacklist when setting breakpoints Daniel Thompson
2020-06-05 13:21 ` Daniel Thompson [this message]
2020-06-05 13:21 ` [RFC PATCH 2/4] kgdb: Use the kprobe blacklist to limit single stepping Daniel Thompson
2020-06-05 13:21 ` [RFC PATCH 3/4] kgdb: Add NOKPROBE labels on the trap handler functions Daniel Thompson
2020-06-11 12:43 ` Masami Hiramatsu
2020-06-05 13:21 ` [RFC PATCH 4/4] kprobes: Allow the kprobes blacklist to be compiled independently Daniel Thompson
2020-06-05 14:29 ` [RFC PATCH 0/4] kgdb: Honour the kprobe blacklist when setting breakpoints Peter Zijlstra
2020-06-05 14:44 ` Peter Zijlstra
2020-06-08 13:50 ` Daniel Thompson
2020-06-08 12:43 ` Daniel Thompson
2020-06-11 12:42 ` Masami Hiramatsu
2020-06-11 14:32 ` Daniel Thompson
2020-06-12 10:13 ` Masami Hiramatsu
2020-06-12 11:04 ` Daniel Thompson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200605132130.1411255-2-daniel.thompson@linaro.org \
--to=daniel.thompson@linaro.org \
--cc=dianders@chromium.org \
--cc=jason.wessel@windriver.com \
--cc=kgdb-bugreport@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=patches@linaro.org \
--cc=peterz@infradead.org \
--cc=pmladek@suse.com \
--cc=sergey.senozhatsky@gmail.com \
--cc=sumit.garg@linaro.org \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox