Linux Kernel Architecture

(Jacob Rumans) #1

Chapter7:Modules


occur, then the error diagnosis will also contain information about why the kernel is tainted.
This helps developers to distinguish bug reports coming from properly running systems and
those where something was already suspicious.
The functionadd_taint_moduleis provided to taint a given instance ofstruct module.Amod-
ule can taint the kernel for two reasons:

❑ TAINT_PROPRIETARY_MODULEis used if a module with a proprietary license, or a license
that is not compatible with the GPL, is loaded into the kernel. Since the source code for
proprietary modules is most likely not available, kernel developers will not be willing to
fix kernel bugs that appear in possibly even completely unrelated kernel areas. The module
might have done arbitrary things to the kernel that cannot be tracked, so the bugs might
well have been introduced by the module.
Note that the kernel provides the functionlicense_is_gpl_compatibleto decide whether
a given license is compatible with the GPL.

All licenses are, in contrast to the usual habit, not specified by constants, but by C
strings.

❑ TAINT_FORCED_MODULEdenotes that the module was forcibly loaded. Forced loading can be
requested if no version information (also calledversion magic) is present in the module, or if
the module and kernel disagree about the version of some symbol.

❑ license_gplokis a Boolean variable that specifies whether the module license is GPL-
compatible; in other words, whether GPL-exported functions may be used or not. The flag is set
when the module is inserted into the kernel. How the kernel judges a license to be compatible
with the GPL or not is discussed below.


❑ module_refis used for reference counting. There is an entry in the array for each CPU of the
system; this entry specifies at how many other points in the system the module is used. The data
typemodule_refused for the individual array elements contains only one entry, which should,
however, be aligned on the L1 cache:



struct module_ref
{
local_t count;
} ____cacheline_aligned;
The kernel provides thetry_module_getandmodule_putfunctions to increment or decrement
the reference counter. It is also possible to use__module_getto increment the reference count if
the caller is sure that the module is not being unloaded right now.try_module_get, in contrast,
ensures that this is really the case.

❑ modules_which_use_meis used as a list element in the data structures that describe the inter-
module dependencies in the kernel. Section 7.3.2 goes into greater detail.


❑ waiteris a pointer to the task structure of the process that caused the module to be unloaded
and is now waiting for the action to terminate.


❑ exitis the counterpart toinit. It is a pointer to a function called to perform module-specific
clean-up work (e.g., releasing reserved memory areas) when a module is removed.


❑ symtab,num_symtabandstrtabare used to record information onallsymbols of the module
(not only on the explicitly exported symbols).

Free download pdf