kernel/kprobes.c: convert to use DEFINE_SEQ_ATTRIBUTE macro
[platform/kernel/linux-rpi.git] / kernel / kprobes.c
index ffbe03a..50cd84f 100644 (file)
@@ -2179,6 +2179,24 @@ int kprobe_add_area_blacklist(unsigned long start, unsigned long end)
        return 0;
 }
 
+/* Remove all symbols in given area from kprobe blacklist */
+static void kprobe_remove_area_blacklist(unsigned long start, unsigned long end)
+{
+       struct kprobe_blacklist_entry *ent, *n;
+
+       list_for_each_entry_safe(ent, n, &kprobe_blacklist, list) {
+               if (ent->start_addr < start || ent->start_addr >= end)
+                       continue;
+               list_del(&ent->list);
+               kfree(ent);
+       }
+}
+
+static void kprobe_remove_ksym_blacklist(unsigned long entry)
+{
+       kprobe_remove_area_blacklist(entry, entry + 1);
+}
+
 int __init __weak arch_populate_kprobe_blacklist(void)
 {
        return 0;
@@ -2211,10 +2229,62 @@ static int __init populate_kprobe_blacklist(unsigned long *start,
        /* Symbols in __kprobes_text are blacklisted */
        ret = kprobe_add_area_blacklist((unsigned long)__kprobes_text_start,
                                        (unsigned long)__kprobes_text_end);
+       if (ret)
+               return ret;
+
+       /* Symbols in noinstr section are blacklisted */
+       ret = kprobe_add_area_blacklist((unsigned long)__noinstr_text_start,
+                                       (unsigned long)__noinstr_text_end);
 
        return ret ? : arch_populate_kprobe_blacklist();
 }
 
+static void add_module_kprobe_blacklist(struct module *mod)
+{
+       unsigned long start, end;
+       int i;
+
+       if (mod->kprobe_blacklist) {
+               for (i = 0; i < mod->num_kprobe_blacklist; i++)
+                       kprobe_add_ksym_blacklist(mod->kprobe_blacklist[i]);
+       }
+
+       start = (unsigned long)mod->kprobes_text_start;
+       if (start) {
+               end = start + mod->kprobes_text_size;
+               kprobe_add_area_blacklist(start, end);
+       }
+
+       start = (unsigned long)mod->noinstr_text_start;
+       if (start) {
+               end = start + mod->noinstr_text_size;
+               kprobe_add_area_blacklist(start, end);
+       }
+}
+
+static void remove_module_kprobe_blacklist(struct module *mod)
+{
+       unsigned long start, end;
+       int i;
+
+       if (mod->kprobe_blacklist) {
+               for (i = 0; i < mod->num_kprobe_blacklist; i++)
+                       kprobe_remove_ksym_blacklist(mod->kprobe_blacklist[i]);
+       }
+
+       start = (unsigned long)mod->kprobes_text_start;
+       if (start) {
+               end = start + mod->kprobes_text_size;
+               kprobe_remove_area_blacklist(start, end);
+       }
+
+       start = (unsigned long)mod->noinstr_text_start;
+       if (start) {
+               end = start + mod->noinstr_text_size;
+               kprobe_remove_area_blacklist(start, end);
+       }
+}
+
 /* Module notifier call back, checking kprobes on the module */
 static int kprobes_module_callback(struct notifier_block *nb,
                                   unsigned long val, void *data)
@@ -2225,6 +2295,11 @@ static int kprobes_module_callback(struct notifier_block *nb,
        unsigned int i;
        int checkcore = (val == MODULE_STATE_GOING);
 
+       if (val == MODULE_STATE_COMING) {
+               mutex_lock(&kprobe_mutex);
+               add_module_kprobe_blacklist(mod);
+               mutex_unlock(&kprobe_mutex);
+       }
        if (val != MODULE_STATE_GOING && val != MODULE_STATE_LIVE)
                return NOTIFY_DONE;
 
@@ -2255,6 +2330,8 @@ static int kprobes_module_callback(struct notifier_block *nb,
                                kill_kprobe(p);
                        }
        }
+       if (val == MODULE_STATE_GOING)
+               remove_module_kprobe_blacklist(mod);
        mutex_unlock(&kprobe_mutex);
        return NOTIFY_DONE;
 }
@@ -2398,28 +2475,19 @@ static int show_kprobe_addr(struct seq_file *pi, void *v)
        return 0;
 }
 
-static const struct seq_operations kprobes_seq_ops = {
+static const struct seq_operations kprobes_sops = {
        .start = kprobe_seq_start,
        .next  = kprobe_seq_next,
        .stop  = kprobe_seq_stop,
        .show  = show_kprobe_addr
 };
 
-static int kprobes_open(struct inode *inode, struct file *filp)
-{
-       return seq_open(filp, &kprobes_seq_ops);
-}
-
-static const struct file_operations debugfs_kprobes_operations = {
-       .open           = kprobes_open,
-       .read           = seq_read,
-       .llseek         = seq_lseek,
-       .release        = seq_release,
-};
+DEFINE_SEQ_ATTRIBUTE(kprobes);
 
 /* kprobes/blacklist -- shows which functions can not be probed */
 static void *kprobe_blacklist_seq_start(struct seq_file *m, loff_t *pos)
 {
+       mutex_lock(&kprobe_mutex);
        return seq_list_start(&kprobe_blacklist, *pos);
 }
 
@@ -2446,24 +2514,18 @@ static int kprobe_blacklist_seq_show(struct seq_file *m, void *v)
        return 0;
 }
 
-static const struct seq_operations kprobe_blacklist_seq_ops = {
-       .start = kprobe_blacklist_seq_start,
-       .next  = kprobe_blacklist_seq_next,
-       .stop  = kprobe_seq_stop,       /* Reuse void function */
-       .show  = kprobe_blacklist_seq_show,
-};
-
-static int kprobe_blacklist_open(struct inode *inode, struct file *filp)
+static void kprobe_blacklist_seq_stop(struct seq_file *f, void *v)
 {
-       return seq_open(filp, &kprobe_blacklist_seq_ops);
+       mutex_unlock(&kprobe_mutex);
 }
 
-static const struct file_operations debugfs_kprobe_blacklist_ops = {
-       .open           = kprobe_blacklist_open,
-       .read           = seq_read,
-       .llseek         = seq_lseek,
-       .release        = seq_release,
+static const struct seq_operations kprobe_blacklist_sops = {
+       .start = kprobe_blacklist_seq_start,
+       .next  = kprobe_blacklist_seq_next,
+       .stop  = kprobe_blacklist_seq_stop,
+       .show  = kprobe_blacklist_seq_show,
 };
+DEFINE_SEQ_ATTRIBUTE(kprobe_blacklist);
 
 static int arm_all_kprobes(void)
 {
@@ -2622,13 +2684,12 @@ static int __init debugfs_kprobe_init(void)
 
        dir = debugfs_create_dir("kprobes", NULL);
 
-       debugfs_create_file("list", 0400, dir, NULL,
-                           &debugfs_kprobes_operations);
+       debugfs_create_file("list", 0400, dir, NULL, &kprobes_fops);
 
        debugfs_create_file("enabled", 0600, dir, &value, &fops_kp);
 
        debugfs_create_file("blacklist", 0400, dir, NULL,
-                           &debugfs_kprobe_blacklist_ops);
+                           &kprobe_blacklist_fops);
 
        return 0;
 }