HALF ECHO LEARN / REFERENCE COLLECTION
v262.2src/analyze/analyze-security.c
Git blob: 3289ae8f47f753b1bf609aed4c5a9040bd9fa2e9
Lines 1001–2000 of 2,984
.description_bad = "Service may change UID/GID identities/capabilities",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#CapabilityBoundingSet=",
.weight = 1500,
.range = 1,
.assess = assess_capability_bounding_set,
.parameter = (UINT64_C(1) << CAP_SETUID)|
(UINT64_C(1) << CAP_SETGID)|
(UINT64_C(1) << CAP_SETPCAP),
},
{
.id = "CapabilityBoundingSet=~CAP_SYS_PTRACE",
.json_field = "CapabilityBoundingSet_CAP_SYS_PTRACE",
.description_good = "Service has no ptrace() debugging abilities",
.description_bad = "Service has ptrace() debugging abilities",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#CapabilityBoundingSet=",
.weight = 1500,
.range = 1,
.assess = assess_capability_bounding_set,
.parameter = (UINT64_C(1) << CAP_SYS_PTRACE),
},
{
.id = "CapabilityBoundingSet=~CAP_SYS_TIME",
.json_field = "CapabilityBoundingSet_CAP_SYS_TIME",
.description_good = "Service processes cannot change the system clock",
.description_bad = "Service processes may change the system clock",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#CapabilityBoundingSet=",
.weight = 1000,
.range = 1,
.assess = assess_capability_bounding_set,
.parameter = UINT64_C(1) << CAP_SYS_TIME,
},
{
.id = "CapabilityBoundingSet=~CAP_NET_ADMIN",
.json_field = "CapabilityBoundingSet_CAP_NET_ADMIN",
.description_good = "Service has no network configuration privileges",
.description_bad = "Service has network configuration privileges",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#CapabilityBoundingSet=",
.weight = 1000,
.range = 1,
.assess = assess_capability_bounding_set,
.parameter = (UINT64_C(1) << CAP_NET_ADMIN),
},
{
.id = "CapabilityBoundingSet=~CAP_SYS_RAWIO",
.json_field = "CapabilityBoundingSet_CAP_SYS_RAWIO",
.description_good = "Service has no raw I/O access",
.description_bad = "Service has raw I/O access",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#CapabilityBoundingSet=",
.weight = 1000,
.range = 1,
.assess = assess_capability_bounding_set,
.parameter = (UINT64_C(1) << CAP_SYS_RAWIO),
},
{
.id = "CapabilityBoundingSet=~CAP_SYS_MODULE",
.json_field = "CapabilityBoundingSet_CAP_SYS_MODULE",
.description_good = "Service cannot load kernel modules",
.description_bad = "Service may load kernel modules",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#CapabilityBoundingSet=",
.weight = 1000,
.range = 1,
.assess = assess_capability_bounding_set,
.parameter = (UINT64_C(1) << CAP_SYS_MODULE),
},
{
.id = "CapabilityBoundingSet=~CAP_AUDIT_*",
.json_field = "CapabilityBoundingSet_CAP_AUDIT",
.description_good = "Service has no audit subsystem access",
.description_bad = "Service has audit subsystem access",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#CapabilityBoundingSet=",
.weight = 500,
.range = 1,
.assess = assess_capability_bounding_set,
.parameter = (UINT64_C(1) << CAP_AUDIT_CONTROL) |
(UINT64_C(1) << CAP_AUDIT_READ) |
(UINT64_C(1) << CAP_AUDIT_WRITE),
},
{
.id = "CapabilityBoundingSet=~CAP_SYSLOG",
.json_field = "CapabilityBoundingSet_CAP_SYSLOG",
.description_good = "Service has no access to kernel logging",
.description_bad = "Service has access to kernel logging",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#CapabilityBoundingSet=",
.weight = 500,
.range = 1,
.assess = assess_capability_bounding_set,
.parameter = (UINT64_C(1) << CAP_SYSLOG),
},
{
.id = "CapabilityBoundingSet=~CAP_SYS_(NICE|RESOURCE)",
.json_field = "CapabilityBoundingSet_CAP_SYS_NICE_RESOURCE",
.description_good = "Service has no privileges to change resource use parameters",
.description_bad = "Service has privileges to change resource use parameters",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#CapabilityBoundingSet=",
.weight = 500,
.range = 1,
.assess = assess_capability_bounding_set,
.parameter = (UINT64_C(1) << CAP_SYS_NICE) |
(UINT64_C(1) << CAP_SYS_RESOURCE),
},
{
.id = "CapabilityBoundingSet=~CAP_MKNOD",
.json_field = "CapabilityBoundingSet_CAP_MKNOD",
.description_good = "Service cannot create device nodes",
.description_bad = "Service may create device nodes",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#CapabilityBoundingSet=",
.weight = 500,
.range = 1,
.assess = assess_capability_bounding_set,
.parameter = (UINT64_C(1) << CAP_MKNOD),
},
{
.id = "CapabilityBoundingSet=~CAP_(CHOWN|FSETID|SETFCAP)",
.json_field = "CapabilityBoundingSet_CAP_CHOWN_FSETID_SETFCAP",
.description_good = "Service cannot change file ownership/access mode/capabilities",
.description_bad = "Service may change file ownership/access mode/capabilities unrestricted",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#CapabilityBoundingSet=",
.weight = 1000,
.range = 1,
.assess = assess_capability_bounding_set,
.parameter = (UINT64_C(1) << CAP_CHOWN) |
(UINT64_C(1) << CAP_FSETID) |
(UINT64_C(1) << CAP_SETFCAP),
},
{
.id = "CapabilityBoundingSet=~CAP_(DAC_*|FOWNER|IPC_OWNER)",
.json_field = "CapabilityBoundingSet_CAP_DAC_FOWNER_IPC_OWNER",
.description_good = "Service cannot override UNIX file/IPC permission checks",
.description_bad = "Service may override UNIX file/IPC permission checks",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#CapabilityBoundingSet=",
.weight = 1000,
.range = 1,
.assess = assess_capability_bounding_set,
.parameter = (UINT64_C(1) << CAP_DAC_OVERRIDE) |
(UINT64_C(1) << CAP_DAC_READ_SEARCH) |
(UINT64_C(1) << CAP_FOWNER) |
(UINT64_C(1) << CAP_IPC_OWNER),
},
{
.id = "CapabilityBoundingSet=~CAP_KILL",
.json_field = "CapabilityBoundingSet_CAP_KILL",
.description_good = "Service cannot send UNIX signals to arbitrary processes",
.description_bad = "Service may send UNIX signals to arbitrary processes",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#CapabilityBoundingSet=",
.weight = 500,
.range = 1,
.assess = assess_capability_bounding_set,
.parameter = (UINT64_C(1) << CAP_KILL),
},
{
.id = "CapabilityBoundingSet=~CAP_NET_(BIND_SERVICE|BROADCAST|RAW)",
.json_field = "CapabilityBoundingSet_CAP_NET_BIND_SERVICE_BROADCAST_RAW)",
.description_good = "Service has no elevated networking privileges",
.description_bad = "Service has elevated networking privileges",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#CapabilityBoundingSet=",
.weight = 500,
.range = 1,
.assess = assess_capability_bounding_set,
.parameter = (UINT64_C(1) << CAP_NET_BIND_SERVICE) |
(UINT64_C(1) << CAP_NET_BROADCAST) |
(UINT64_C(1) << CAP_NET_RAW),
},
{
.id = "CapabilityBoundingSet=~CAP_SYS_BOOT",
.json_field = "CapabilityBoundingSet_CAP_SYS_BOOT",
.description_good = "Service cannot issue reboot()",
.description_bad = "Service may issue reboot()",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#CapabilityBoundingSet=",
.weight = 100,
.range = 1,
.assess = assess_capability_bounding_set,
.parameter = (UINT64_C(1) << CAP_SYS_BOOT),
},
{
.id = "CapabilityBoundingSet=~CAP_MAC_*",
.json_field = "CapabilityBoundingSet_CAP_MAC",
.description_good = "Service cannot adjust SMACK MAC",
.description_bad = "Service may adjust SMACK MAC",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#CapabilityBoundingSet=",
.weight = 100,
.range = 1,
.assess = assess_capability_bounding_set,
.parameter = (UINT64_C(1) << CAP_MAC_ADMIN)|
(UINT64_C(1) << CAP_MAC_OVERRIDE),
},
{
.id = "CapabilityBoundingSet=~CAP_LINUX_IMMUTABLE",
.json_field = "CapabilityBoundingSet_CAP_LINUX_IMMUTABLE",
.description_good = "Service cannot mark files immutable",
.description_bad = "Service may mark files immutable",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#CapabilityBoundingSet=",
.weight = 75,
.range = 1,
.assess = assess_capability_bounding_set,
.parameter = (UINT64_C(1) << CAP_LINUX_IMMUTABLE),
},
{
.id = "CapabilityBoundingSet=~CAP_IPC_LOCK",
.json_field = "CapabilityBoundingSet_CAP_IPC_LOCK",
.description_good = "Service cannot lock memory into RAM",
.description_bad = "Service may lock memory into RAM",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#CapabilityBoundingSet=",
.weight = 50,
.range = 1,
.assess = assess_capability_bounding_set,
.parameter = (UINT64_C(1) << CAP_IPC_LOCK),
},
{
.id = "CapabilityBoundingSet=~CAP_SYS_CHROOT",
.json_field = "CapabilityBoundingSet_CAP_SYS_CHROOT",
.description_good = "Service cannot issue chroot()",
.description_bad = "Service may issue chroot()",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#CapabilityBoundingSet=",
.weight = 50,
.range = 1,
.assess = assess_capability_bounding_set,
.parameter = (UINT64_C(1) << CAP_SYS_CHROOT),
},
{
.id = "CapabilityBoundingSet=~CAP_BLOCK_SUSPEND",
.json_field = "CapabilityBoundingSet_CAP_BLOCK_SUSPEND",
.description_good = "Service cannot establish wake locks",
.description_bad = "Service may establish wake locks",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#CapabilityBoundingSet=",
.weight = 25,
.range = 1,
.assess = assess_capability_bounding_set,
.parameter = (UINT64_C(1) << CAP_BLOCK_SUSPEND),
},
{
.id = "CapabilityBoundingSet=~CAP_WAKE_ALARM",
.json_field = "CapabilityBoundingSet_CAP_WAKE_ALARM",
.description_good = "Service cannot program timers that wake up the system",
.description_bad = "Service may program timers that wake up the system",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#CapabilityBoundingSet=",
.weight = 25,
.range = 1,
.assess = assess_capability_bounding_set,
.parameter = (UINT64_C(1) << CAP_WAKE_ALARM),
},
{
.id = "CapabilityBoundingSet=~CAP_LEASE",
.json_field = "CapabilityBoundingSet_CAP_LEASE",
.description_good = "Service cannot create file leases",
.description_bad = "Service may create file leases",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#CapabilityBoundingSet=",
.weight = 25,
.range = 1,
.assess = assess_capability_bounding_set,
.parameter = (UINT64_C(1) << CAP_LEASE),
},
{
.id = "CapabilityBoundingSet=~CAP_SYS_TTY_CONFIG",
.json_field = "CapabilityBoundingSet_CAP_SYS_TTY_CONFIG",
.description_good = "Service cannot issue vhangup()",
.description_bad = "Service may issue vhangup()",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#CapabilityBoundingSet=",
.weight = 25,
.range = 1,
.assess = assess_capability_bounding_set,
.parameter = (UINT64_C(1) << CAP_SYS_TTY_CONFIG),
},
{
.id = "CapabilityBoundingSet=~CAP_SYS_PACCT",
.json_field = "CapabilityBoundingSet_CAP_SYS_PACCT",
.description_good = "Service cannot use acct()",
.description_bad = "Service may use acct()",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#CapabilityBoundingSet=",
.weight = 25,
.range = 1,
.assess = assess_capability_bounding_set,
.parameter = (UINT64_C(1) << CAP_SYS_PACCT),
},
{
.id = "CapabilityBoundingSet=~CAP_BPF",
.json_field = "CapabilityBoundingSet_CAP_BPF",
.description_good = "Service may not load BPF programs",
.description_bad = "Service may load BPF programs",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#CapabilityBoundingSet=",
.weight = 25,
.range = 1,
.assess = assess_capability_bounding_set,
.parameter = (UINT64_C(1) << CAP_BPF),
},
{
.id = "UMask=",
.json_field = "UMask",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#UMask=",
.weight = 100,
.range = 10,
.assess = assess_umask,
},
{
.id = "KeyringMode=",
.json_field = "KeyringMode",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#KeyringMode=",
.description_good = "Service doesn't share key material with other services",
.description_bad = "Service shares key material with other service",
.weight = 1000,
.range = 1,
.assess = assess_keyring_mode,
},
{
.id = "ProtectProc=",
.json_field = "ProtectProc",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#ProtectProc=",
.description_good = "Service has restricted access to process tree (/proc hidepid=)",
.description_bad = "Service has full access to process tree (/proc hidepid=)",
.weight = 1000,
.range = 3,
.assess = assess_protect_proc,
},
{
.id = "ProcSubset=",
.json_field = "ProcSubset",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#ProcSubset=",
.description_good = "Service has no access to non-process /proc files (/proc subset=)",
.description_bad = "Service has full access to non-process /proc files (/proc subset=)",
.weight = 10,
.range = 1,
.assess = assess_proc_subset,
},
{
.id = "NotifyAccess=",
.json_field = "NotifyAccess",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#NotifyAccess=",
.description_good = "Service child processes cannot alter service state",
.description_bad = "Service child processes may alter service state",
.weight = 1000,
.range = 1,
.assess = assess_notify_access,
},
{
.id = "RemoveIPC=",
.json_field = "RemoveIPC",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#RemoveIPC=",
.description_good = "Service user cannot leave SysV IPC objects around",
.description_bad = "Service user may leave SysV IPC objects around",
.description_na = "Service runs as root, option does not apply",
.weight = 100,
.range = 1,
.assess = assess_remove_ipc,
.offset = offsetof(SecurityInfo, remove_ipc),
},
{
.id = "Delegate=",
.json_field = "Delegate",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#Delegate=",
.description_good = "Service does not maintain its own delegated control group subtree",
.description_bad = "Service maintains its own delegated control group subtree",
.weight = 100,
.range = 1,
.assess = assess_bool,
.offset = offsetof(SecurityInfo, delegate),
.parameter = true, /* invert! */
},
{
.id = "RestrictRealtime=",
.json_field = "RestrictRealtime",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#RestrictRealtime=",
.description_good = "Service realtime scheduling access is restricted",
.description_bad = "Service may acquire realtime scheduling",
.weight = 500,
.range = 1,
.assess = assess_bool,
.offset = offsetof(SecurityInfo, restrict_realtime),
},
{
.id = "RestrictSUIDSGID=",
.json_field = "RestrictSUIDSGID",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#RestrictSUIDSGID=",
.description_good = "SUID/SGID file creation by service is restricted",
.description_bad = "Service may create SUID/SGID files",
.weight = 1000,
.range = 1,
.assess = assess_bool,
.offset = offsetof(SecurityInfo, restrict_suid_sgid),
},
{
.id = "RestrictNamespaces=~user",
.json_field = "RestrictNamespaces_user",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#RestrictNamespaces=",
.description_good = "Service cannot create user namespaces",
.description_bad = "Service may create user namespaces",
.weight = 1500,
.range = 1,
.assess = assess_restrict_namespaces,
.parameter = CLONE_NEWUSER,
},
{
.id = "RestrictNamespaces=~mnt",
.json_field = "RestrictNamespaces_mnt",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#RestrictNamespaces=",
.description_good = "Service cannot create file system namespaces",
.description_bad = "Service may create file system namespaces",
.weight = 500,
.range = 1,
.assess = assess_restrict_namespaces,
.parameter = CLONE_NEWNS,
},
{
.id = "RestrictNamespaces=~ipc",
.json_field = "RestrictNamespaces_ipc",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#RestrictNamespaces=",
.description_good = "Service cannot create IPC namespaces",
.description_bad = "Service may create IPC namespaces",
.weight = 500,
.range = 1,
.assess = assess_restrict_namespaces,
.parameter = CLONE_NEWIPC,
},
{
.id = "RestrictNamespaces=~pid",
.json_field = "RestrictNamespaces_pid",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#RestrictNamespaces=",
.description_good = "Service cannot create process namespaces",
.description_bad = "Service may create process namespaces",
.weight = 500,
.range = 1,
.assess = assess_restrict_namespaces,
.parameter = CLONE_NEWPID,
},
{
.id = "RestrictNamespaces=~cgroup",
.json_field = "RestrictNamespaces_cgroup",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#RestrictNamespaces=",
.description_good = "Service cannot create cgroup namespaces",
.description_bad = "Service may create cgroup namespaces",
.weight = 500,
.range = 1,
.assess = assess_restrict_namespaces,
.parameter = CLONE_NEWCGROUP,
},
{
.id = "RestrictNamespaces=~net",
.json_field = "RestrictNamespaces_net",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#RestrictNamespaces=",
.description_good = "Service cannot create network namespaces",
.description_bad = "Service may create network namespaces",
.weight = 500,
.range = 1,
.assess = assess_restrict_namespaces,
.parameter = CLONE_NEWNET,
},
{
.id = "RestrictNamespaces=~uts",
.json_field = "RestrictNamespaces_uts",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#RestrictNamespaces=",
.description_good = "Service cannot create hostname namespaces",
.description_bad = "Service may create hostname namespaces",
.weight = 100,
.range = 1,
.assess = assess_restrict_namespaces,
.parameter = CLONE_NEWUTS,
},
{
.id = "RestrictAddressFamilies=~AF_(INET|INET6)",
.json_field = "RestrictAddressFamilies_AF_INET_INET6",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#RestrictAddressFamilies=",
.description_good = "Service cannot allocate Internet sockets",
.description_bad = "Service may allocate Internet sockets",
.weight = 1500,
.range = 1,
.assess = assess_bool,
.offset = offsetof(SecurityInfo, restrict_address_family_inet),
},
{
.id = "RestrictAddressFamilies=~AF_UNIX",
.json_field = "RestrictAddressFamilies_AF_UNIX",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#RestrictAddressFamilies=",
.description_good = "Service cannot allocate local sockets",
.description_bad = "Service may allocate local sockets",
.weight = 25,
.range = 1,
.assess = assess_bool,
.offset = offsetof(SecurityInfo, restrict_address_family_unix),
},
{
.id = "RestrictAddressFamilies=~AF_NETLINK",
.json_field = "RestrictAddressFamilies_AF_NETLINK",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#RestrictAddressFamilies=",
.description_good = "Service cannot allocate netlink sockets",
.description_bad = "Service may allocate netlink sockets",
.weight = 200,
.range = 1,
.assess = assess_bool,
.offset = offsetof(SecurityInfo, restrict_address_family_netlink),
},
{
.id = "RestrictAddressFamilies=~AF_PACKET",
.json_field = "RestrictAddressFamilies_AF_PACKET",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#RestrictAddressFamilies=",
.description_good = "Service cannot allocate packet sockets",
.description_bad = "Service may allocate packet sockets",
.weight = 1000,
.range = 1,
.assess = assess_bool,
.offset = offsetof(SecurityInfo, restrict_address_family_packet),
},
{
.id = "RestrictAddressFamilies=~…",
.json_field = "RestrictAddressFamilies_OTHER",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#RestrictAddressFamilies=",
.description_good = "Service cannot allocate exotic sockets",
.description_bad = "Service may allocate exotic sockets",
.weight = 1250,
.range = 1,
.assess = assess_bool,
.offset = offsetof(SecurityInfo, restrict_address_family_other),
},
#if HAVE_SECCOMP
{
.id = "SystemCallArchitectures=",
.json_field = "SystemCallArchitectures",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#SystemCallArchitectures=",
.weight = 1000,
.range = 10,
.assess = assess_system_call_architectures,
},
{
.id = "SystemCallFilter=~@swap",
.json_field = "SystemCallFilter_swap",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#SystemCallFilter=",
.weight = 1000,
.range = 10,
.assess = assess_system_call_filter,
.parameter = SYSCALL_FILTER_SET_SWAP,
},
{
.id = "SystemCallFilter=~@obsolete",
.json_field = "SystemCallFilter_obsolete",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#SystemCallFilter=",
.weight = 250,
.range = 10,
.assess = assess_system_call_filter,
.parameter = SYSCALL_FILTER_SET_OBSOLETE,
},
{
.id = "SystemCallFilter=~@clock",
.json_field = "SystemCallFilter_clock",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#SystemCallFilter=",
.weight = 1000,
.range = 10,
.assess = assess_system_call_filter,
.parameter = SYSCALL_FILTER_SET_CLOCK,
},
{
.id = "SystemCallFilter=~@cpu-emulation",
.json_field = "SystemCallFilter_cpu_emulation",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#SystemCallFilter=",
.weight = 250,
.range = 10,
.assess = assess_system_call_filter,
.parameter = SYSCALL_FILTER_SET_CPU_EMULATION,
},
{
.id = "SystemCallFilter=~@debug",
.json_field = "SystemCallFilter_debug",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#SystemCallFilter=",
.weight = 1000,
.range = 10,
.assess = assess_system_call_filter,
.parameter = SYSCALL_FILTER_SET_DEBUG,
},
{
.id = "SystemCallFilter=~@mount",
.json_field = "SystemCallFilter_mount",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#SystemCallFilter=",
.weight = 1000,
.range = 10,
.assess = assess_system_call_filter,
.parameter = SYSCALL_FILTER_SET_MOUNT,
},
{
.id = "SystemCallFilter=~@module",
.json_field = "SystemCallFilter_module",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#SystemCallFilter=",
.weight = 1000,
.range = 10,
.assess = assess_system_call_filter,
.parameter = SYSCALL_FILTER_SET_MODULE,
},
{
.id = "SystemCallFilter=~@raw-io",
.json_field = "SystemCallFilter_raw_io",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#SystemCallFilter=",
.weight = 1000,
.range = 10,
.assess = assess_system_call_filter,
.parameter = SYSCALL_FILTER_SET_RAW_IO,
},
{
.id = "SystemCallFilter=~@reboot",
.json_field = "SystemCallFilter_reboot",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#SystemCallFilter=",
.weight = 1000,
.range = 10,
.assess = assess_system_call_filter,
.parameter = SYSCALL_FILTER_SET_REBOOT,
},
{
.id = "SystemCallFilter=~@privileged",
.json_field = "SystemCallFilter_privileged",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#SystemCallFilter=",
.weight = 700,
.range = 10,
.assess = assess_system_call_filter,
.parameter = SYSCALL_FILTER_SET_PRIVILEGED,
},
{
.id = "SystemCallFilter=~@resources",
.json_field = "SystemCallFilter_resources",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#SystemCallFilter=",
.weight = 700,
.range = 10,
.assess = assess_system_call_filter,
.parameter = SYSCALL_FILTER_SET_RESOURCES,
},
#endif
{
.id = "IPAddressDeny=",
.json_field = "IPAddressDeny",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.resource-control.html#IPAddressAllow=ADDRESS%5B/PREFIXLENGTH%5D…",
.weight = 1000,
.range = 10,
.assess = assess_ip_address_allow,
},
{
.id = "DeviceAllow=",
.json_field = "DeviceAllow",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.resource-control.html#DeviceAllow=",
.weight = 1000,
.range = 10,
.assess = assess_device_allow,
},
{
.id = "AmbientCapabilities=",
.json_field = "AmbientCapabilities",
.url = "https://www.freedesktop.org/software/systemd/man/systemd.exec.html#AmbientCapabilities=",
.description_good = "Service process does not receive ambient capabilities",
.description_bad = "Service process receives ambient capabilities",
.weight = 500,
.range = 1,
.assess = assess_ambient_capabilities,
},
};
static sd_json_variant* security_assessor_find_in_policy(const struct security_assessor *a, sd_json_variant *policy, const char *name) {
sd_json_variant *item;
assert(a);
if (!policy)
return NULL;
if (!sd_json_variant_is_object(policy)) {
log_debug("Specified policy is not a JSON object, ignoring.");
return NULL;
}
item = sd_json_variant_by_key(policy, a->json_field);
if (!item)
return NULL;
if (!sd_json_variant_is_object(item)) {
log_debug("Item for '%s' in policy JSON object is not an object, ignoring.", a->id);
return NULL;
}
return name ? sd_json_variant_by_key(item, name) : item;
}
static uint64_t access_weight(const struct security_assessor *a, sd_json_variant *policy) {
sd_json_variant *val;
assert(a);
val = security_assessor_find_in_policy(a, policy, "weight");
if (val) {
if (sd_json_variant_is_unsigned(val))
return sd_json_variant_unsigned(val);
log_debug("JSON field 'weight' of policy for %s is not an unsigned integer, ignoring.", a->id);
}
return a->weight;
}
static uint64_t access_range(const struct security_assessor *a, sd_json_variant *policy) {
sd_json_variant *val;
assert(a);
val = security_assessor_find_in_policy(a, policy, "range");
if (val) {
if (sd_json_variant_is_unsigned(val))
return sd_json_variant_unsigned(val);
log_debug("JSON field 'range' of policy for %s is not an unsigned integer, ignoring.", a->id);
}
return a->range;
}
static const char *access_description_na(const struct security_assessor *a, sd_json_variant *policy) {
sd_json_variant *val;
assert(a);
val = security_assessor_find_in_policy(a, policy, "description_na");
if (val) {
if (sd_json_variant_is_string(val))
return sd_json_variant_string(val);
log_debug("JSON field 'description_na' of policy for %s is not a string, ignoring.", a->id);
}
return a->description_na;
}
static const char *access_description_good(const struct security_assessor *a, sd_json_variant *policy) {
sd_json_variant *val;
assert(a);
val = security_assessor_find_in_policy(a, policy, "description_good");
if (val) {
if (sd_json_variant_is_string(val))
return sd_json_variant_string(val);
log_debug("JSON field 'description_good' of policy for %s is not a string, ignoring.", a->id);
}
return a->description_good;
}
static const char *access_description_bad(const struct security_assessor *a, sd_json_variant *policy) {
sd_json_variant *val;
assert(a);
val = security_assessor_find_in_policy(a, policy, "description_bad");
if (val) {
if (sd_json_variant_is_string(val))
return sd_json_variant_string(val);
log_debug("JSON field 'description_bad' of policy for %s is not a string, ignoring.", a->id);
}
return a->description_bad;
}
static int assess(const SecurityInfo *info,
Table *overview_table,
AnalyzeSecurityFlags flags,
unsigned threshold,
sd_json_variant *policy,
PagerFlags pager_flags,
sd_json_format_flags_t json_format_flags) {
static const struct {
uint64_t exposure;
const char *name;
const char* (*color)(void);
Glyph smiley;
} badness_table[] = {
{ 100, "DANGEROUS", ansi_highlight_red, GLYPH_DEPRESSED_SMILEY },
{ 90, "UNSAFE", ansi_highlight_red, GLYPH_UNHAPPY_SMILEY },
{ 75, "EXPOSED", ansi_highlight_yellow, GLYPH_SLIGHTLY_UNHAPPY_SMILEY },
{ 50, "MEDIUM", NULL, GLYPH_NEUTRAL_SMILEY },
{ 10, "OK", ansi_highlight_green, GLYPH_SLIGHTLY_HAPPY_SMILEY },
{ 1, "SAFE", ansi_highlight_green, GLYPH_HAPPY_SMILEY },
{ 0, "PERFECT", ansi_highlight_green, GLYPH_ECSTATIC_SMILEY },
};
uint64_t badness_sum = 0, weight_sum = 0, exposure;
_cleanup_(table_unrefp) Table *details_table = NULL;
size_t i;
int r;
if (!FLAGS_SET(flags, ANALYZE_SECURITY_SHORT)) {
details_table = table_new(" ", "name", "json_field", "description", "weight", "badness", "range", "exposure");
if (!details_table)
return log_oom();
r = table_set_json_field_name(details_table, 0, "set");
if (r < 0)
return log_error_errno(r, "Failed to set JSON field name of column 0: %m");
(void) table_set_sort(details_table, (size_t) 3, (size_t) 1);
(void) table_set_reverse(details_table, 3, true);
if (getenv_bool("SYSTEMD_ANALYZE_DEBUG") <= 0)
(void) table_set_display(details_table, (size_t) 0, (size_t) 1, (size_t) 2, (size_t) 3, (size_t) 7);
}
FOREACH_ELEMENT(a, security_assessor_table) {
_cleanup_free_ char *d = NULL;
uint64_t badness;
void *data;
uint64_t weight = access_weight(a, policy);
uint64_t range = access_range(a, policy);
data = (uint8_t*) info + a->offset;
if (a->default_dependencies_only && !info->default_dependencies) {
badness = UINT64_MAX;
d = strdup("Service runs in special boot phase, option is not appropriate");
if (!d)
return log_oom();
} else if (weight == 0) {
badness = UINT64_MAX;
d = strdup("Option excluded by policy, skipping");
if (!d)
return log_oom();
} else {
r = a->assess(a, info, data, &badness, &d);
if (r < 0)
return r;
}
assert(range > 0);
if (badness != UINT64_MAX) {
assert(badness <= range);
badness_sum += DIV_ROUND_UP(badness * weight, range);
weight_sum += weight;
}
if (details_table) {
const char *description, *color = NULL;
int checkmark;
if (badness == UINT64_MAX) {
checkmark = -1;
description = access_description_na(a, policy);
color = NULL;
} else if (badness == a->range) {
checkmark = 0;
description = access_description_bad(a, policy);
color = ansi_highlight_red();
} else if (badness == 0) {
checkmark = 1;
description = access_description_good(a, policy);
color = ansi_highlight_green();
} else {
checkmark = 0;
description = NULL;
color = ansi_highlight_red();
}
if (d)
description = d;
if (checkmark < 0) {
r = table_add_many(details_table, TABLE_EMPTY);
if (r < 0)
return table_log_add_error(r);
} else {
r = table_add_many(details_table,
TABLE_BOOLEAN_CHECKMARK, checkmark > 0,
TABLE_SET_MINIMUM_WIDTH, 1,
TABLE_SET_MAXIMUM_WIDTH, 1,
TABLE_SET_ELLIPSIZE_PERCENT, 0,
TABLE_SET_COLOR, color);
if (r < 0)
return table_log_add_error(r);
}
r = table_add_many(details_table,
TABLE_STRING, a->id, TABLE_SET_URL, a->url,
TABLE_STRING, a->json_field,
TABLE_STRING, description,
TABLE_UINT64, weight, TABLE_SET_ALIGN_PERCENT, 100,
TABLE_UINT64, badness, TABLE_SET_ALIGN_PERCENT, 100,
TABLE_UINT64, range, TABLE_SET_ALIGN_PERCENT, 100,
TABLE_EMPTY, TABLE_SET_ALIGN_PERCENT, 100);
if (r < 0)
return table_log_add_error(r);
}
}
assert(weight_sum > 0);
if (details_table) {
size_t row;
for (row = 1; row < table_get_rows(details_table); row++) {
char buf[DECIMAL_STR_MAX(uint64_t) + 1 + DECIMAL_STR_MAX(uint64_t) + 1];
const uint64_t *weight, *badness, *range;
TableCell *cell;
uint64_t x;
assert_se(weight = table_get_at(details_table, row, 4));
assert_se(badness = table_get_at(details_table, row, 5));
assert_se(range = table_get_at(details_table, row, 6));
if (*badness == UINT64_MAX || *badness == 0)
continue;
assert_se(cell = table_get_cell(details_table, row, 7));
x = DIV_ROUND_UP(DIV_ROUND_UP(*badness * *weight * 100U, *range), weight_sum);
xsprintf(buf, "%" PRIu64 ".%" PRIu64, x / 10, x % 10);
r = table_update(details_table, cell, TABLE_STRING, buf);
if (r < 0)
return log_error_errno(r, "Failed to update cell in table: %m");
}
if (!sd_json_format_enabled(json_format_flags)) {
r = table_hide_column_from_display(details_table, (size_t) 2);
if (r < 0)
return log_error_errno(r, "Failed to set columns to display: %m");
}
r = table_print_with_pager(details_table, json_format_flags, pager_flags, /* show_header= */ true);
if (r < 0)
return r;
}
exposure = DIV_ROUND_UP(badness_sum * 100U, weight_sum);
for (i = 0; i < ELEMENTSOF(badness_table); i++)
if (exposure >= badness_table[i].exposure)
break;
assert(i < ELEMENTSOF(badness_table));
if (details_table && !sd_json_format_enabled(json_format_flags)) {
_cleanup_free_ char *clickable = NULL;
const char *name;
/* If we shall output the details table, also print the brief summary underneath */
if (info->fragment_path) {
r = terminal_urlify_path(info->fragment_path, info->id, &clickable);
if (r < 0)
return log_oom();
name = clickable;
} else
name = info->id;
printf("\n%s %sOverall exposure level for %s%s: %s%" PRIu64 ".%" PRIu64 " %s%s %s\n",
glyph(GLYPH_ARROW_RIGHT),
ansi_highlight(),
name,
ansi_normal(),
badness_table[i].color ? badness_table[i].color() : "",
exposure / 10, exposure % 10,
badness_table[i].name,
ansi_normal(),
glyph(badness_table[i].smiley));
}
fflush(stdout);
if (overview_table) {
char buf[DECIMAL_STR_MAX(uint64_t) + 1 + DECIMAL_STR_MAX(uint64_t) + 1];
_cleanup_free_ char *url = NULL;
if (info->fragment_path) {
r = file_url_from_path(info->fragment_path, &url);
if (r < 0)
return log_error_errno(r, "Failed to generate URL from path: %m");
}
xsprintf(buf, "%" PRIu64 ".%" PRIu64, exposure / 10, exposure % 10);
r = table_add_many(overview_table,
TABLE_STRING, info->id,
TABLE_SET_URL, url,
TABLE_STRING, buf,
TABLE_SET_ALIGN_PERCENT, 100,
TABLE_STRING, badness_table[i].name,
TABLE_SET_COLOR, badness_table[i].color ? badness_table[i].color() : "",
TABLE_STRING, glyph(badness_table[i].smiley));
if (r < 0)
return table_log_add_error(r);
}
/* Return error when overall exposure level is over threshold */
if (exposure > threshold)
return -EINVAL;
return 0;
}
static int property_read_restrict_namespaces(
sd_bus *bus,
const char *member,
sd_bus_message *m,
sd_bus_error *error,
void *userdata) {
SecurityInfo *info = ASSERT_PTR(userdata);
int r;
uint64_t namespaces;
assert(bus);
assert(member);
assert(m);
r = sd_bus_message_read(m, "t", &namespaces);
if (r < 0)
return r;