modprobe

package module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 12, 2021 License: MIT Imports: 8 Imported by: 9

README

go-modprobe

Load an unload Linux kernel modules using the Linux module syscalls.

This package is Linux specific. Loading a module uses the finit variant, which allows loading of modules by a file descriptor, rather than having to load an ELF into the process memory before loading.

The ability to load and unload modules is dependent on either the CAP_SYS_MODULE capability, or running as root. Care should be taken to understand what security implications this has on processes that use this library.

Setting the capability on a binary using this package

$ sudo setcap cap_sys_module+ep /path/to/binary

Documentation

Overview

Package modprobe allows users to load and unload Linux kernel modules by calling the relevent Linux syscalls.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dependencies

func Dependencies(path string) ([]string, error)

Dependencies takes a path to a .ko file, determine what modules will have to be present before loading that module, and return those modules as a slice of strings.

func Init

func Init(file *os.File, params string) error

Init will use the provide .ko file's os.File (created with os.Open or similar), to load that kernel module into the running kernel. This may error out for a number of reasons, such as no permission (either setcap CAP_SYS_MODULE or run as root), the .ko being for the wrong kernel, or the file not being a module at all.

Any arguments to the module may be passed through `params`, such as `file=/root/data/backing_file`.

func InitWithFlags

func InitWithFlags(file *os.File, params string, flags int) error

InitWithFlags will preform an Init, but allow the passing of flags to the syscall. The `flags` parameter is a bit mask value created by ORing together zero or more of the following flags:

MODULE_INIT_IGNORE_MODVERSIONS - Ignore symbol version hashes
MODULE_INIT_IGNORE_VERMAGIC - Ignore kernel version magic.

Both flags are defined in the golang.org/x/sys/unix package.

func Load

func Load(module, params string) error

Load will, given a short module name (such as `g_ether`), determine where the kernel module is located, determine any dependencies, and load all required modules.

func Name

func Name(file *os.File) (string, error)

Name will, given a file descriptor to a Kernel Module (.ko file), parse the binary to get the module name. For instance, given a handle to the file at `kernel/drivers/usb/gadget/legacy/g_ether.ko`, return `g_ether`.

func Remove

func Remove(name string) error

Remove will unload a loaded kernel module. If no such module is loaded, or if the module can not be unloaded, this function will return an error.

func ResolveName

func ResolveName(name string) (string, error)

ResolveName will, given a module name (such as `g_ether`) return an absolute path to the .ko that provides that module.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL