Add user taint flag
Subsystems (2)
PATCH 1/1 Add user taint flag
Allow taint flags to be set from userspace by writing to /proc/sys/kernel/tainted, and add a new taint flag, TAINT_USER, to be used when userspace is potentially doing something naughty that might compromise the kernel. This will allow support personnel to ask further questions about what may have caused the user taint flag to have been set. (For example, by examining the logs of the JVM to determine what evil things might have been lurking in the hearts of Java programs. :-)
include/linux/kernel.h +1 -0
@@ -198,6 +198,7 @@#define TAINT_FORCED_RMMOD (1<<3)#define TAINT_MACHINE_CHECK (1<<4)#define TAINT_BAD_PAGE (1<<5) +#define TAINT_USER (1<<6)extern void dump_stack (void );
include/linux/sysctl.h +2 -0
@@ -915,6 +915,8 @@ void __user *, size_t *, loff_t *);extern int proc_dointvec_bset (ctl_table *,int ,struct file *,void __user *,size_t *,loff_t *); +extern int proc_dointvec_taint (ctl_table *,int ,struct file *, +void __user *,size_t *,loff_t *);extern int proc_dointvec_minmax (ctl_table *,int ,struct file *,void __user *,size_t *,loff_t *); extern int proc_dointvec_jiffies(ctl_table *, int, struct file *,
kernel/panic.c +4 -2
@@ -150,6 +150,7 @@* 'R' - User forced a module unload. * 'M' - Machine had a machine check experience. * 'B' - System has hit bad_page. +* 'U' - Userspace-defined naughtiness. * * The string is overwritten by the next call to print_taint(). */
@@ -158,13 +159,14 @@ {static char buf[20 ];if (tainted) { -snprintf (buf,sizeof (buf),"Tainted: %c%c%c%c%c%c" , +snprintf (buf,sizeof (buf),"Tainted: %c%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' :' ' ); + tainted &TAINT_BAD_PAGE ?'B' :' ' , + tainted &TAINT_USER ?'U' :' ' ); }else snprintf (buf,sizeof (buf),"Not tainted" );
kernel/sysctl.c +19 -2
@@ -305,8 +305,8 @@ .procname = "tainted", .data = &tainted, .maxlen = sizeof(int), - .mode = 0444, - .proc_handler = &proc_dointvec, + .mode = 0644, + .proc_handler = &proc_dointvec_taint, }, { .ctl_name = KERN_CAP_BSET,
@@ -1835,6 +1835,23 @@ do_proc_dointvec_bset_conv,&op); } +/* +* Taint values can only be increased +*/ +int proc_dointvec_taint (ctl_table *table,int write,struct file *filp, +void __user *buffer,size_t *lenp,loff_t *ppos) +{ +int op; + +if (!capable (CAP_SYS_ADMIN )) { +return -EPERM ; + } + + op =OP_OR ; +return do_proc_dointvec (table,write,filp,buffer,lenp,ppos, + do_proc_dointvec_bset_conv,&op); +} +struct do_proc_dointvec_minmax_conv_param {int *min;int *max;
Quoted 6 lines · Theodore Ts'o
Allow taint flags to be set from userspace by writing to
/proc/sys/kernel/tainted, and add a new taint flag,TAINT_USER, to be used when userspace is potentially doing something naughty that might compromise the kernel.
What sort of userspace actions are you thinking of here?
And how is other userspace to detect what the naughty userspace is doing?
Someone's done something and you're not telling us what it was ;)
Quoted 4 lines
...
kernel/sysctl.c +1
-0+/*
kernel/sysctl.c line 1848
Quoted 10 lines
kernel/sysctl.c +10
-0+* Taint values can only be increased +*/ +int proc_dointvec_taint (ctl_table *table,int write,struct file *filp, +void __user *buffer,size_t *lenp,loff_t *ppos) +{ +int op; + +if (!capable (CAP_SYS_ADMIN )) { +return -EPERM ; + }
Aren't the /proc file permissions sufficient?
Quoted 7 lines · Andrew Morton
Quoted 4 lines · Theodore Ts'o
Allow taint flags to be set from userspace by writing to
/proc/sys/kernel/tainted, and add a new taint flag,TAINT_USER, to be used when userspace is potentially doing something naughty that might compromise the kernel.What sort of userspace actions are you thinking of here?
You don't really want to know. No, really. :-)
Quoted 1 line
And how is other userspace to detect what the naughty userspace is doing?
When the kernel returns a panic or an Oops, then we'll know something bad had happened....
Quoted 1 line
Someone's done something and you're not telling us what it was ;)
OK, OK. See the attached patch. Note especially the NOT-Signed-off-by.... I am not expecting nor requesting this to get anywhere near mainline.
The problem is that the Real-Time Specification for Java (RTSJ) **requires** that the JVM provide class functions which provide direct access to physical memory; all physical memory. In fact, the RTSJ compliance test explicitly checks for this; it requires that you give the compliance test the address of a few hundred megs of physical memory for the test. The absolutely hilarious bit about all of this is that the same customer who wants RTSJ compliance because of federal procurement regulations is also interested in using SELinux. We've told them that actually using this feature of RTSJ is incompatible with their security needs, and that on production systems they should delete the rmem module from their configured systems. However, it must be present in order to demonstrate RTSJ compliance.
Blame Sun for this insanity, especially since there is no documented way to actually determine which physical memory address are safe to use with this facility --- so any use of this particular RTSJ class *guarantees* that the Java program will be completely non-portable.
So if something does actually use the rmem device, it the rmem module (see below) sets the user TAINT flag, for the same reason that we want to set the taint flag after loading a module from ATI or NVidia. Technically speaking, we don't need to be able to set it via the /proc interface, but it seems like a useful thing that could be useful for other applications.
The basic idea as far as debuging is concerned when someone posts an oops on LKML is the same as any other taint flag; if you see that it came from a tainted kernel, you know not to waste any time looking at the oops. If this goes to our support people, they will know to ask for the JVM log files, which will show the use of this nasty RTSJ capability, and they will know to ask the right questions.
Quoted 5 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ if (!capable(CAP_SYS_ADMIN)) { + return -EPERM; + }Aren't the /proc file permissions sufficient?
Well, that would mean that anyone with CAP_DAC_OVERRIDE would be able to raise the taint level. I think CAP_SYS_ADMIN is actually the better capability; we do something similar with /proc/sys/kernel/cap-bound, which requires CAP_SYS_MODULE.
- Ted
These two kernel modules are needed for use by the TCK conformance test which tests the JVM's RTSJ implementation. Unfortunately, RTSJ requires that Java programs have direct access to physical memory, and /dev/mem does not allow mmap to work to anything beyond I/O mapped memory regions on the x86 platform. Since this is a spectacularly bad idea (so much for write once, debug everywhere) and could potentially destablize the kernel, set the TAINT_USER flag if available.
drivers/char/Kconfig +18 -0
@@ -1013,5 +1013,23 @@ sysfs directory, /sys/devices/platform/telco_clock, with a number of files for controlling the behavior of this hardware. +config ALLOC_RTSJ_MEM + tristate "RTSJ-specific hack to reserve memory" + default m + help + The RTSJ TCK conformance test requires reserving some physical + memory for testing /dev/rmem. + +config RMEM + tristate "Access to physical memory via /dev/rmem" + default m + help + The /dev/mem device only allows mmap() memory availble to + I/O mapped memory; it does not allow access to "real" + physical memory. The /dev/rmem device is a hack which does + allow access to physical memory. We use this instead of + patching /dev/mem because we don't expect this functionality + to ever be accepted into mainline. + endmenu
drivers/char/Makefile +4 -0
@@ -93,6 +93,10 @@ obj-$(CONFIG_HANGCHECK_TIMER) += hangcheck-timer.o obj-$(CONFIG_TCG_TPM) += tpm/ + +obj-$(CONFIG_ALLOC_RTSJ_MEM) += alloc_rtsj_mem.o +obj-$(CONFIG_RMEM) += rmem.o + # Files generated that shall be removed upon make clean clean-files := consolemap_deftbl.c defkeymap.c qtronixmap.c
drivers/char/alloc_rtsj_mem.c new file +88 -0
88 lines not on this page · raw message
drivers/char/rmem.c new file +135 -0
135 lines not on this page · raw message
init/main.c +7 -0
@@ -100,6 +100,12 @@#else static inline void acpi_early_init (void ) { }#endif +#ifdef CONFIG_ALLOC_RTSJ_MEM +extern void alloc_rtsj_mem_early_setup (void ); +#else +static inline void alloc_rtsj_mem_early_setup (void ) { } +#endif +#ifdef CONFIG_TC extern void tc_init (void );
@@ -509,6 +515,7 @@ }#endif vfs_caches_init_early (); +alloc_rtsj_mem_early_setup ();mem_init ();kmem_cache_init ();setup_per_cpu_pageset ();
Quoted 8 lines · Theodore Tso
drivers/char/rmem.c new file +6
-0+struct page *rmem_vma_nopage (struct vm_area_struct *vma, +unsigned long address,int *type) +{ +struct page *pageptr; +unsigned long offset = vma->vm_pgoff <<PAGE_SHIFT ; +unsigned long physaddr = address - vma->vm_start + offset;
drivers/char/rmem.c line 61
Quoted 10 lines
drivers/char/rmem.c new file +10
-0+unsigned long pageframe = physaddr >>PAGE_SHIFT ; + +if (!pfn_valid (pageframe)) +return NOPAGE_SIGBUS ; + pageptr =pfn_to_page (pageframe); +get_page (pageptr); +if (type) + *type =VM_FAULT_MINOR ; +return pageptr; +}
This won't work because struct page could easily be a free page.
I think /dev/mem should be able to remap physical memory now that PG_reserved is gone.
--
Send instant messages to your online friends http://au.messenger.yahoo.com
Quoted 8 lines · Andrew Morton
Quoted 5 lines · Theodore Ts'o
Allow taint flags to be set from userspace by writing to
/proc/sys/kernel/tainted, and add a new taint flag,TAINT_USER, to be used when userspace is potentially doing something naughty that might compromise the kernel.What sort of userspace actions are you thinking of here?
I also thought about tainting the kernel from a userspace program that messes with runtime power management - switch off and on various devices at runtime (which is not recommended by anyone) - and you are clearly in Unsupportedland.
So yes, this is a good idea (although i just would have written a module without MODULE_LICENSE that just printk'ed "Tainting kernel, we will use runtime power management" on load.)
Signature · 3 lines
Stefan Seyfried \ "I didn't want to write for pay. I QA / R&D Team Mobile Devices \ wanted to be paid for what I write." SUSE LINUX Products GmbH, Nürnberg \ -- Leonard Cohen
Hi,
Quoted 7 lines · Theodore Ts'o
Allow taint flags to be set from userspace by writing to
/proc/sys/kernel/tainted, and add a new taint flag,TAINT_USER, to be used when userspace is potentially doing something naughty that might compromise the kernel. This will allow support personnel to ask further questions about what may have caused the user taint flag to have been set. (For example, by examining the logs of the JVM to determine what evil things might have been lurking in the hearts of Java programs. :-)
That's going to lead to a head-scratching fishing expedition from support people wondering just why this flag was set.
At the very least we should force the caller to supply a log message explaining *why* the taint flag is being set and printk it at KERN_ERR loglevel or higher; so the user API would be
echo $log > /proc/sys/kernel/taint
rather than manipulating the bit directly.
--Stephen
Quoted 4 lines · Theodore Ts'o
Allow taint flags to be set from userspace by writing to
/proc/sys/kernel/tainted, and add a new taint flag,TAINT_USER, to be used when userspace is potentially doing something naughty that might compromise the kernel.
we should then patch the /dev/mem driver or something to set this :) (well and possibly give it an exception for now for PCI space until the X people fix their stuff to use the proper sysfs stuff)
Quoted 3 lines · Arjan van de Ven
we should then patch the
/dev/memdriver or something to set this :) (well and possibly give it an exception for now for PCI space until the X people fix their stuff to use the proper sysfs stuff)
/dev/mem is used for all sorts of sane things including DMIdecode. Tainting on it isn't terribly useful. Mind you this whole user taint patch seems bogus as it can only be set by root owned processes so doesn't appear to do the job it is intended for - perhaps Ted can explain ?
What X needs btw is mmap on PCI mmio bars, teach the X mapping code to use those instead of /dev/mem is a simple matter of coding as the right abstractions are in the tree already.
It would need the kernel to also provide a /dev/isa mapping however.
Alan
Quoted 10 lines · Alan Cox
Quoted 3 lines · Arjan van de Ven
we should then patch the
/dev/memdriver or something to set this :) (well and possibly give it an exception for now for PCI space until the X people fix their stuff to use the proper sysfs stuff)
/dev/memis used for all sorts of sane things including DMIdecode. Tainting on it isn't terribly useful. Mind you this whole user taint patch seems bogus as it can only be set by root owned processes so doesn't appear to do the job it is intended for - perhaps Ted can explain ?
Taint on write to /dev/mem, perhaps? I don't think DMIdecode needs to scribble on /dev/mem, does it? (Figure if a userspace program runs OK on a recent Fedora or RedHat kernel, it doesn't need to scribble on /dev/mem too much, because the vast majority of it is lopped out via a patch....)
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
we should then patch the
/dev/memdriver or something to set this :) (well and possibly give it an exception for now for PCI space until the X people fix their stuff to use the proper sysfs stuff)
Quoted 9 lines
Quoted 5 lines
/dev/memis used for all sorts of sane things including DMIdecode. Tainting on it isn't terribly useful. Mind you this whole user taint patch seems bogus as it can only be set by root owned processes so doesn't appear to do the job it is intended for - perhaps Ted can explain ?Taint on write to
/dev/mem, perhaps? I don't think DMIdecode needs to scribble on/dev/mem, does it? (Figure if a userspace program runs OK
lm-sensors looks like it pokes (writes) to /dev/mem trying to figure out some devices.
Quoted 3 lines
on a recent Fedora or RedHat kernel, it doesn't need to scribble on
/dev/memtoo much, because the vast majority of it is lopped out via a patch....)
And what about /dev/port? That can also screw up things, so should probably be included in the taint unless I am missing something.
Jan Engelhardt
Quoted 7 lines · Alan Cox
Quoted 3 lines · Arjan van de Ven
we should then patch the
/dev/memdriver or something to set this :) (well and possibly give it an exception for now for PCI space until the X people fix their stuff to use the proper sysfs stuff)
/dev/memis used for all sorts of sane things including DMIdecode. Tainting on it isn't terribly useful.
I meant taint-on-writable/write, dmi and others map it read only which is obviously different
Quoted 9 lines · Arjan van de Ven
Quoted 4 lines · Theodore Ts'o
Allow taint flags to be set from userspace by writing to
/proc/sys/kernel/tainted, and add a new taint flag,TAINT_USER, to be used when userspace is potentially doing something naughty that might compromise the kernel.we should then patch the
/dev/memdriver or something to set this :) (well and possibly give it an exception for now for PCI space until the X people fix their stuff to use the proper sysfs stuff)
It may make sense to have an explicit taint flag which means direct access to memory, via /dev/mem or otherwise, with exceptions for I/O mapped memory not claimed by a device driver (and of course X until it is fixed, or never, whichever comes first).
As I've mentioned, the original reason why I did this was because I needed to mmap physical memory, which at the time when I originally did things, /dev/mem didn't support except for the I/O mapped memory range, and I assumed that any attempt to enhance /dev/mem's mmap() capabilities in a patch intended for mainline wouldn't be looked at as a friendly act. In fact, I was so unhappy about being forced by the RTSJ specification to do this insane thing that I wanted to make sure that if it were ever used, it would set a TAINT flag to warn people that just about anything unsane could have happened, and the system's stability was at the mercy of the competence of Java application programmers. :-)
- Ted
Quoted 21 lines · On Sun, 21 May 2006 19:04:32 -0400 Theodore Ts'o wrote:
Allow taint flags to be set from userspace by writing to
/proc/sys/kernel/tainted, and add a new taint flag,TAINT_USER, to be used when userspace is potentially doing something naughty that might compromise the kernel. This will allow support personnel to ask further questions about what may have caused the user taint flag to have been set. (For example, by examining the logs of the JVM to determine what evil things might have been lurking in the hearts of Java programs. :-)Signed-off-by "Theodore Ts'o" <[email protected]>Index:
linux-2.6/kernel/sysctl.c
===================================================================kernel/sysctl.c +1
-0@@ -1835,6 +1835,23 @@ do_proc_dointvec_bset_conv,&op); } +/*
kernel/sysctl.c line 1848
Quoted 10 lines
kernel/sysctl.c +10
-0+* Taint values can only be increased +*/ +int proc_dointvec_taint (ctl_table *table,int write,struct file *filp, +void __user *buffer,size_t *lenp,loff_t *ppos) +{ +int op; + +if (!capable (CAP_SYS_ADMIN )) { +return -EPERM ; + }
no braces.
kernel/sysctl.c line 1852
Quoted 4 lines
kernel/sysctl.c +4
-0+ + op =OP_OR ; +return do_proc_dointvec (table,write,filp,buffer,lenp,ppos, + do_proc_dointvec_bset_conv,&op);
find/use that spacebar (after commas).
kernel/sysctl.c line 1857
Quoted 5 lines
kernel/sysctl.c +2
-0+} +struct do_proc_dointvec_minmax_conv_param {int *min;int *max;
---
~Randy
kernel/panic.c line 153
Quoted 7 lines · Theodore Ts'o
kernel/panic.c +1
-0@@ -150,6 +150,7 @@* 'R' - User forced a module unload. * 'M' - Machine had a machine check experience. * 'B' - System has hit bad_page. +* 'U' - Userspace-defined naughtiness.
Just a note, some other distros already use the 'U' flag in taint messages to show an "unsupported" module has been loaded. I know it's out-of-the-tree and will never go into mainline, just FYI if you happen to see some 'U' flags in the wild today...
Oh, and I like this feature, makes sense to me to have this.
thanks,
greg k-h
Quoted 14 lines · Greg KH
kernel/panic.c line 153
Quoted 7 lines · Theodore Ts'o
kernel/panic.c +1
-0@@ -150,6 +150,7 @@* 'R' - User forced a module unload. * 'M' - Machine had a machine check experience. * 'B' - System has hit bad_page. +* 'U' - Userspace-defined naughtiness. Just a note, some other distros already use the 'U' flag in taint messages to show an "unsupported" module has been loaded. I know it's out-of-the-tree and will never go into mainline, just FYI if you happen to see some 'U' flags in the wild today...
Quoted 1 line
Oh, and I like this feature, makes sense to me to have this.
Should we worry about collisions with what distributions are using? That could cause confusion in the future....
- Ted
Quoted 15 lines · Theodore Tso
Quoted 14 lines · Greg KH
kernel/panic.c line 153
Quoted 7 lines · Theodore Ts'o
kernel/panic.c +1
-0@@ -150,6 +150,7 @@* 'R' - User forced a module unload. * 'M' - Machine had a machine check experience. * 'B' - System has hit bad_page. +* 'U' - Userspace-defined naughtiness. Just a note, some other distros already use the 'U' flag in taint messages to show an "unsupported" module has been loaded. I know it's out-of-the-tree and will never go into mainline, just FYI if you happen to see some 'U' flags in the wild today...
Quoted 4 lines
Quoted 1 line
Oh, and I like this feature, makes sense to me to have this.
Should we worry about collisions with what distributions are using? That could cause confusion in the future....
We use it in Fedora/RHEL if a module is loaded that hasn't been gpg signed. It's been handy to spot things like 3rd parties replacing jbd.ko with their own variant in bug-reports.
The signed modules stuff went over like a lead balloon when that was posted last time. Pushing the bit of the patch that describes the taint flag may make sense though to make sure there aren't collisions like this. I agree there is scope for confusion here, and imo kernel.org should be the canonical place where these flags are defined, even if the kernel.org tree doesn't actually use them all.
Dave
Signature · 1 line
http://www.codemonkey.org.uk
Quoted 16 lines · Dave Jones
Quoted 15 lines · Theodore Tso
Quoted 14 lines · Greg KH
kernel/panic.c line 153
Quoted 7 lines · Theodore Ts'o
kernel/panic.c +1
-0@@ -150,6 +150,7 @@* 'R' - User forced a module unload. * 'M' - Machine had a machine check experience. * 'B' - System has hit bad_page. +* 'U' - Userspace-defined naughtiness. Just a note, some other distros already use the 'U' flag in taint messages to show an "unsupported" module has been loaded. I know it's out-of-the-tree and will never go into mainline, just FYI if you happen to see some 'U' flags in the wild today...
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Oh, and I like this feature, makes sense to me to have this.
Should we worry about collisions with what distributions are using? That could cause confusion in the future....
We use it in Fedora/RHEL if a module is loaded that hasn't been gpg signed. It's been handy to spot things like 3rd parties replacing jbd.ko with their own variant in bug-reports.
Brainfart on my part. We mark such modules as (U) in the module list in oopses, but we don't actually taint.
Meh, too early for davej's.
Dave
Signature · 1 line
http://www.codemonkey.org.uk
Quoted 15 lines · Theodore Tso
Quoted 14 lines · Greg KH
kernel/panic.c line 153
Quoted 7 lines · Theodore Ts'o
kernel/panic.c +1
-0@@ -150,6 +150,7 @@* 'R' - User forced a module unload. * 'M' - Machine had a machine check experience. * 'B' - System has hit bad_page. +* 'U' - Userspace-defined naughtiness. Just a note, some other distros already use the 'U' flag in taint messages to show an "unsupported" module has been loaded. I know it's out-of-the-tree and will never go into mainline, just FYI if you happen to see some 'U' flags in the wild today...
Quoted 3 lines
Quoted 1 line
Oh, and I like this feature, makes sense to me to have this.
Should we worry about collisions with what distributions are using?
I wouldn't. It's their responsibility to handle things like this when merging to new kernel versions. They can just change the character, like they handle new sysrq values.
thanks,
greg k-h