~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/kernel/module/tracking.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-or-later
  2 /*
  3  * Module taint unload tracking support
  4  *
  5  * Copyright (C) 2022 Aaron Tomlin
  6  */
  7 
  8 #include <linux/module.h>
  9 #include <linux/string.h>
 10 #include <linux/printk.h>
 11 #include <linux/slab.h>
 12 #include <linux/list.h>
 13 #include <linux/debugfs.h>
 14 #include <linux/rculist.h>
 15 #include "internal.h"
 16 
 17 static LIST_HEAD(unloaded_tainted_modules);
 18 extern struct dentry *mod_debugfs_root;
 19 
 20 int try_add_tainted_module(struct module *mod)
 21 {
 22         struct mod_unload_taint *mod_taint;
 23 
 24         module_assert_mutex_or_preempt();
 25 
 26         if (!mod->taints)
 27                 goto out;
 28 
 29         list_for_each_entry_rcu(mod_taint, &unloaded_tainted_modules, list,
 30                                 lockdep_is_held(&module_mutex)) {
 31                 if (!strcmp(mod_taint->name, mod->name) &&
 32                     mod_taint->taints & mod->taints) {
 33                         mod_taint->count++;
 34                         goto out;
 35                 }
 36         }
 37 
 38         mod_taint = kmalloc(sizeof(*mod_taint), GFP_KERNEL);
 39         if (unlikely(!mod_taint))
 40                 return -ENOMEM;
 41         strscpy(mod_taint->name, mod->name, MODULE_NAME_LEN);
 42         mod_taint->taints = mod->taints;
 43         list_add_rcu(&mod_taint->list, &unloaded_tainted_modules);
 44         mod_taint->count = 1;
 45 out:
 46         return 0;
 47 }
 48 
 49 void print_unloaded_tainted_modules(void)
 50 {
 51         struct mod_unload_taint *mod_taint;
 52         char buf[MODULE_FLAGS_BUF_SIZE];
 53 
 54         if (!list_empty(&unloaded_tainted_modules)) {
 55                 printk(KERN_DEFAULT "Unloaded tainted modules:");
 56                 list_for_each_entry_rcu(mod_taint, &unloaded_tainted_modules,
 57                                         list) {
 58                         size_t l;
 59 
 60                         l = module_flags_taint(mod_taint->taints, buf);
 61                         buf[l++] = '\0';
 62                         pr_cont(" %s(%s):%llu", mod_taint->name, buf,
 63                                 mod_taint->count);
 64                 }
 65         }
 66 }
 67 
 68 #ifdef CONFIG_DEBUG_FS
 69 static void *unloaded_tainted_modules_seq_start(struct seq_file *m, loff_t *pos)
 70         __acquires(rcu)
 71 {
 72         rcu_read_lock();
 73         return seq_list_start_rcu(&unloaded_tainted_modules, *pos);
 74 }
 75 
 76 static void *unloaded_tainted_modules_seq_next(struct seq_file *m, void *p, loff_t *pos)
 77 {
 78         return seq_list_next_rcu(p, &unloaded_tainted_modules, pos);
 79 }
 80 
 81 static void unloaded_tainted_modules_seq_stop(struct seq_file *m, void *p)
 82         __releases(rcu)
 83 {
 84         rcu_read_unlock();
 85 }
 86 
 87 static int unloaded_tainted_modules_seq_show(struct seq_file *m, void *p)
 88 {
 89         struct mod_unload_taint *mod_taint;
 90         char buf[MODULE_FLAGS_BUF_SIZE];
 91         size_t l;
 92 
 93         mod_taint = list_entry(p, struct mod_unload_taint, list);
 94         l = module_flags_taint(mod_taint->taints, buf);
 95         buf[l++] = '\0';
 96 
 97         seq_printf(m, "%s (%s) %llu", mod_taint->name, buf, mod_taint->count);
 98         seq_puts(m, "\n");
 99 
100         return 0;
101 }
102 
103 static const struct seq_operations unloaded_tainted_modules_seq_ops = {
104         .start = unloaded_tainted_modules_seq_start,
105         .next  = unloaded_tainted_modules_seq_next,
106         .stop  = unloaded_tainted_modules_seq_stop,
107         .show  = unloaded_tainted_modules_seq_show,
108 };
109 
110 static int unloaded_tainted_modules_open(struct inode *inode, struct file *file)
111 {
112         return seq_open(file, &unloaded_tainted_modules_seq_ops);
113 }
114 
115 static const struct file_operations unloaded_tainted_modules_fops = {
116         .open = unloaded_tainted_modules_open,
117         .read = seq_read,
118         .llseek = seq_lseek,
119         .release = seq_release,
120 };
121 
122 static int __init unloaded_tainted_modules_init(void)
123 {
124         debugfs_create_file("unloaded_tainted", 0444, mod_debugfs_root, NULL,
125                             &unloaded_tainted_modules_fops);
126         return 0;
127 }
128 module_init(unloaded_tainted_modules_init);
129 #endif /* CONFIG_DEBUG_FS */
130 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php