kmodguard is a kernel module whilelisting system.
output.mp4
- You don't want to maintain a
modprobe.dblacklist. - You don't like setting
kernel.modules_disabled = 1because you want loadable modules support without rebooting.
kmodctl: operator CLI (init,start,stop,status,hook,allow,remove,apply)kmodguard: daemon that evaluates module load requests against policykmodguard-core: shared policy schema, alias resolver, and decision engine
Default policy path: /etc/kmodguard/policy.toml.
Policy supports canonical module names and aliases:
allow.modules: canonical modulesallow.aliases: accepted alias tokens/patternsdeny.modules: explicit deny entriesmode:enforceoraudit
-
Build:
make build -
Install:
sudo make install -
Initialize policy (required):
sudo kmodctl init --output /etc/kmodguard/policy.toml -
Reload and start service:
sudo systemctl daemon-reload && sudo systemctl enable --now kmodguard.service
kmodctl allow <module>: allow module immediately in daemon memory.kmodctl remove <module>: remove module immediately in daemon memory.kmodctl apply: persist current daemon runtime policy to/etc/kmodguard/policy.toml.
Notes:
allow/removerequire daemon socket access.- policy file is unchanged until
kmodctl apply.
kmodguard->/usr/libexec/kmodguard/kmodguardkmodctl->/usr/bin/kmodctlkmodguard.service->/etc/systemd/system/kmodguard.servicekmodguard-hook->/usr/libexec/kmodguard/kmodguard-hook
Staging example (packaging):
make build && make DESTDIR=/tmp/kmodguard-pkg install
startstores existing/proc/sys/kernel/modprobeat/run/kmodguard/original_modprobe.stoprestores it.- The hook (
kmodctl hook) is fail-closed: if the daemon socket is unreachable, module loads are denied and the event is logged via syslog. There is no local-policy fallback. - Denied requests are reported through daemon stderr (captured by journald under systemd).
- The daemon control socket (
/run/kmodguard/daemon.sock) is created0600inside a0755runtime directory. The daemon also enforcesSO_PEERCREDand rejects any connection from a non-root peer withERR unauthorized. kmodctl allow|remove|applytherefore only work when invoked as root and only when the daemon is running.
If the daemon is down and the handler path is stuck, manually restore:
echo /usr/bin/modprobe > /proc/sys/kernel/modprobe
Or use kmodctl disarm --force which falls back to /usr/bin/modprobe when the saved state file is missing.
This project is licensed under the GNU Affero General Public License v3.0 only (AGPL-3.0-only). See LICENSE for the full text.