Documentation
¶
Overview ¶
Package modprobe implements the kernel modprobe usermode helper: it loads a kernel module on demand.
Index ¶
- Variables
- func Main(args []string)
- func ModuleNameFromArgs(args []string) (string, bool)
- func NormalizeModuleName(name string) string
- func ParametersFor(specs []*runtime.KernelModuleSpec, name string) []string
- func QuietFromArgs(args []string) bool
- func ValidModuleName(name string) bool
- func VerifyKernelParent(ppid int, procfsPath string) error
- type Lookup
Constants ¶
This section is empty.
Variables ¶
var ErrNotAModule = errors.New("not a module name")
ErrNotAModule is returned when the requested name is not a module shipped with the running kernel.
This is the expected outcome for subsystem aliases (e.g. 'fs-xfs', 'net-pf-10', 'crypto-aes'), which are what userspace can trigger via mounts, sockets, etc.: Talos never loads modules via aliases.
Functions ¶
func Main ¶
func Main(args []string)
Main is the entrypoint into /sbin/modprobe as invoked by the kernel usermode helper (request_module()).
The kernel executes the static usermode helper (machined) as `/sbin/modprobe -q -- <module>` and waits for the process to exit, so the module is loaded by the time Main returns.
The helper runs as root in the initial namespaces, so it loads the module itself: the module name is looked up without resolving aliases (see LookupModule), and the parameters come from the machine config (KernelModuleSpec resources read via the machined API) if the module is listed there.
Like `modprobe -q`, a request for a name which is not a module exits with an error silently.
func ModuleNameFromArgs ¶
ModuleNameFromArgs extracts the module name from the modprobe arguments.
The kernel invokes `modprobe -q -- <module>`: options (arguments starting with '-') before '--' are skipped, the first argument after '--' or the first non-option argument is the module name.
func NormalizeModuleName ¶
NormalizeModuleName converts the module name to the form used by the kernel ('-' and '_' are interchangeable).
func ParametersFor ¶
func ParametersFor(specs []*runtime.KernelModuleSpec, name string) []string
ParametersFor returns the parameters of the module from the machine config (KernelModuleSpec resources), if listed.
Module names are matched in the normalized form, so the config might list the module as 'dm-thin-pool' while the kernel requests 'dm_thin_pool'.
func QuietFromArgs ¶
QuietFromArgs reports whether the quiet option ('-q') is present among the modprobe options.
func ValidModuleName ¶
ValidModuleName checks that the name is syntactically a kernel module name.
func VerifyKernelParent ¶
VerifyKernelParent checks that the process with the given PID is a kernel thread.
The kernel spawns the usermode helper from a kernel thread (kthreadd or a kworker), while any process started from userspace has a userspace parent (orphans are reparented to init or a subreaper, never to a kernel thread), so a kernel thread as the parent proves the request was issued by the kernel.
Types ¶
type Lookup ¶
type Lookup int
Lookup is the outcome of looking up a module name in the modules directory.
func LookupModule ¶
LookupModule looks the module name up in modules.builtin and modules.dep of the modules directory.
Aliases (modules.alias) are deliberately not consulted: kernel code requesting another module (e.g. a driver loading a helper module while probing a device) uses the module name, while subsystem aliases (net-pf-*, fs-*, crypto-*, binfmt-*, ...) are what userspace can trigger via sockets, mounts, etc.