Search code examples
linuxroot

How do I programmatically taint the Linux kernel?


Is it possible to taint a running Linux kernel programatically? I want to be able to test things with a tainted kernel, without recompiling it to make it tainted or finding a proprietary kernel module to load.


Solution

  • The root user can taint the kernel by writing a taint value to /proc/sys/kernel/tainted. Taint flags can only be set (not removed) in this way: there is no way to untaint a running kernel. When writing a value to indicate that userspace has done something weird, you should use TAINT_USER (which has a value of 32). For example (as root):

    # cat /proc/sys/kernel/tainted
    64
    # echo 32 > /proc/sys/kernel/tainted
    # cat /proc/sys/kernel/tainted
    96