Commit acdfe931 authored by Naveen N. Rao's avatar Naveen N. Rao Committed by Michael Ellerman

powerpc/kprobes: refactor kprobe_lookup_name for safer string operations

Use safer string manipulation functions when dealing with a
user-provided string in kprobe_lookup_name().
Reported-by: default avatarDavid Laight <David.Laight@ACULAB.COM>
Signed-off-by: default avatarNaveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
parent 67ac0bfe
...@@ -53,7 +53,7 @@ bool arch_within_kprobe_blacklist(unsigned long addr) ...@@ -53,7 +53,7 @@ bool arch_within_kprobe_blacklist(unsigned long addr)
kprobe_opcode_t *kprobe_lookup_name(const char *name, unsigned int offset) kprobe_opcode_t *kprobe_lookup_name(const char *name, unsigned int offset)
{ {
kprobe_opcode_t *addr; kprobe_opcode_t *addr = NULL;
#ifdef PPC64_ELF_ABI_v2 #ifdef PPC64_ELF_ABI_v2
/* PPC64 ABIv2 needs local entry point */ /* PPC64 ABIv2 needs local entry point */
...@@ -85,36 +85,29 @@ kprobe_opcode_t *kprobe_lookup_name(const char *name, unsigned int offset) ...@@ -85,36 +85,29 @@ kprobe_opcode_t *kprobe_lookup_name(const char *name, unsigned int offset)
* Also handle <module:symbol> format. * Also handle <module:symbol> format.
*/ */
char dot_name[MODULE_NAME_LEN + 1 + KSYM_NAME_LEN]; char dot_name[MODULE_NAME_LEN + 1 + KSYM_NAME_LEN];
const char *modsym;
bool dot_appended = false; bool dot_appended = false;
if ((modsym = strchr(name, ':')) != NULL) { const char *c;
modsym++; ssize_t ret = 0;
if (*modsym != '\0' && *modsym != '.') { int len = 0;
/* Convert to <module:.symbol> */
strncpy(dot_name, name, modsym - name); if ((c = strnchr(name, MODULE_NAME_LEN, ':')) != NULL) {
dot_name[modsym - name] = '.'; c++;
dot_name[modsym - name + 1] = '\0'; len = c - name;
strncat(dot_name, modsym, memcpy(dot_name, name, len);
sizeof(dot_name) - (modsym - name) - 2); } else
dot_appended = true; c = name;
} else {
dot_name[0] = '\0'; if (*c != '\0' && *c != '.') {
strncat(dot_name, name, sizeof(dot_name) - 1); dot_name[len++] = '.';
}
} else if (name[0] != '.') {
dot_name[0] = '.';
dot_name[1] = '\0';
strncat(dot_name, name, KSYM_NAME_LEN - 2);
dot_appended = true; dot_appended = true;
} else {
dot_name[0] = '\0';
strncat(dot_name, name, KSYM_NAME_LEN - 1);
} }
addr = (kprobe_opcode_t *)kallsyms_lookup_name(dot_name); ret = strscpy(dot_name + len, c, KSYM_NAME_LEN);
if (!addr && dot_appended) { if (ret > 0)
/* Let's try the original non-dot symbol lookup */ addr = (kprobe_opcode_t *)kallsyms_lookup_name(dot_name);
/* Fallback to the original non-dot symbol lookup */
if (!addr && dot_appended)
addr = (kprobe_opcode_t *)kallsyms_lookup_name(name); addr = (kprobe_opcode_t *)kallsyms_lookup_name(name);
}
#else #else
addr = (kprobe_opcode_t *)kallsyms_lookup_name(name); addr = (kprobe_opcode_t *)kallsyms_lookup_name(name);
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment