From: Aaron Tomlin <atomlin@redhat.com>
To: mcgrof@kernel.org
Cc: christophe.leroy@csgroup.eu, linux-kernel@vger.kernel.org,
linux-modules@vger.kernel.org, atomlin@atomlin.com
Subject: [PATCH modules-next] module: Add debugfs interface to view unloaded tainted modules
Date: Tue, 23 Aug 2022 20:32:25 +0100 [thread overview]
Message-ID: <20220823193225.2072649-1-atomlin@redhat.com> (raw)
This patch provides debug/modules/unloaded_tainted file to see
a record of unloaded tainted modules.
Signed-off-by: Aaron Tomlin <atomlin@redhat.com>
---
kernel/module/tracking.c | 66 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 66 insertions(+)
diff --git a/kernel/module/tracking.c b/kernel/module/tracking.c
index 7f8133044d09..015e641bc346 100644
--- a/kernel/module/tracking.c
+++ b/kernel/module/tracking.c
@@ -10,6 +10,7 @@
#include <linux/printk.h>
#include <linux/slab.h>
#include <linux/list.h>
+#include <linux/debugfs.h>
#include <linux/rculist.h>
#include "internal.h"
@@ -59,3 +60,68 @@ void print_unloaded_tainted_modules(void)
}
}
}
+
+#ifdef CONFIG_DEBUG_FS
+static void *unloaded_tainted_modules_seq_start(struct seq_file *m, loff_t *pos)
+{
+ mutex_lock(&module_mutex);
+ return seq_list_start_rcu(&unloaded_tainted_modules, *pos);
+}
+
+static void *unloaded_tainted_modules_seq_next(struct seq_file *m, void *p, loff_t *pos)
+{
+ return seq_list_next_rcu(p, &unloaded_tainted_modules, pos);
+}
+
+static void unloaded_tainted_modules_seq_stop(struct seq_file *m, void *p)
+{
+ mutex_unlock(&module_mutex);
+}
+
+static int unloaded_tainted_modules_seq_show(struct seq_file *m, void *p)
+{
+ struct mod_unload_taint *mod_taint;
+ char buf[MODULE_FLAGS_BUF_SIZE];
+ size_t l;
+
+ mod_taint = list_entry(p, struct mod_unload_taint, list);
+ l = module_flags_taint(mod_taint->taints, buf);
+ buf[l++] = '\0';
+
+ seq_printf(m, "%s (%s) %llu", mod_taint->name, buf, mod_taint->count);
+ seq_puts(m, "\n");
+
+ return 0;
+}
+
+static const struct seq_operations unloaded_tainted_modules_seq_ops = {
+ .start = unloaded_tainted_modules_seq_start,
+ .next = unloaded_tainted_modules_seq_next,
+ .stop = unloaded_tainted_modules_seq_stop,
+ .show = unloaded_tainted_modules_seq_show,
+};
+
+static int unloaded_tainted_modules_open(struct inode *inode, struct file *file)
+{
+ return seq_open(file, &unloaded_tainted_modules_seq_ops);
+}
+
+static const struct file_operations unloaded_tainted_modules_fops = {
+ .open = unloaded_tainted_modules_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = seq_release,
+};
+
+static int __init unloaded_tainted_modules_init(void)
+{
+ struct dentry *dir;
+
+ dir = debugfs_create_dir("modules", NULL);
+ debugfs_create_file("unloaded_tainted", 0444, dir, NULL,
+ &unloaded_tainted_modules_fops);
+
+ return 0;
+}
+module_init(unloaded_tainted_modules_init);
+#endif /* CONFIG_DEBUG_FS */
base-commit: 554694ba120b87e39cf732ed632e6a0c52fafb7c
--
2.37.1
next reply other threads:[~2022-08-23 20:12 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-23 19:32 Aaron Tomlin [this message]
2022-08-29 7:14 ` [PATCH modules-next] module: Add debugfs interface to view unloaded tainted modules Petr Pavlu
2022-08-31 10:19 ` Aaron Tomlin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220823193225.2072649-1-atomlin@redhat.com \
--to=atomlin@redhat.com \
--cc=atomlin@atomlin.com \
--cc=christophe.leroy@csgroup.eu \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-modules@vger.kernel.org \
--cc=mcgrof@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).