use add_taint() for setting tainted bit flags
Subsystems (3)
PATCH 1/1 use add_taint() for setting tainted bit flags
From: Randy Dunlap <[email protected]>
Use the add_taint() interface for setting tainted bit flags instead of doing it manually.
---
arch/i386/kernel/smpboot.c | 2 +- arch/x86_64/kernel/mce.c | 2 +- kernel/module.c | 11 ++++++----- mm/page_alloc.c | 3 ++- 4 files changed, 10 insertions(+), 8 deletions(-)
arch/i386/kernel/smpboot.c renamed from arch/i386/kernel/smpboot.c~use_add_taint +1 -1
@@ -202,7 +202,7 @@ static void __devinit smp_store_cpu_info goto valid_k7;/* If we get here, it's not a certified SMP capable AMD system. */ - tainted |=TAINT_UNSAFE_SMP ; +add_taint (TAINT_UNSAFE_SMP ); } valid_k7:
arch/x86_64/kernel/mce.c renamed from arch/x86_64/kernel/mce.c~use_add_taint +1 -1
@@ -212,7 +212,7 @@ void do_machine_check(struct pt_regs * r panicm_found =1 ; } - tainted |=TAINT_MACHINE_CHECK ; +add_taint (TAINT_MACHINE_CHECK ); }/* Never do anything final in the polling timer */
kernel/module.c renamed from kernel/module.c~use_add_taint +6 -5
@@ -20,6 +20,7 @@#include <linux/module.h> #include <linux/moduleloader.h> #include <linux/init.h> +#include <linux/kernel.h> #include <linux/slab.h> #include <linux/vmalloc.h> #include <linux/elf.h>
@@ -498,7 +499,7 @@ static inline int try_force(unsigned int {int ret = (flags &O_TRUNC );if (ret) - tainted |=TAINT_FORCED_MODULE ; +add_taint (TAINT_FORCED_MODULE );return ret; }#else
@@ -897,7 +898,7 @@ static int check_version(Elf_Shdr *sechdif (!(tainted &TAINT_FORCED_MODULE )) {printk ("%s: no version for \"%s\" found: kernel tainted.\n" , mod->name, symname); - tainted |=TAINT_FORCED_MODULE ; +add_taint (TAINT_FORCED_MODULE ); }return 1 ; }
@@ -1352,7 +1353,7 @@ static void set_license(struct module *mif (!mod->license_gplok && !(tainted &TAINT_PROPRIETARY_MODULE )) {printk (KERN_WARNING "%s: module license '%s' taints kernel.\n" , mod->name, license); - tainted |=TAINT_PROPRIETARY_MODULE ; +add_taint (TAINT_PROPRIETARY_MODULE ); } }
@@ -1610,7 +1611,7 @@ static struct module *load_module(void _ modmagic =get_modinfo (sechdrs, infoindex,"vermagic" );/* This is allowed: modprobe --force will invalidate it. */ if (!modmagic) { - tainted |=TAINT_FORCED_MODULE ; +add_taint (TAINT_FORCED_MODULE );printk (KERN_WARNING "%s: no version magic, tainting kernel.\n" , mod->name); }else if (!same_magic (modmagic, vermagic)) {
@@ -1739,7 +1740,7 @@ static struct module *load_module(void _ (mod->num_gpl_syms && !gplcrcindex)) {printk (KERN_WARNING "%s: No versions for exported symbols." " Tainting kernel.\n" , mod->name); - tainted |=TAINT_FORCED_MODULE ; +add_taint (TAINT_FORCED_MODULE ); }#endif
mm/page_alloc.c renamed from mm/page_alloc.c~use_add_taint +2 -1
@@ -22,6 +22,7 @@#include <linux/pagemap.h> #include <linux/bootmem.h> #include <linux/compiler.h> +#include <linux/kernel.h> #include <linux/module.h> #include <linux/suspend.h> #include <linux/pagevec.h>
@@ -117,7 +118,7 @@ static void bad_page(const char *functioset_page_count (page,0 );reset_page_mapcount (page); page->mapping =NULL ; - tainted |=TAINT_BAD_PAGE ; +add_taint (TAINT_BAD_PAGE ); }#ifndef CONFIG_HUGETLB_PAGE
---
kernel/module.c line 23
Quoted 10 lines · Randy.Dunlap
Use the
add_taint()interface for setting tainted bit flags instead of doing it manually.kernel/module.c renamed from kernel/module.c~use_add_taint +1
-0@@ -20,6 +20,7 @@#include <linux/module.h> #include <linux/moduleloader.h> #include <linux/init.h> +#include <linux/kernel.h>
^^^^^^^^^^^^^^^^^^^^^^^^^
Will something like this be accepted? Not even boot-tested yet.
[PATCH] Separate tainted code.
include/linux/kernel.h is overcrowded. kernel/panic.c has nothing to do with tainting.
arch/i386/kernel/smpboot.c | 1 + arch/x86_64/kernel/mce.c | 1 + include/linux/kernel.h | 10 ---------- include/linux/tainted.h | 15 +++++++++++++++ kernel/Makefile | 2 +- kernel/module.c | 1 + kernel/panic.c | 37 ------------------------------------- kernel/sysctl.c | 1 + kernel/tainted.c | 41 +++++++++++++++++++++++++++++++++++++++++ mm/page_alloc.c | 1 + 10 files changed, 62 insertions(+), 48 deletions(-)
arch/i386/kernel/smpboot.c +1 -0
@@ -37,6 +37,7 @@#include <linux/config.h> #include <linux/init.h> #include <linux/kernel.h> +#include <linux/tainted.h> #include <linux/mm.h> #include <linux/sched.h>
arch/x86_64/kernel/mce.c +1 -0
@@ -17,6 +17,7 @@#include <linux/fs.h> #include <linux/cpu.h> #include <linux/percpu.h> +#include <linux/tainted.h> #include <asm/processor.h> #include <asm/msr.h> #include <asm/mce.h>
include/linux/kernel.h +0 -10
@@ -170,9 +170,6 @@ extern void bust_spinlocks(int yes);extern int oops_in_progress;/* If set, an oops, panic(), BUG() or die() is in progress */ extern int panic_timeout;extern int panic_on_oops; -extern int tainted; -extern const char *print_tainted (void ); -extern void add_taint (unsigned );/* Values used for system_state */ extern enum system_states {
@@ -183,13 +180,6 @@ extern enum system_states {SYSTEM_RESTART , } system_state; -#define TAINT_PROPRIETARY_MODULE (1<<0) -#define TAINT_FORCED_MODULE (1<<1) -#define TAINT_UNSAFE_SMP (1<<2) -#define TAINT_FORCED_RMMOD (1<<3) -#define TAINT_MACHINE_CHECK (1<<4) -#define TAINT_BAD_PAGE (1<<5) -extern void dump_stack (void );#ifdef DEBUG
include/linux/tainted.h +15 -0
@@ -0,0 +1,15 @@ +#ifndef __TAINTED_H__ +#define __TAINTED_H__ + +#define TAINT_PROPRIETARY_MODULE (1<<0) +#define TAINT_FORCED_MODULE (1<<1) +#define TAINT_UNSAFE_SMP (1<<2) +#define TAINT_FORCED_RMMOD (1<<3) +#define TAINT_MACHINE_CHECK (1<<4) +#define TAINT_BAD_PAGE (1<<5) + +extern int tainted; +const char *print_tainted (void ); +void add_taint (unsigned ); + +#endif
kernel/Makefile +1 -1
@@ -4,7 +4,7 @@ obj-y = sched.o fork.o exec_domain.o panic.o printk.o profile.o \ exit.o itimer.o time.o softirq.o resource.o \ - sysctl.o capability.o ptrace.o timer.o user.o \ + sysctl.o capability.o ptrace.o tainted.o timer.o user.o \ signal.o sys.o kmod.o workqueue.o pid.o \ rcupdate.o intermodule.o extable.o params.o posix-timers.o \ kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o
kernel/module.c +1 -0
@@ -36,6 +36,7 @@#include <linux/stop_machine.h> #include <linux/device.h> #include <linux/string.h> +#include <linux/tainted.h> #include <asm/uaccess.h> #include <asm/semaphore.h> #include <asm/cacheflush.h>
kernel/panic.c +0 -37
@@ -22,7 +22,6 @@int panic_timeout;int panic_on_oops; -int tainted;EXPORT_SYMBOL (panic_timeout);
@@ -137,39 +136,3 @@ NORET_TYPE void panic(const char * fmt, }EXPORT_SYMBOL (panic); - -/** -* print_tainted - return a string to represent the kernel taint state. -* -* 'P' - Proprietary module has been loaded. -* 'F' - Module has been forcibly loaded. -* 'S' - SMP with CPUs not designed for SMP. -* 'R' - User forced a module unload. -* 'M' - Machine had a machine check experience. -* 'B' - System has hit bad_page. -* -* The string is overwritten by the next call to print_taint(). -*/ - -const char *print_tainted (void ) -{ -static char buf[20 ]; -if (tainted) { -snprintf (buf,sizeof (buf),"Tainted: %c%c%c%c%c%c" , - tainted &TAINT_PROPRIETARY_MODULE ?'P' :'G' , - tainted &TAINT_FORCED_MODULE ?'F' :' ' , - tainted &TAINT_UNSAFE_SMP ?'S' :' ' , - tainted &TAINT_FORCED_RMMOD ?'R' :' ' , - tainted &TAINT_MACHINE_CHECK ?'M' :' ' , - tainted &TAINT_BAD_PAGE ?'B' :' ' ); - } -else -snprintf (buf,sizeof (buf),"Not tainted" ); -return (buf); -} - -void add_taint (unsigned flag) -{ - tainted |= flag; -} -EXPORT_SYMBOL (add_taint);
kernel/sysctl.c +1 -0
@@ -42,6 +42,7 @@#include <linux/limits.h> #include <linux/dcache.h> #include <linux/syscalls.h> +#include <linux/tainted.h> #include <asm/uaccess.h> #include <asm/processor.h>
kernel/tainted.c +41 -0
41 lines not on this page · raw message
mm/page_alloc.c +1 -0
@@ -34,6 +34,7 @@#include <linux/cpuset.h> #include <linux/nodemask.h> #include <linux/vmalloc.h> +#include <linux/tainted.h> #include <asm/tlbflush.h> #include "internal.h"
Quoted 13 lines · On Sun, 11 Sep 2005 22:33:53 +0400 Alexey Dobriyan wrote:
kernel/module.c line 23
Quoted 10 lines · Randy.Dunlap
Use the
add_taint()interface for setting tainted bit flags instead of doing it manually.kernel/module.c renamed from kernel/module.c~use_add_taint +1
-0@@ -20,6 +20,7 @@#include <linux/module.h> #include <linux/moduleloader.h> #include <linux/init.h> +#include <linux/kernel.h> ^^^^^^^^^^^^^^^^^^^^^^^^^
Quoted 1 line
Will something like this be accepted? Not even boot-tested yet.
Makes sense to me.
Quoted 18 lines
[PATCH] Separate tainted code.
include/linux/kernel.his overcrowded.kernel/panic.chas nothing to do with tainting.arch/i386/kernel/smpboot.c | 1 + arch/x86_64/kernel/mce.c | 1 + include/linux/kernel.h | 10 ---------- include/linux/tainted.h | 15 +++++++++++++++ kernel/Makefile | 2 +- kernel/module.c | 1 + kernel/panic.c | 37 ------------------------------------- kernel/sysctl.c | 1 + kernel/tainted.c | 41 +++++++++++++++++++++++++++++++++++++++++ mm/page_alloc.c | 1 + 10 files changed, 62 insertions(+), 48 deletions(-)
Quoted 11 lines
+/**
+ *print_tainted- return a string to represent the kernel taint state.
+ *
+ * 'P' - Proprietary module has been loaded.
+ * 'F' - Module has been forcibly loaded.
+ * 'S' - SMP with CPUs not designed for SMP.
+ * 'R' - User forced a module unload.
+ * 'M' - Machine had a machine check experience.
+ * 'B' - System has hitbad_page.
+ *
+ * The string is overwritten by the next call toprint_taint().
~~~~~~~~~~~
Please change that to 'print_tainted' too.
kernel/tainted.c line 21
Quoted 4 lines
+ */
kernel/tainted.c +3
-0+ +const char *print_tainted (void ) +{
---
~Randy