Transparently handle <.symbol> lookup for kprobes
PATCH 1/1 Transparently handle <.symbol> lookup for kprobes
When data symbols are not present in kernel image, user needs to add dot(".") before function name explicitly, that he wants to probe in kprobe module on ppc64.
for ex:-
When data symbols are missing on ppc64,
====================
[root@llm27lp1 ~]# cat /proc/kallsyms | grep do_fork c00000000006283c T .do_fork
==============================
User needs add "." to "do_fork"
kp.symbol_name = ".do_fork";
============================
This makes kprobe modules unportable. Below patch fixes the problem.
--- include/asm-powerpc/kprobes.h | 6 ++++++ 1 file changed, 6 insertions(+)
include/asm-powerpc/kprobes.h +6 -0
@@ -64,6 +64,12 @@ typedef unsigned int kprobe_opcode_t; addr = *(kprobe_opcode_t **)addr; \ }else if (name[0 ] !='.' ) \ addr = *(kprobe_opcode_t **)addr; \ + }else { \ +char dot_name[KSYM_NAME_LEN +1 ]; \ + dot_name[0 ] ='.' ; \ + dot_name[1 ] ='\0' ; \ +strncat (dot_name, name,KSYM_NAME_LEN ); \ + addr = (kprobe_opcode_t *)kallsyms_lookup_name (dot_name); \ } \ }
include/asm-powerpc/kprobes.h typedef unsigned int kprobe_opcode_t; · line 71
Quoted 5 lines · Srinivasa Ds
include/asm-powerpc/kprobes.h +5
-0+ }else { \ +char dot_name[KSYM_NAME_LEN +1 ]; \ + dot_name[0 ] ='.' ; \ + dot_name[1 ] ='\0' ; \ +strncat (dot_name, name,KSYM_NAME_LEN ); \
Assuming the kernel strncat works like the userspace one does, there is a possibility that dot_name[] won't be properly null-terminated here. If strlen(name) >= KSYM_NAME_LEN-1, then strncat will set dot_name[KSYM_NAME_LEN-1] to something non-null and won't touch dot_name[KSYM_NAME_LEN].
Paul.
Quoted 13 lines · Paul Mackerras
include/asm-powerpc/kprobes.h typedef unsigned int kprobe_opcode_t; · line 71
Quoted 5 lines · Srinivasa Ds
include/asm-powerpc/kprobes.h +5
-0+ }else { \ +char dot_name[KSYM_NAME_LEN +1 ]; \ + dot_name[0 ] ='.' ; \ + dot_name[1 ] ='\0' ; \ +strncat (dot_name, name,KSYM_NAME_LEN ); \Assuming the kernel strncat works like the userspace one does, there is a possibility that dot_name[] won't be properly null-terminated here. If strlen(name) >= KSYM_NAME_LEN-1, then strncat will set dot_name[KSYM_NAME_LEN-1] to something non-null and won't touch dot_name[KSYM_NAME_LEN].
Irrespective of length of the string, kernel implementation of strncat(lib/string.c) ensures that last character of string is set to null. So dot_name[] is always null terminated.
========================
char *strncat(char *dest, const char *src, size_t count)
{
char *tmp = dest;
if (count) {
while (*dest)
dest++;
while ((*dest++ = *src++) != 0) {
if (--count == 0) {
*dest = '\0';
break;
}
}
}
return tmp;
}EXPORT_SYMBOL(strncat);
===============================
Is this OK then ??
Thanks
Srinivasa DS
Quoted 2 lines
Paul.