aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTejun Heo <htejun@gmail.com>2007-07-17 07:03:51 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-07-17 13:23:03 -0400
commit9281acea6a3687ff0f262e0be31eac34895b95d7 (patch)
treef060d6e4f6a5da1c82bc789104683d39377a2e9a
parentb45d52797432bd6b5d9786dbda940eb8d0b9ed06 (diff)
kallsyms: make KSYM_NAME_LEN include space for trailing '\0'
KSYM_NAME_LEN is peculiar in that it does not include the space for the trailing '\0', forcing all users to use KSYM_NAME_LEN + 1 when allocating buffer. This is nonsense and error-prone. Moreover, when the caller forgets that it's very likely to subtly bite back by corrupting the stack because the last position of the buffer is always cleared to zero. This patch increments KSYM_NAME_LEN by one and updates code accordingly. * off-by-one bug in asm-powerpc/kprobes.h::kprobe_lookup_name() macro is fixed. * Where MODULE_NAME_LEN and KSYM_NAME_LEN were used together, MODULE_NAME_LEN was treated as if it didn't include space for the trailing '\0'. Fix it. Signed-off-by: Tejun Heo <htejun@gmail.com> Acked-by: Paulo Marques <pmarques@grupopie.com> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Paul Mackerras <paulus@samba.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--arch/parisc/kernel/unwind.c2
-rw-r--r--fs/proc/base.c2
-rw-r--r--include/asm-powerpc/kprobes.h4
-rw-r--r--include/linux/kallsyms.h6
-rw-r--r--kernel/kallsyms.c16
-rw-r--r--kernel/lockdep.c4
-rw-r--r--kernel/module.c10
-rw-r--r--kernel/time/timer_list.c2
-rw-r--r--kernel/time/timer_stats.c2
-rw-r--r--mm/slab.c2
-rw-r--r--scripts/kallsyms.c4
11 files changed, 27 insertions, 27 deletions
diff --git a/arch/parisc/kernel/unwind.c b/arch/parisc/kernel/unwind.c
index 322167737de7..cf780cb3b916 100644
--- a/arch/parisc/kernel/unwind.c
+++ b/arch/parisc/kernel/unwind.c
@@ -242,7 +242,7 @@ static void unwind_frame_regs(struct unwind_frame_info *info)
242#ifdef CONFIG_KALLSYMS 242#ifdef CONFIG_KALLSYMS
243 /* Handle some frequent special cases.... */ 243 /* Handle some frequent special cases.... */
244 { 244 {
245 char symname[KSYM_NAME_LEN+1]; 245 char symname[KSYM_NAME_LEN];
246 char *modname; 246 char *modname;
247 247
248 kallsyms_lookup(info->ip, NULL, NULL, &modname, 248 kallsyms_lookup(info->ip, NULL, NULL, &modname,
diff --git a/fs/proc/base.c b/fs/proc/base.c
index ae3627337a92..42cb4f5613b6 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -283,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
283static int proc_pid_wchan(struct task_struct *task, char *buffer) 283static int proc_pid_wchan(struct task_struct *task, char *buffer)
284{ 284{
285 unsigned long wchan; 285 unsigned long wchan;
286 char symname[KSYM_NAME_LEN+1]; 286 char symname[KSYM_NAME_LEN];
287 287
288 wchan = get_wchan(task); 288 wchan = get_wchan(task);
289 289
diff --git a/include/asm-powerpc/kprobes.h b/include/asm-powerpc/kprobes.h
index b0e40ff32ee0..9537fda238b8 100644
--- a/include/asm-powerpc/kprobes.h
+++ b/include/asm-powerpc/kprobes.h
@@ -65,10 +65,10 @@ typedef unsigned int kprobe_opcode_t;
65 } else if (name[0] != '.') \ 65 } else if (name[0] != '.') \
66 addr = *(kprobe_opcode_t **)addr; \ 66 addr = *(kprobe_opcode_t **)addr; \
67 } else { \ 67 } else { \
68 char dot_name[KSYM_NAME_LEN+1]; \ 68 char dot_name[KSYM_NAME_LEN]; \
69 dot_name[0] = '.'; \ 69 dot_name[0] = '.'; \
70 dot_name[1] = '\0'; \ 70 dot_name[1] = '\0'; \
71 strncat(dot_name, name, KSYM_NAME_LEN); \ 71 strncat(dot_name, name, KSYM_NAME_LEN - 2); \
72 addr = (kprobe_opcode_t *)kallsyms_lookup_name(dot_name); \ 72 addr = (kprobe_opcode_t *)kallsyms_lookup_name(dot_name); \
73 } \ 73 } \
74} 74}
diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
index 5f06527dca21..f73de6fb5c68 100644
--- a/include/linux/kallsyms.h
+++ b/include/linux/kallsyms.h
@@ -7,9 +7,9 @@
7 7
8#include <linux/errno.h> 8#include <linux/errno.h>
9 9
10#define KSYM_NAME_LEN 127 10#define KSYM_NAME_LEN 128
11#define KSYM_SYMBOL_LEN (sizeof("%s+%#lx/%#lx [%s]") + KSYM_NAME_LEN + \ 11#define KSYM_SYMBOL_LEN (sizeof("%s+%#lx/%#lx [%s]") + (KSYM_NAME_LEN - 1) + \
12 2*(BITS_PER_LONG*3/10) + MODULE_NAME_LEN + 1) 12 2*(BITS_PER_LONG*3/10) + (MODULE_NAME_LEN - 1) + 1)
13 13
14#ifdef CONFIG_KALLSYMS 14#ifdef CONFIG_KALLSYMS
15/* Lookup the address for a symbol. Returns 0 if not found. */ 15/* Lookup the address for a symbol. Returns 0 if not found. */
diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
index 0d662475dd9f..474219a41929 100644
--- a/kernel/kallsyms.c
+++ b/kernel/kallsyms.c
@@ -152,7 +152,7 @@ static unsigned int get_symbol_offset(unsigned long pos)
152/* Lookup the address for this symbol. Returns 0 if not found. */ 152/* Lookup the address for this symbol. Returns 0 if not found. */
153unsigned long kallsyms_lookup_name(const char *name) 153unsigned long kallsyms_lookup_name(const char *name)
154{ 154{
155 char namebuf[KSYM_NAME_LEN+1]; 155 char namebuf[KSYM_NAME_LEN];
156 unsigned long i; 156 unsigned long i;
157 unsigned int off; 157 unsigned int off;
158 158
@@ -248,7 +248,7 @@ const char *kallsyms_lookup(unsigned long addr,
248{ 248{
249 const char *msym; 249 const char *msym;
250 250
251 namebuf[KSYM_NAME_LEN] = 0; 251 namebuf[KSYM_NAME_LEN - 1] = 0;
252 namebuf[0] = 0; 252 namebuf[0] = 0;
253 253
254 if (is_ksym_addr(addr)) { 254 if (is_ksym_addr(addr)) {
@@ -265,7 +265,7 @@ const char *kallsyms_lookup(unsigned long addr,
265 /* see if it's in a module */ 265 /* see if it's in a module */
266 msym = module_address_lookup(addr, symbolsize, offset, modname); 266 msym = module_address_lookup(addr, symbolsize, offset, modname);
267 if (msym) 267 if (msym)
268 return strncpy(namebuf, msym, KSYM_NAME_LEN); 268 return strncpy(namebuf, msym, KSYM_NAME_LEN - 1);
269 269
270 return NULL; 270 return NULL;
271} 271}
@@ -273,7 +273,7 @@ const char *kallsyms_lookup(unsigned long addr,
273int lookup_symbol_name(unsigned long addr, char *symname) 273int lookup_symbol_name(unsigned long addr, char *symname)
274{ 274{
275 symname[0] = '\0'; 275 symname[0] = '\0';
276 symname[KSYM_NAME_LEN] = '\0'; 276 symname[KSYM_NAME_LEN - 1] = '\0';
277 277
278 if (is_ksym_addr(addr)) { 278 if (is_ksym_addr(addr)) {
279 unsigned long pos; 279 unsigned long pos;
@@ -291,7 +291,7 @@ int lookup_symbol_attrs(unsigned long addr, unsigned long *size,
291 unsigned long *offset, char *modname, char *name) 291 unsigned long *offset, char *modname, char *name)
292{ 292{
293 name[0] = '\0'; 293 name[0] = '\0';
294 name[KSYM_NAME_LEN] = '\0'; 294 name[KSYM_NAME_LEN - 1] = '\0';
295 295
296 if (is_ksym_addr(addr)) { 296 if (is_ksym_addr(addr)) {
297 unsigned long pos; 297 unsigned long pos;
@@ -312,7 +312,7 @@ int sprint_symbol(char *buffer, unsigned long address)
312 char *modname; 312 char *modname;
313 const char *name; 313 const char *name;
314 unsigned long offset, size; 314 unsigned long offset, size;
315 char namebuf[KSYM_NAME_LEN+1]; 315 char namebuf[KSYM_NAME_LEN];
316 316
317 name = kallsyms_lookup(address, &size, &offset, &modname, namebuf); 317 name = kallsyms_lookup(address, &size, &offset, &modname, namebuf);
318 if (!name) 318 if (!name)
@@ -342,8 +342,8 @@ struct kallsym_iter
342 unsigned long value; 342 unsigned long value;
343 unsigned int nameoff; /* If iterating in core kernel symbols */ 343 unsigned int nameoff; /* If iterating in core kernel symbols */
344 char type; 344 char type;
345 char name[KSYM_NAME_LEN+1]; 345 char name[KSYM_NAME_LEN];
346 char module_name[MODULE_NAME_LEN + 1]; 346 char module_name[MODULE_NAME_LEN];
347 int exported; 347 int exported;
348}; 348};
349 349
diff --git a/kernel/lockdep.c b/kernel/lockdep.c
index 1a5ff2211d88..edba2ffb43de 100644
--- a/kernel/lockdep.c
+++ b/kernel/lockdep.c
@@ -379,7 +379,7 @@ get_usage_chars(struct lock_class *class, char *c1, char *c2, char *c3, char *c4
379 379
380static void print_lock_name(struct lock_class *class) 380static void print_lock_name(struct lock_class *class)
381{ 381{
382 char str[KSYM_NAME_LEN + 1], c1, c2, c3, c4; 382 char str[KSYM_NAME_LEN], c1, c2, c3, c4;
383 const char *name; 383 const char *name;
384 384
385 get_usage_chars(class, &c1, &c2, &c3, &c4); 385 get_usage_chars(class, &c1, &c2, &c3, &c4);
@@ -401,7 +401,7 @@ static void print_lock_name(struct lock_class *class)
401static void print_lockdep_cache(struct lockdep_map *lock) 401static void print_lockdep_cache(struct lockdep_map *lock)
402{ 402{
403 const char *name; 403 const char *name;
404 char str[KSYM_NAME_LEN + 1]; 404 char str[KSYM_NAME_LEN];
405 405
406 name = lock->name; 406 name = lock->name;
407 if (!name) 407 if (!name)
diff --git a/kernel/module.c b/kernel/module.c
index 539fed9ac83c..33c04ad51175 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -2133,7 +2133,7 @@ int lookup_module_symbol_name(unsigned long addr, char *symname)
2133 sym = get_ksymbol(mod, addr, NULL, NULL); 2133 sym = get_ksymbol(mod, addr, NULL, NULL);
2134 if (!sym) 2134 if (!sym)
2135 goto out; 2135 goto out;
2136 strlcpy(symname, sym, KSYM_NAME_LEN + 1); 2136 strlcpy(symname, sym, KSYM_NAME_LEN);
2137 mutex_unlock(&module_mutex); 2137 mutex_unlock(&module_mutex);
2138 return 0; 2138 return 0;
2139 } 2139 }
@@ -2158,9 +2158,9 @@ int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size,
2158 if (!sym) 2158 if (!sym)
2159 goto out; 2159 goto out;
2160 if (modname) 2160 if (modname)
2161 strlcpy(modname, mod->name, MODULE_NAME_LEN + 1); 2161 strlcpy(modname, mod->name, MODULE_NAME_LEN);
2162 if (name) 2162 if (name)
2163 strlcpy(name, sym, KSYM_NAME_LEN + 1); 2163 strlcpy(name, sym, KSYM_NAME_LEN);
2164 mutex_unlock(&module_mutex); 2164 mutex_unlock(&module_mutex);
2165 return 0; 2165 return 0;
2166 } 2166 }
@@ -2181,8 +2181,8 @@ int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
2181 *value = mod->symtab[symnum].st_value; 2181 *value = mod->symtab[symnum].st_value;
2182 *type = mod->symtab[symnum].st_info; 2182 *type = mod->symtab[symnum].st_info;
2183 strlcpy(name, mod->strtab + mod->symtab[symnum].st_name, 2183 strlcpy(name, mod->strtab + mod->symtab[symnum].st_name,
2184 KSYM_NAME_LEN + 1); 2184 KSYM_NAME_LEN);
2185 strlcpy(module_name, mod->name, MODULE_NAME_LEN + 1); 2185 strlcpy(module_name, mod->name, MODULE_NAME_LEN);
2186 *exported = is_exported(name, mod); 2186 *exported = is_exported(name, mod);
2187 mutex_unlock(&module_mutex); 2187 mutex_unlock(&module_mutex);
2188 return 0; 2188 return 0;
diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
index 8bbcfb77f7d2..e5edc3a22a08 100644
--- a/kernel/time/timer_list.c
+++ b/kernel/time/timer_list.c
@@ -38,7 +38,7 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
38 38
39static void print_name_offset(struct seq_file *m, void *sym) 39static void print_name_offset(struct seq_file *m, void *sym)
40{ 40{
41 char symname[KSYM_NAME_LEN+1]; 41 char symname[KSYM_NAME_LEN];
42 42
43 if (lookup_symbol_name((unsigned long)sym, symname) < 0) 43 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
44 SEQ_printf(m, "<%p>", sym); 44 SEQ_printf(m, "<%p>", sym);
diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
index 9b8a826236dd..8ed62fda16c6 100644
--- a/kernel/time/timer_stats.c
+++ b/kernel/time/timer_stats.c
@@ -269,7 +269,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
269 269
270static void print_name_offset(struct seq_file *m, unsigned long addr) 270static void print_name_offset(struct seq_file *m, unsigned long addr)
271{ 271{
272 char symname[KSYM_NAME_LEN+1]; 272 char symname[KSYM_NAME_LEN];
273 273
274 if (lookup_symbol_name(addr, symname) < 0) 274 if (lookup_symbol_name(addr, symname) < 0)
275 seq_printf(m, "<%p>", (void *)addr); 275 seq_printf(m, "<%p>", (void *)addr);
diff --git a/mm/slab.c b/mm/slab.c
index 35056394139b..96d30ee256ef 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -4344,7 +4344,7 @@ static void show_symbol(struct seq_file *m, unsigned long address)
4344{ 4344{
4345#ifdef CONFIG_KALLSYMS 4345#ifdef CONFIG_KALLSYMS
4346 unsigned long offset, size; 4346 unsigned long offset, size;
4347 char modname[MODULE_NAME_LEN + 1], name[KSYM_NAME_LEN + 1]; 4347 char modname[MODULE_NAME_LEN], name[KSYM_NAME_LEN];
4348 4348
4349 if (lookup_symbol_attrs(address, &size, &offset, modname, name) == 0) { 4349 if (lookup_symbol_attrs(address, &size, &offset, modname, name) == 0) {
4350 seq_printf(m, "%s+%#lx/%#lx", name, offset, size); 4350 seq_printf(m, "%s+%#lx/%#lx", name, offset, size);
diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
index 8b809b264d18..10b006694e5d 100644
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -31,7 +31,7 @@
31#include <string.h> 31#include <string.h>
32#include <ctype.h> 32#include <ctype.h>
33 33
34#define KSYM_NAME_LEN 127 34#define KSYM_NAME_LEN 128
35 35
36 36
37struct sym_entry { 37struct sym_entry {
@@ -254,7 +254,7 @@ static void write_src(void)
254 unsigned int i, k, off; 254 unsigned int i, k, off;
255 unsigned int best_idx[256]; 255 unsigned int best_idx[256];
256 unsigned int *markers; 256 unsigned int *markers;
257 char buf[KSYM_NAME_LEN+1]; 257 char buf[KSYM_NAME_LEN];
258 258
259 printf("#include <asm/types.h>\n"); 259 printf("#include <asm/types.h>\n");
260 printf("#if BITS_PER_LONG == 64\n"); 260 printf("#if BITS_PER_LONG == 64\n");