summaryrefslogtreecommitdiffstats
path: root/kernel/module.c
diff options
context:
space:
mode:
authorPetr Mladek <pmladek@suse.com>2016-09-21 07:47:22 -0400
committerJessica Yu <jeyu@redhat.com>2016-11-26 14:18:01 -0500
commit7fd8329ba502ef76dd91db561c7aed696b2c7720 (patch)
tree1cd64753819f07f811f0c0daabfdf72c952a089f /kernel/module.c
parentc7d47f26df949f0031fe2905068ee85db1b63ed9 (diff)
taint/module: Clean up global and module taint flags handling
The commit 66cc69e34e86a231 ("Fix: module signature vs tracepoints: add new TAINT_UNSIGNED_MODULE") updated module_taint_flags() to potentially print one more character. But it did not increase the size of the corresponding buffers in m_show() and print_modules(). We have recently done the same mistake when adding a taint flag for livepatching, see https://lkml.kernel.org/r/cfba2c823bb984690b73572aaae1db596b54a082.1472137475.git.jpoimboe@redhat.com Also struct module uses an incompatible type for mod-taints flags. It survived from the commit 2bc2d61a9638dab670d ("[PATCH] list module taint flags in Oops/panic"). There was used "int" for the global taint flags at these times. But only the global tain flags was later changed to "unsigned long" by the commit 25ddbb18aae33ad2 ("Make the taint flags reliable"). This patch defines TAINT_FLAGS_COUNT that can be used to create arrays and buffers of the right size. Note that we could not use enum because the taint flag indexes are used also in assembly code. Then it reworks the table that describes the taint flags. The TAINT_* numbers can be used as the index. Instead, we add information if the taint flag is also shown per-module. Finally, it uses "unsigned long", bit operations, and the updated taint_flags table also for mod->taints. It is not optimal because only few taint flags can be printed by module_taint_flags(). But better be on the safe side. IMHO, it is not worth the optimization and this is a good compromise. Signed-off-by: Petr Mladek <pmladek@suse.com> Link: http://lkml.kernel.org/r/1474458442-21581-1-git-send-email-pmladek@suse.com [jeyu@redhat.com: fix broken lkml link in changelog] Signed-off-by: Jessica Yu <jeyu@redhat.com>
Diffstat (limited to 'kernel/module.c')
-rw-r--r--kernel/module.c33
1 files changed, 13 insertions, 20 deletions
diff --git a/kernel/module.c b/kernel/module.c
index f57dd63186e6..a4acd8f403ae 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -330,7 +330,7 @@ static inline void add_taint_module(struct module *mod, unsigned flag,
330 enum lockdep_ok lockdep_ok) 330 enum lockdep_ok lockdep_ok)
331{ 331{
332 add_taint(flag, lockdep_ok); 332 add_taint(flag, lockdep_ok);
333 mod->taints |= (1U << flag); 333 set_bit(flag, &mod->taints);
334} 334}
335 335
336/* 336/*
@@ -1138,24 +1138,13 @@ static inline int module_unload_init(struct module *mod)
1138static size_t module_flags_taint(struct module *mod, char *buf) 1138static size_t module_flags_taint(struct module *mod, char *buf)
1139{ 1139{
1140 size_t l = 0; 1140 size_t l = 0;
1141 int i;
1142
1143 for (i = 0; i < TAINT_FLAGS_COUNT; i++) {
1144 if (taint_flags[i].module && test_bit(i, &mod->taints))
1145 buf[l++] = taint_flags[i].true;
1146 }
1141 1147
1142 if (mod->taints & (1 << TAINT_PROPRIETARY_MODULE))
1143 buf[l++] = 'P';
1144 if (mod->taints & (1 << TAINT_OOT_MODULE))
1145 buf[l++] = 'O';
1146 if (mod->taints & (1 << TAINT_FORCED_MODULE))
1147 buf[l++] = 'F';
1148 if (mod->taints & (1 << TAINT_CRAP))
1149 buf[l++] = 'C';
1150 if (mod->taints & (1 << TAINT_UNSIGNED_MODULE))
1151 buf[l++] = 'E';
1152 if (mod->taints & (1 << TAINT_LIVEPATCH))
1153 buf[l++] = 'K';
1154 /*
1155 * TAINT_FORCED_RMMOD: could be added.
1156 * TAINT_CPU_OUT_OF_SPEC, TAINT_MACHINE_CHECK, TAINT_BAD_PAGE don't
1157 * apply to modules.
1158 */
1159 return l; 1148 return l;
1160} 1149}
1161 1150
@@ -4041,6 +4030,10 @@ int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
4041} 4030}
4042#endif /* CONFIG_KALLSYMS */ 4031#endif /* CONFIG_KALLSYMS */
4043 4032
4033/* Maximum number of characters written by module_flags() */
4034#define MODULE_FLAGS_BUF_SIZE (TAINT_FLAGS_COUNT + 4)
4035
4036/* Keep in sync with MODULE_FLAGS_BUF_SIZE !!! */
4044static char *module_flags(struct module *mod, char *buf) 4037static char *module_flags(struct module *mod, char *buf)
4045{ 4038{
4046 int bx = 0; 4039 int bx = 0;
@@ -4085,7 +4078,7 @@ static void m_stop(struct seq_file *m, void *p)
4085static int m_show(struct seq_file *m, void *p) 4078static int m_show(struct seq_file *m, void *p)
4086{ 4079{
4087 struct module *mod = list_entry(p, struct module, list); 4080 struct module *mod = list_entry(p, struct module, list);
4088 char buf[8]; 4081 char buf[MODULE_FLAGS_BUF_SIZE];
4089 4082
4090 /* We always ignore unformed modules. */ 4083 /* We always ignore unformed modules. */
4091 if (mod->state == MODULE_STATE_UNFORMED) 4084 if (mod->state == MODULE_STATE_UNFORMED)
@@ -4256,7 +4249,7 @@ EXPORT_SYMBOL_GPL(__module_text_address);
4256void print_modules(void) 4249void print_modules(void)
4257{ 4250{
4258 struct module *mod; 4251 struct module *mod;
4259 char buf[8]; 4252 char buf[MODULE_FLAGS_BUF_SIZE];
4260 4253
4261 printk(KERN_DEFAULT "Modules linked in:"); 4254 printk(KERN_DEFAULT "Modules linked in:");
4262 /* Most callers should already have preempt disabled, but make sure */ 4255 /* Most callers should already have preempt disabled, but make sure */