From: Jianyu Zhan <nasa4836@gmail.com>
To: ananth@in.ibm.com, anil.s.keshavamurthy@intel.com,
davem@davemloft.net, masami.hiramatsu.pt@hitachi.com,
rdunlap@infradead.org
Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
nasa4836@gmail.com
Subject: [PATCH] kprobes: be more permissive when user specifies both symbol name and address
Date: Mon, 14 Apr 2014 18:40:50 +0800 [thread overview]
Message-ID: <1397472050-19947-1-git-send-email-nasa4836@gmail.com> (raw)
Currently, if user specifies both symbol name and address, we just
bail out.
This might be too rude. This patch makes it give more tolerance.
If both are specified, let symbol name take precedence; upon failure,
try address. And print a warning message if user specify an address
to inform him that using symbol is more preferred.
Signed-off-by: Jianyu Zhan <nasa4836@gmail.com>
---
Documentation/kprobes.txt | 4 +++-
kernel/kprobes.c | 33 +++++++++++++++++++++++++++++----
2 files changed, 32 insertions(+), 5 deletions(-)
diff --git a/Documentation/kprobes.txt b/Documentation/kprobes.txt
index 0cfb00f..ecf901b 100644
--- a/Documentation/kprobes.txt
+++ b/Documentation/kprobes.txt
@@ -344,7 +344,9 @@ to install a probepoint is known. This field is used to calculate the
probepoint.
3. Specify either the kprobe "symbol_name" OR the "addr". If both are
-specified, kprobe registration will fail with -EINVAL.
+specified, searching for "symbol_name" takes precedence; upon failure,
+then try "addr". If neither is specified, kprobe registration will fail
+with -EINVAL.
4. With CISC architectures (such as i386 and x86_64), the kprobes code
does not validate if the kprobe.addr is at an instruction boundary.
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index ceeadfc..2444a7a 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -1354,17 +1354,42 @@ static int __kprobes in_kprobes_functions(unsigned long addr)
static kprobe_opcode_t __kprobes *kprobe_addr(struct kprobe *p)
{
kprobe_opcode_t *addr = p->addr;
+ char namebuf[KSYM_NAME_LEN];
+ const char *sym_name = NULL;
- if ((p->symbol_name && p->addr) ||
- (!p->symbol_name && !p->addr))
+ if (!p->symbol_name && !p->addr)
goto invalid;
if (p->symbol_name) {
kprobe_lookup_name(p->symbol_name, addr);
- if (!addr)
- return ERR_PTR(-ENOENT);
+ if (addr) {
+ if (p->addr && p->addr != addr)
+ printk(KERN_WARNING "Warning: kprobe adrress for %s "
+ "mismatch, should be %p, not %p.\n",
+ p->symbol_name, addr, p->addr);
+ goto found;
+ }
+ }
+ if (p->addr) {
+ printk(KERN_WARNING "Warning: kprobes symbol name is now supported."
+ "Please use it instead.\n");
+ sym_name = kallsyms_lookup((unsigned long)(p->addr),
+ NULL, NULL, NULL, namebuf);
+ if (sym_name) {
+ if (p->symbol_name && strncmp(sym_name, p->symbol_name,
+ KSYM_NAME_LEN))
+ printk(KERN_WARNING "Warning: found %s at addres "
+ "%p, but not %s.\n",
+ p->symbol_name, addr, sym_name);
+
+ addr = p->addr;
+ goto found;
+ }
+
}
+ return ERR_PTR(-ENOENT);
+found:
addr = (kprobe_opcode_t *)(((char *)addr) + p->offset);
if (addr)
return addr;
--
1.9.0.GIT
next reply other threads:[~2014-04-14 10:41 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-14 10:40 Jianyu Zhan [this message]
2014-04-14 15:00 ` Masami Hiramatsu
2014-04-15 8:11 ` Zhan Jianyu
2014-04-15 8:27 ` Masami Hiramatsu
2014-04-15 8:33 ` Zhan Jianyu
2014-04-14 15:08 ` Masami Hiramatsu
2014-04-15 8:10 Jianyu Zhan
2014-04-15 8:54 ` Masami Hiramatsu
2014-04-15 8:58 ` Masami Hiramatsu
2014-04-15 9:16 Jianyu Zhan
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=1397472050-19947-1-git-send-email-nasa4836@gmail.com \
--to=nasa4836@gmail.com \
--cc=ananth@in.ibm.com \
--cc=anil.s.keshavamurthy@intel.com \
--cc=davem@davemloft.net \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=masami.hiramatsu.pt@hitachi.com \
--cc=rdunlap@infradead.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
all inboxes | Powered by JetHome®