Meaning of “Tainted…” in oops message.

With my work, I sometimes have to check with ‘oops’ message and first thing I have to check is whether it’s tainted one or not.

For the later use, I decided to keep it in here (also inspired by djoo’s blog. ^^).

It’s basically well explained in kernel source itself. Following is the snippet from the kernel v2.6.30.

struct tnt {
        u8      bit;
        char    true;
        char    false;
};

static const struct tnt tnts[] = {
        { TAINT_PROPRIETARY_MODULE,     'P', 'G' },
        { TAINT_FORCED_MODULE,          'F', ' ' },
        { TAINT_UNSAFE_SMP,             'S', ' ' },
        { TAINT_FORCED_RMMOD,           'R', ' ' },
        { TAINT_MACHINE_CHECK,          'M', ' ' },
        { TAINT_BAD_PAGE,               'B', ' ' },
        { TAINT_USER,                   'U', ' ' },
        { TAINT_DIE,                    'D', ' ' },
        { TAINT_OVERRIDDEN_ACPI_TABLE,  'A', ' ' },
        { TAINT_WARN,                   'W', ' ' },
        { TAINT_CRAP,                   'C', ' ' },
};

/**
 *      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' - System experienced a machine check exception.
 *  'B' - System has hit bad_page.
 *  'U' - Userspace-defined naughtiness.
 *  'D' - Kernel has oopsed before
 *  'A' - ACPI table overridden.
 *  'W' - Taint on warning.
 *  'C' - modules from drivers/staging are loaded.
 *
 *      The string is overwritten by the next call to print_taint().
 */
const char *print_tainted(void)
{
        static char buf[ARRAY_SIZE(tnts) + sizeof("Tainted: ") + 1];

        if (tainted_mask) {
                char *s;
                int i;

                s = buf + sprintf(buf, "Tainted: ");
                for (i = 0; i bit, &tainted_mask) ?
                                        t->true : t->false;
                }
                *s = 0;
        } else
                snprintf(buf, sizeof(buf), "Not tainted");

        return buf;
}

Nothing specially need to explain. Thanks for the easy and clear implementation.

Related definitions are defined as following.

#define TAINT_PROPRIETARY_MODULE        0
#define TAINT_FORCED_MODULE             1
#define TAINT_UNSAFE_SMP                2
#define TAINT_FORCED_RMMOD              3
#define TAINT_MACHINE_CHECK             4
#define TAINT_BAD_PAGE                  5
#define TAINT_USER                      6
#define TAINT_DIE                       7
#define TAINT_OVERRIDDEN_ACPI_TABLE     8
#define TAINT_WARN                      9
#define TAINT_CRAP                      10

In number, it has the value of 2^0 = 1, 2^1 = 2, 2^3 = 4, etc.

You can see this value in /proc/sys/kernel/tainted.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.