All articles

Inspect Linux capabilities without changing them

5 minutes read


Linux publication

Share this article

𝕏✉

Illustration for Inspect Linux capabilities without changing them

Linux capabilities split many traditional root privileges into smaller units. A process might bind a low port, trace another process, or change file ownership because it holds one relevant capability, not because its effective user ID is zero.1

That distinction matters during both debugging and security review. Check the executable, the live process, and the service definition before deciding where authority came from.

Inspect file capabilities

getcap -- /usr/bin/ping

An empty result means that path has no file capability record that getcap reports. A result such as cap_net_raw=ep names the capability and the file capability flags.2

To inventory common executable directories:

getcap -r /usr/bin /usr/sbin 2>/dev/null

Recursive scans may cross many packages. Capture the output for comparison, but verify each path against package ownership and local policy before calling it suspicious.

Read a process’s capability sets

grep '^Cap' /proc/$$/status

The fields include the inheritable, permitted, effective, bounding, and ambient sets. The inheritable set is not a record of what the parent passed down: its capabilities are preserved across execve and become permitted only when the new program’s file inheritable bits allow it. The effective set is what the kernel checks for most capability-gated operations. The permitted set limits what can become effective. The bounding set limits capabilities gained across an executable transition, and the ambient set can preserve selected capabilities across execve under specific rules.1

Decode the shell’s effective mask when capsh is installed:

effective=$(awk '/^CapEff:/ { print $2 }' /proc/$$/status)
capsh --decode="$effective"

Use the target PID instead of $$ to inspect another process. Access may be restricted by procfs mount options, credentials, or ptrace policy.

Check the service definition

systemd can add capabilities, remove them from the bounding set, or block privilege gain:

systemctl show example.service \
  -p User \
  -p AmbientCapabilities \
  -p CapabilityBoundingSet \
  -p NoNewPrivileges

These properties help explain how a non-root service obtained its live capability sets. Unit settings such as AmbientCapabilities= and CapabilityBoundingSet= are part of systemd’s process execution controls.3

User namespaces can change the scope in which a capability is meaningful. A capability held inside a container’s user namespace is not automatically equivalent to the same capability in the initial namespace.1

[!CAUTION] setcap changes executable security metadata. Do not use it as a quick fix for a permission error. Granting a capability to a widely used interpreter or shell can create a serious privilege boundary failure.

Sources and further reading
  1. capabilities(7)
  2. getcap(8)
  3. systemd.exec