lsmguard

package
v4.25.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package lsmguard refuses execs in the kernel with a BPF LSM program on bprm_check_security, for hosts whose kernel runs the bpf LSM (lsm=...,bpf) and where the sensor runs with CAP_BPF and CAP_SYS_ADMIN.

The program matches a file by identity (inode and device), not by path, so a renamed or hard-linked copy of a blocked binary is refused too. The sensor fills its map from the exact program paths its block-mode rules name, resolved on the host filesystem. Off unless --bpf-lsm is set.

Limits, stated plainly: the identity of a file on an overlay filesystem or a btrfs subvolume can differ between stat and the kernel's view, so a path there may not match; a replaced file is a new inode and is only covered after the next sync. Not yet run on a live kernel: the object is verified to load as a spec, not by the kernel's verifier.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Spec

func Spec() (*ebpf.CollectionSpec, error)

Spec reads the embedded program without loading it, so it can be checked without privileges.

Types

type Entry

type Entry struct {
	Path string
	Rule decide.RuleRef
}

Entry is one program path to refuse and the rule that names it.

type Guard

type Guard struct {
	// contains filtered or unexported fields
}

Guard is the loaded and attached program.

func Load

func Load() (*Guard, error)

Load loads and attaches the program. It needs the bpf LSM enabled in the kernel and CAP_BPF with CAP_SYS_ADMIN (or root).

func (*Guard) Close

func (g *Guard) Close()

Close detaches the program; execs are no longer checked.

func (*Guard) Run

func (g *Guard) Run(ctx context.Context, report func(Refusal))

Run reads refusals until ctx ends.

func (*Guard) SetEnforce

func (g *Guard) SetEnforce(on bool) error

SetEnforce turns refusing on or off. Off, a match is reported and allowed.

func (*Guard) Sync

func (g *Guard) Sync(entries []Entry, root string) (missing []string, err error)

Sync makes the blocked map hold exactly the files the entries name, read under root (the host filesystem as the sensor sees it). It returns the paths it could not resolve.

type Refusal

type Refusal struct {
	Path     string
	Rule     decide.RuleRef
	PID      int
	Enforced bool
}

Refusal is one exec the program matched.

Jump to

Keyboard shortcuts

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