Commit 373d4d099761cb1f637bed488ab3871945882273

Authored by Rusty Russell
1 parent 64748a2c90

taint: add explicit flag to show whether lock dep is still OK.

Fix up all callers as they were before, with make one change: an
unsigned module taints the kernel, but doesn't turn off lockdep.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

Showing 37 changed files with 69 additions and 67 deletions Side-by-side Diff

arch/alpha/kernel/traps.c
... ... @@ -186,7 +186,7 @@
186 186 #endif
187 187 printk("%s(%d): %s %ld\n", current->comm, task_pid_nr(current), str, err);
188 188 dik_show_regs(regs, r9_15);
189   - add_taint(TAINT_DIE);
  189 + add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
190 190 dik_show_trace((unsigned long *)(regs+1));
191 191 dik_show_code((unsigned int *)regs->pc);
192 192  
arch/arm/kernel/traps.c
... ... @@ -296,7 +296,7 @@
296 296  
297 297 bust_spinlocks(0);
298 298 die_owner = -1;
299   - add_taint(TAINT_DIE);
  299 + add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
300 300 die_nest_count--;
301 301 if (!die_nest_count)
302 302 /* Nest count reaches zero, release the lock. */
arch/arm64/kernel/traps.c
... ... @@ -242,7 +242,7 @@
242 242 crash_kexec(regs);
243 243  
244 244 bust_spinlocks(0);
245   - add_taint(TAINT_DIE);
  245 + add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
246 246 raw_spin_unlock_irq(&die_lock);
247 247 oops_exit();
248 248  
arch/avr32/kernel/traps.c
... ... @@ -61,7 +61,7 @@
61 61 show_regs_log_lvl(regs, KERN_EMERG);
62 62 show_stack_log_lvl(current, regs->sp, regs, KERN_EMERG);
63 63 bust_spinlocks(0);
64   - add_taint(TAINT_DIE);
  64 + add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
65 65 spin_unlock_irq(&die_lock);
66 66  
67 67 if (in_interrupt())
arch/hexagon/kernel/traps.c
... ... @@ -225,7 +225,7 @@
225 225 do_show_stack(current, &regs->r30, pt_elr(regs));
226 226  
227 227 bust_spinlocks(0);
228   - add_taint(TAINT_DIE);
  228 + add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
229 229  
230 230 spin_unlock_irq(&die.lock);
231 231  
arch/ia64/kernel/traps.c
... ... @@ -72,7 +72,7 @@
72 72  
73 73 bust_spinlocks(0);
74 74 die.lock_owner = -1;
75   - add_taint(TAINT_DIE);
  75 + add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
76 76 spin_unlock_irq(&die.lock);
77 77  
78 78 if (!regs)
arch/m68k/kernel/traps.c
... ... @@ -1176,7 +1176,7 @@
1176 1176 console_verbose();
1177 1177 printk("%s: %08x\n",str,nr);
1178 1178 show_registers(fp);
1179   - add_taint(TAINT_DIE);
  1179 + add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
1180 1180 do_exit(SIGSEGV);
1181 1181 }
1182 1182  
arch/mips/kernel/traps.c
... ... @@ -396,7 +396,7 @@
396 396  
397 397 printk("%s[#%d]:\n", str, ++die_counter);
398 398 show_registers(regs);
399   - add_taint(TAINT_DIE);
  399 + add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
400 400 raw_spin_unlock_irq(&die_lock);
401 401  
402 402 oops_exit();
arch/parisc/kernel/traps.c
... ... @@ -282,7 +282,7 @@
282 282  
283 283 show_regs(regs);
284 284 dump_stack();
285   - add_taint(TAINT_DIE);
  285 + add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
286 286  
287 287 if (in_interrupt())
288 288 panic("Fatal exception in interrupt");
arch/powerpc/kernel/traps.c
... ... @@ -138,7 +138,7 @@
138 138 {
139 139 bust_spinlocks(0);
140 140 die_owner = -1;
141   - add_taint(TAINT_DIE);
  141 + add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
142 142 die_nest_count--;
143 143 oops_exit();
144 144 printk("\n");
arch/s390/kernel/traps.c
... ... @@ -271,7 +271,7 @@
271 271 print_modules();
272 272 show_regs(regs);
273 273 bust_spinlocks(0);
274   - add_taint(TAINT_DIE);
  274 + add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
275 275 spin_unlock_irq(&die_lock);
276 276 if (in_interrupt())
277 277 panic("Fatal exception in interrupt");
arch/sh/kernel/traps.c
... ... @@ -38,7 +38,7 @@
38 38 notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV);
39 39  
40 40 bust_spinlocks(0);
41   - add_taint(TAINT_DIE);
  41 + add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
42 42 spin_unlock_irq(&die_lock);
43 43 oops_exit();
44 44  
arch/sparc/kernel/setup_64.c
... ... @@ -115,7 +115,7 @@
115 115 break;
116 116 }
117 117 cheetah_pcache_forced_on = 1;
118   - add_taint(TAINT_MACHINE_CHECK);
  118 + add_taint(TAINT_MACHINE_CHECK, LOCKDEP_NOW_UNRELIABLE);
119 119 cheetah_enable_pcache();
120 120 break;
121 121  
arch/sparc/kernel/traps_32.c
... ... @@ -58,7 +58,7 @@
58 58  
59 59 printk("%s(%d): %s [#%d]\n", current->comm, task_pid_nr(current), str, ++die_counter);
60 60 show_regs(regs);
61   - add_taint(TAINT_DIE);
  61 + add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
62 62  
63 63 __SAVE; __SAVE; __SAVE; __SAVE;
64 64 __SAVE; __SAVE; __SAVE; __SAVE;
arch/sparc/kernel/traps_64.c
... ... @@ -2383,7 +2383,7 @@
2383 2383 notify_die(DIE_OOPS, str, regs, 0, 255, SIGSEGV);
2384 2384 __asm__ __volatile__("flushw");
2385 2385 show_regs(regs);
2386   - add_taint(TAINT_DIE);
  2386 + add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
2387 2387 if (regs->tstate & TSTATE_PRIV) {
2388 2388 struct thread_info *tp = current_thread_info();
2389 2389 struct reg_window *rw = (struct reg_window *)
arch/unicore32/kernel/traps.c
... ... @@ -231,7 +231,7 @@
231 231 ret = __die(str, err, thread, regs);
232 232  
233 233 bust_spinlocks(0);
234   - add_taint(TAINT_DIE);
  234 + add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
235 235 spin_unlock_irq(&die_lock);
236 236 oops_exit();
237 237  
arch/x86/kernel/cpu/amd.c
... ... @@ -220,8 +220,7 @@
220 220 */
221 221 WARN_ONCE(1, "WARNING: This combination of AMD"
222 222 " processors is not suitable for SMP.\n");
223   - if (!test_taint(TAINT_UNSAFE_SMP))
224   - add_taint(TAINT_UNSAFE_SMP);
  223 + add_taint(TAINT_UNSAFE_SMP, LOCKDEP_NOW_UNRELIABLE);
225 224  
226 225 valid_k7:
227 226 ;
arch/x86/kernel/cpu/mcheck/mce.c
... ... @@ -1085,7 +1085,7 @@
1085 1085 /*
1086 1086 * Set taint even when machine check was not enabled.
1087 1087 */
1088   - add_taint(TAINT_MACHINE_CHECK);
  1088 + add_taint(TAINT_MACHINE_CHECK, LOCKDEP_NOW_UNRELIABLE);
1089 1089  
1090 1090 severity = mce_severity(&m, cfg->tolerant, NULL);
1091 1091  
arch/x86/kernel/cpu/mcheck/p5.c
... ... @@ -33,7 +33,7 @@
33 33 smp_processor_id());
34 34 }
35 35  
36   - add_taint(TAINT_MACHINE_CHECK);
  36 + add_taint(TAINT_MACHINE_CHECK, LOCKDEP_NOW_UNRELIABLE);
37 37 }
38 38  
39 39 /* Set up machine check reporting for processors with Intel style MCE: */
arch/x86/kernel/cpu/mcheck/winchip.c
... ... @@ -15,7 +15,7 @@
15 15 static void winchip_machine_check(struct pt_regs *regs, long error_code)
16 16 {
17 17 printk(KERN_EMERG "CPU0: Machine Check Exception.\n");
18   - add_taint(TAINT_MACHINE_CHECK);
  18 + add_taint(TAINT_MACHINE_CHECK, LOCKDEP_NOW_UNRELIABLE);
19 19 }
20 20  
21 21 /* Set up machine check reporting on the Winchip C6 series */
arch/x86/kernel/cpu/mtrr/generic.c
... ... @@ -542,7 +542,7 @@
542 542  
543 543 if (tmp != mask_lo) {
544 544 printk(KERN_WARNING "mtrr: your BIOS has configured an incorrect mask, fixing it.\n");
545   - add_taint(TAINT_FIRMWARE_WORKAROUND);
  545 + add_taint(TAINT_FIRMWARE_WORKAROUND, LOCKDEP_STILL_OK);
546 546 mask_lo = tmp;
547 547 }
548 548 }
arch/x86/kernel/dumpstack.c
... ... @@ -232,7 +232,7 @@
232 232  
233 233 bust_spinlocks(0);
234 234 die_owner = -1;
235   - add_taint(TAINT_DIE);
  235 + add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
236 236 die_nest_count--;
237 237 if (!die_nest_count)
238 238 /* Nest count reaches zero, release the lock. */
arch/xtensa/kernel/traps.c
... ... @@ -524,7 +524,7 @@
524 524 if (!user_mode(regs))
525 525 show_stack(NULL, (unsigned long*)regs->areg[1]);
526 526  
527   - add_taint(TAINT_DIE);
  527 + add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
528 528 spin_unlock_irq(&die_lock);
529 529  
530 530 if (in_interrupt())
drivers/acpi/custom_method.c
... ... @@ -66,7 +66,7 @@
66 66 buf = NULL;
67 67 if (ACPI_FAILURE(status))
68 68 return -EINVAL;
69   - add_taint(TAINT_OVERRIDDEN_ACPI_TABLE);
  69 + add_taint(TAINT_OVERRIDDEN_ACPI_TABLE, LOCKDEP_NOW_UNRELIABLE);
70 70 }
71 71  
72 72 return count;
... ... @@ -661,7 +661,7 @@
661 661 pr_warn(PREFIX
662 662 "Override [%4.4s-%8.8s], this is unsafe: tainting kernel\n",
663 663 table->signature, table->oem_table_id);
664   - add_taint(TAINT_OVERRIDDEN_ACPI_TABLE);
  664 + add_taint(TAINT_OVERRIDDEN_ACPI_TABLE, LOCKDEP_NOW_UNRELIABLE);
665 665 }
666 666  
667 667  
drivers/base/regmap/regmap-debugfs.c
... ... @@ -267,7 +267,7 @@
267 267 return -EINVAL;
268 268  
269 269 /* Userspace has been fiddling around behind the kernel's back */
270   - add_taint(TAINT_USER);
  270 + add_taint(TAINT_USER, LOCKDEP_NOW_UNRELIABLE);
271 271  
272 272 regmap_write(map, reg, value);
273 273 return buf_size;
include/linux/kernel.h
... ... @@ -398,7 +398,11 @@
398 398 extern int panic_on_io_nmi;
399 399 extern int sysctl_panic_on_stackoverflow;
400 400 extern const char *print_tainted(void);
401   -extern void add_taint(unsigned flag);
  401 +enum lockdep_ok {
  402 + LOCKDEP_STILL_OK,
  403 + LOCKDEP_NOW_UNRELIABLE
  404 +};
  405 +extern void add_taint(unsigned flag, enum lockdep_ok);
402 406 extern int test_taint(unsigned flag);
403 407 extern unsigned long get_taint(void);
404 408 extern int root_mountflags;
... ... @@ -197,9 +197,10 @@
197 197 return -ENOENT;
198 198 }
199 199  
200   -static inline void add_taint_module(struct module *mod, unsigned flag)
  200 +static inline void add_taint_module(struct module *mod, unsigned flag,
  201 + enum lockdep_ok lockdep_ok)
201 202 {
202   - add_taint(flag);
  203 + add_taint(flag, lockdep_ok);
203 204 mod->taints |= (1U << flag);
204 205 }
205 206  
... ... @@ -727,7 +728,7 @@
727 728 {
728 729 int ret = (flags & O_TRUNC);
729 730 if (ret)
730   - add_taint(TAINT_FORCED_RMMOD);
  731 + add_taint(TAINT_FORCED_RMMOD, LOCKDEP_NOW_UNRELIABLE);
731 732 return ret;
732 733 }
733 734 #else
... ... @@ -1138,7 +1139,7 @@
1138 1139 if (!test_taint(TAINT_FORCED_MODULE))
1139 1140 printk(KERN_WARNING "%s: %s: kernel tainted.\n",
1140 1141 mod->name, reason);
1141   - add_taint_module(mod, TAINT_FORCED_MODULE);
  1142 + add_taint_module(mod, TAINT_FORCED_MODULE, LOCKDEP_NOW_UNRELIABLE);
1142 1143 return 0;
1143 1144 #else
1144 1145 return -ENOEXEC;
... ... @@ -2147,7 +2148,8 @@
2147 2148 if (!test_taint(TAINT_PROPRIETARY_MODULE))
2148 2149 printk(KERN_WARNING "%s: module license '%s' taints "
2149 2150 "kernel.\n", mod->name, license);
2150   - add_taint_module(mod, TAINT_PROPRIETARY_MODULE);
  2151 + add_taint_module(mod, TAINT_PROPRIETARY_MODULE,
  2152 + LOCKDEP_NOW_UNRELIABLE);
2151 2153 }
2152 2154 }
2153 2155  
2154 2156  
... ... @@ -2700,10 +2702,10 @@
2700 2702 }
2701 2703  
2702 2704 if (!get_modinfo(info, "intree"))
2703   - add_taint_module(mod, TAINT_OOT_MODULE);
  2705 + add_taint_module(mod, TAINT_OOT_MODULE, LOCKDEP_STILL_OK);
2704 2706  
2705 2707 if (get_modinfo(info, "staging")) {
2706   - add_taint_module(mod, TAINT_CRAP);
  2708 + add_taint_module(mod, TAINT_CRAP, LOCKDEP_STILL_OK);
2707 2709 printk(KERN_WARNING "%s: module is from the staging directory,"
2708 2710 " the quality is unknown, you have been warned.\n",
2709 2711 mod->name);
2710 2712  
2711 2713  
... ... @@ -2869,15 +2871,17 @@
2869 2871 * using GPL-only symbols it needs.
2870 2872 */
2871 2873 if (strcmp(mod->name, "ndiswrapper") == 0)
2872   - add_taint(TAINT_PROPRIETARY_MODULE);
  2874 + add_taint(TAINT_PROPRIETARY_MODULE, LOCKDEP_NOW_UNRELIABLE);
2873 2875  
2874 2876 /* driverloader was caught wrongly pretending to be under GPL */
2875 2877 if (strcmp(mod->name, "driverloader") == 0)
2876   - add_taint_module(mod, TAINT_PROPRIETARY_MODULE);
  2878 + add_taint_module(mod, TAINT_PROPRIETARY_MODULE,
  2879 + LOCKDEP_NOW_UNRELIABLE);
2877 2880  
2878 2881 /* lve claims to be GPL but upstream won't provide source */
2879 2882 if (strcmp(mod->name, "lve") == 0)
2880   - add_taint_module(mod, TAINT_PROPRIETARY_MODULE);
  2883 + add_taint_module(mod, TAINT_PROPRIETARY_MODULE,
  2884 + LOCKDEP_NOW_UNRELIABLE);
2881 2885  
2882 2886 #ifdef CONFIG_MODVERSIONS
2883 2887 if ((mod->num_syms && !mod->crcs)
... ... @@ -3197,7 +3201,7 @@
3197 3201 "%s: module verification failed: signature and/or"
3198 3202 " required key missing - tainting kernel\n",
3199 3203 mod->name);
3200   - add_taint_module(mod, TAINT_FORCED_MODULE);
  3204 + add_taint_module(mod, TAINT_FORCED_MODULE, LOCKDEP_STILL_OK);
3201 3205 }
3202 3206 #endif
3203 3207  
... ... @@ -259,27 +259,20 @@
259 259 return tainted_mask;
260 260 }
261 261  
262   -void add_taint(unsigned flag)
  262 +/**
  263 + * add_taint: add a taint flag if not already set.
  264 + * @flag: one of the TAINT_* constants.
  265 + * @lockdep_ok: whether lock debugging is still OK.
  266 + *
  267 + * If something bad has gone wrong, you'll want @lockdebug_ok = false, but for
  268 + * some notewortht-but-not-corrupting cases, it can be set to true.
  269 + */
  270 +void add_taint(unsigned flag, enum lockdep_ok lockdep_ok)
263 271 {
264   - /*
265   - * Can't trust the integrity of the kernel anymore.
266   - * We don't call directly debug_locks_off() because the issue
267   - * is not necessarily serious enough to set oops_in_progress to 1
268   - * Also we want to keep up lockdep for staging/out-of-tree
269   - * development and post-warning case.
270   - */
271   - switch (flag) {
272   - case TAINT_CRAP:
273   - case TAINT_OOT_MODULE:
274   - case TAINT_WARN:
275   - case TAINT_FIRMWARE_WORKAROUND:
276   - break;
  272 + if (lockdep_ok == LOCKDEP_NOW_UNRELIABLE && __debug_locks_off())
  273 + printk(KERN_WARNING
  274 + "Disabling lock debugging due to kernel taint\n");
277 275  
278   - default:
279   - if (__debug_locks_off())
280   - printk(KERN_WARNING "Disabling lock debugging due to kernel taint\n");
281   - }
282   -
283 276 set_bit(flag, &tainted_mask);
284 277 }
285 278 EXPORT_SYMBOL(add_taint);
... ... @@ -421,7 +414,8 @@
421 414 print_modules();
422 415 dump_stack();
423 416 print_oops_end_marker();
424   - add_taint(taint);
  417 + /* Just a warning, don't kill lockdep. */
  418 + add_taint(taint, LOCKDEP_STILL_OK);
425 419 }
426 420  
427 421 void warn_slowpath_fmt(const char *file, int line, const char *fmt, ...)
... ... @@ -2785,7 +2785,7 @@
2785 2785 if (irqs_disabled())
2786 2786 print_irqtrace_events(prev);
2787 2787 dump_stack();
2788   - add_taint(TAINT_WARN);
  2788 + add_taint(TAINT_WARN, LOCKDEP_STILL_OK);
2789 2789 }
2790 2790  
2791 2791 /*
... ... @@ -2006,7 +2006,7 @@
2006 2006 int i;
2007 2007 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2008 2008 if ((tmptaint >> i) & 1)
2009   - add_taint(i);
  2009 + add_taint(i, LOCKDEP_STILL_OK);
2010 2010 }
2011 2011 }
2012 2012  
... ... @@ -166,7 +166,8 @@
166 166 print_modules();
167 167 show_regs(regs);
168 168 print_oops_end_marker();
169   - add_taint(BUG_GET_TAINT(bug));
  169 + /* Just a warning, don't kill lockdep. */
  170 + add_taint(BUG_GET_TAINT(bug), LOCKDEP_STILL_OK);
170 171 return BUG_TRAP_TYPE_WARN;
171 172 }
172 173  
... ... @@ -716,7 +716,7 @@
716 716 print_symbol(KERN_ALERT "vma->vm_file->f_op->mmap: %s\n",
717 717 (unsigned long)vma->vm_file->f_op->mmap);
718 718 dump_stack();
719   - add_taint(TAINT_BAD_PAGE);
  719 + add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
720 720 }
721 721  
722 722 static inline bool is_cow_mapping(vm_flags_t flags)
... ... @@ -320,7 +320,7 @@
320 320 out:
321 321 /* Leave bad fields for debug, except PageBuddy could make trouble */
322 322 reset_page_mapcount(page); /* remove PageBuddy */
323   - add_taint(TAINT_BAD_PAGE);
  323 + add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
324 324 }
325 325  
326 326 /*
... ... @@ -812,7 +812,7 @@
812 812 printk(KERN_ERR "slab error in %s(): cache `%s': %s\n",
813 813 function, cachep->name, msg);
814 814 dump_stack();
815   - add_taint(TAINT_BAD_PAGE);
  815 + add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
816 816 }
817 817 #endif
818 818  
... ... @@ -562,7 +562,7 @@
562 562 printk(KERN_ERR "----------------------------------------"
563 563 "-------------------------------------\n\n");
564 564  
565   - add_taint(TAINT_BAD_PAGE);
  565 + add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
566 566 }
567 567  
568 568 static void slab_fix(struct kmem_cache *s, char *fmt, ...)
sound/soc/soc-core.c
... ... @@ -251,7 +251,7 @@
251 251 return -EINVAL;
252 252  
253 253 /* Userspace has been fiddling around behind the kernel's back */
254   - add_taint(TAINT_USER);
  254 + add_taint(TAINT_USER, LOCKDEP_NOW_UNRELIABLE);
255 255  
256 256 snd_soc_write(codec, reg, value);
257 257 return buf_size;