From 9d65cb4a1718a072898c7a57a3bc61b2dc4bcd4d Mon Sep 17 00:00:00 2001 From: Alexey Dobriyan Date: Tue, 8 May 2007 00:28:43 -0700 Subject: Fix race between cat /proc/*/wchan and rmmod et al kallsyms_lookup() can go iterating over modules list unprotected which is OK for emergency situations (oops), but not OK for regular stuff like /proc/*/wchan. Introduce lookup_symbol_name()/lookup_module_symbol_name() which copy symbol name into caller-supplied buffer or return -ERANGE. All copying is done with module_mutex held, so... Signed-off-by: Alexey Dobriyan Cc: Rusty Russell Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- kernel/time/timer_list.c | 11 ++++------- kernel/time/timer_stats.c | 10 ++++------ 2 files changed, 8 insertions(+), 13 deletions(-) (limited to 'kernel/time') diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c index fe9314a89f2..b734ca4bc75 100644 --- a/kernel/time/timer_list.c +++ b/kernel/time/timer_list.c @@ -38,15 +38,12 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases); static void print_name_offset(struct seq_file *m, void *sym) { - unsigned long addr = (unsigned long)sym; - char namebuf[KSYM_NAME_LEN+1]; - const char *sym_name; + char symname[KSYM_NAME_LEN+1]; - sym_name = kallsyms_lookup(addr, NULL, NULL, NULL, namebuf); - if (sym_name) - SEQ_printf(m, "%s", sym_name); - else + if (lookup_symbol_name((unsigned long)sym, symname) < 0) SEQ_printf(m, "<%p>", sym); + else + SEQ_printf(m, "%s", symname); } static void diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c index 946ed45f7d2..868f1bceb07 100644 --- a/kernel/time/timer_stats.c +++ b/kernel/time/timer_stats.c @@ -257,14 +257,12 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf, static void print_name_offset(struct seq_file *m, unsigned long addr) { - char namebuf[KSYM_NAME_LEN+1]; - const char *sym_name; + char symname[KSYM_NAME_LEN+1]; - sym_name = kallsyms_lookup(addr, NULL, NULL, NULL, namebuf); - if (sym_name) - seq_printf(m, "%s", sym_name); - else + if (lookup_symbol_name(addr, symname) < 0) seq_printf(m, "<%p>", (void *)addr); + else + seq_printf(m, "%s", symname); } static int tstats_show(struct seq_file *m, void *v) -- cgit v1.2.3-70-g09d2