Help us shape the future of Go! Take the 2026 Go Developer Survey

procmount

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package procmount checks that /proc hides other accounts' processes.

While a plugin runs, its /proc/<pid> entries (cmdline, comm, the names and number of its threads, its memory counters) are written by the plugin and readable by every account unless /proc is mounted with hidepid=invisible (hidepid=2). The agent account could poll them: a covert channel seccomp cannot close, since the plugin writes them from inside its own process. A pid namespace would not help: the parent namespace still lists the plugin. So lockfile requires the mount option, except in a container that declares itself (ContainerFile) and passes Container.Check: there no other account shares the pid namespace, and the parent namespace is the Docker host's.

Index

Constants

View Source
const ContainerFile = "/etc/lockfile/container.toml"

ContainerFile declares, in an image, that the console runs in a container of its own. Docker cannot mount /proc with hidepid, so there lockfile accepts a /proc that lists every process of the console's pid namespace, provided that namespace holds no other account (Container).

View Source
const Fix = "remount /proc with hidepid=invisible as root: " +
	"mount -o remount,hidepid=invisible,gid=<admin group> /proc " +
	"and make it permanent in /etc/fstab: " +
	"proc /proc proc defaults,hidepid=invisible,gid=<admin group> 0 0 " +
	"(gid= names a group whose members still see every process, for monitoring tools)"

Fix is the remedy, for the human: the remount and the fstab line.

Variables

View Source
var ErrContainer = errors.New("not a private container")

ErrContainer is returned when a container's /proc cannot stand in for hidepid=invisible; it wraps the failed condition.

View Source
var ErrNoProc = errors.New("no proc filesystem mounted at /proc")

ErrNoProc is returned when no proc mount is found at /proc.

View Source
var ErrNotHidden = errors.New("/proc is not mounted with hidepid=invisible")

ErrNotHidden is returned when /proc shows other accounts' processes.

Functions

func Check

func Check(read func() ([]byte, error)) error

Check reads a mount table with read and returns nil when /proc hides other accounts' processes, ErrNotHidden or ErrNoProc otherwise, or the read error.

func CheckSystem

func CheckSystem() error

CheckSystem checks this process's /proc: hidepid=invisible, or, where ContainerFile is present, the container's conditions instead.

func CheckWith

func CheckWith(read func() ([]byte, error), c Container) error

CheckWith is CheckSystem with the mount table and the container given. A declared container must pass c.Check, hidepid or not (its error wraps ErrContainer, and ErrNotHidden too when /proc is not hidden). Undeclared, the result is Check's.

func Hidden

func Hidden(table string) (bool, error)

Hidden reports whether the proc filesystem mounted at /proc (the last one, if mounted over) has hidepid=invisible or its numeric spelling hidepid=2. table is /proc/self/mountinfo or /proc/mounts.

func ReadMountinfo

func ReadMountinfo() ([]byte, error)

ReadMountinfo reads this process's mount table.

Types

type Container

type Container struct {
	File string // ContainerFile
	Proc string // "/proc"
	PID  int    // this process, as its own pid namespace numbers it
	UID  int    // the console's account
	// Owner returns a file's owner uid (fileOwner).
	Owner func(fs.FileInfo) (uid int, ok bool)
}

Container is the stand-in for hidepid=invisible in a container. All conditions must hold: File is a root-owned declaration that others cannot write, in such a directory; the console is in a pid namespace other than the initial one, and Proc is that namespace's /proc; no process listed there runs under an account other than root and UID (the console's); the console runs under a seccomp filter.

func SystemContainer

func SystemContainer() Container

SystemContainer is the Container of this process.

func (Container) Check

func (c Container) Check() error

Check returns nil when all three conditions hold, an error wrapping ErrContainer that names the first failed one otherwise.

func (Container) Declared

func (c Container) Declared() bool

Declared reports whether File exists (whether this is meant to be a container), without checking it.

type Mount

type Mount struct {
	Point, FSType, Options string
}

Mount is one line of a mount table.

func MountOf

func MountOf(table, path string) (Mount, bool)

MountOf returns the mount holding path (absolute, symlinks resolved): the last mount whose point is path or one of its parents.

func Mounts

func Mounts(table string) []Mount

Mounts parses a mount table (mountinfo or /proc/mounts), in order.

Jump to

Keyboard shortcuts

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