2020-08-06 14:34:18 -04:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2023-12-21 17:18:54 -05:00
|
|
|
|
2020-08-06 14:34:18 -04:00
|
|
|
#ifndef _SELINUX_POLICYCAP_H_
|
|
|
|
#define _SELINUX_POLICYCAP_H_
|
|
|
|
|
|
|
|
/* Policy capabilities */
|
|
|
|
enum {
|
2022-03-01 12:39:20 -05:00
|
|
|
POLICYDB_CAP_NETPEER,
|
|
|
|
POLICYDB_CAP_OPENPERM,
|
|
|
|
POLICYDB_CAP_EXTSOCKCLASS,
|
|
|
|
POLICYDB_CAP_ALWAYSNETWORK,
|
|
|
|
POLICYDB_CAP_CGROUPSECLABEL,
|
|
|
|
POLICYDB_CAP_NNP_NOSUID_TRANSITION,
|
|
|
|
POLICYDB_CAP_GENFS_SECLABEL_SYMLINKS,
|
|
|
|
POLICYDB_CAP_IOCTL_SKIP_CLOEXEC,
|
selinux: introduce an initial SID for early boot processes
Currently, SELinux doesn't allow distinguishing between kernel threads
and userspace processes that are started before the policy is first
loaded - both get the label corresponding to the kernel SID. The only
way a process that persists from early boot can get a meaningful label
is by doing a voluntary dyntransition or re-executing itself.
Reusing the kernel label for userspace processes is problematic for
several reasons:
1. The kernel is considered to be a privileged domain and generally
needs to have a wide range of permissions allowed to work correctly,
which prevents the policy writer from effectively hardening against
early boot processes that might remain running unintentionally after
the policy is loaded (they represent a potential extra attack surface
that should be mitigated).
2. Despite the kernel being treated as a privileged domain, the policy
writer may want to impose certain special limitations on kernel
threads that may conflict with the requirements of intentional early
boot processes. For example, it is a good hardening practice to limit
what executables the kernel can execute as usermode helpers and to
confine the resulting usermode helper processes. However, a
(legitimate) process surviving from early boot may need to execute a
different set of executables.
3. As currently implemented, overlayfs remembers the security context of
the process that created an overlayfs mount and uses it to bound
subsequent operations on files using this context. If an overlayfs
mount is created before the SELinux policy is loaded, these "mounter"
checks are made against the kernel context, which may clash with
restrictions on the kernel domain (see 2.).
To resolve this, introduce a new initial SID (reusing the slot of the
former "init" initial SID) that will be assigned to any userspace
process started before the policy is first loaded. This is easy to do,
as we can simply label any process that goes through the
bprm_creds_for_exec LSM hook with the new init-SID instead of
propagating the kernel SID from the parent.
To provide backwards compatibility for existing policies that are
unaware of this new semantic of the "init" initial SID, introduce a new
policy capability "userspace_initial_context" and set the "init" SID to
the same context as the "kernel" SID unless this capability is set by
the policy.
Another small backwards compatibility measure is needed in
security_sid_to_context_core() for before the initial SELinux policy
load - see the code comment for explanation.
Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
Reviewed-by: Stephen Smalley <stephen.smalley.work@gmail.com>
[PM: edited comments based on feedback/discussion]
Signed-off-by: Paul Moore <paul@paul-moore.com>
2023-11-14 16:51:16 +01:00
|
|
|
POLICYDB_CAP_USERSPACE_INITIAL_CONTEXT,
|
selinux: Add netlink xperm support
Reuse the existing extended permissions infrastructure to support
policies based on the netlink message types.
A new policy capability "netlink_xperm" is introduced. When disabled,
the previous behaviour is preserved. That is, netlink_send will rely on
the permission mappings defined in nlmsgtab.c (e.g, nlmsg_read for
RTM_GETADDR on NETLINK_ROUTE). When enabled, the mappings are ignored
and the generic "nlmsg" permission is used instead.
The new "nlmsg" permission is an extended permission. The 16 bits of the
extended permission are mapped to the nlmsg_type field.
Example policy on Android, preventing regular apps from accessing the
device's MAC address and ARP table, but allowing this access to
privileged apps, looks as follows:
allow netdomain self:netlink_route_socket {
create read getattr write setattr lock append connect getopt
setopt shutdown nlmsg
};
allowxperm netdomain self:netlink_route_socket nlmsg ~{
RTM_GETLINK RTM_GETNEIGH RTM_GETNEIGHTBL
};
allowxperm priv_app self:netlink_route_socket nlmsg {
RTM_GETLINK RTM_GETNEIGH RTM_GETNEIGHTBL
};
The constants in the example above (e.g., RTM_GETLINK) are explicitly
defined in the policy.
It is possible to generate policies to support kernels that may or
may not have the capability enabled by generating a rule for each
scenario. For instance:
allow domain self:netlink_audit_socket nlmsg_read;
allow domain self:netlink_audit_socket nlmsg;
allowxperm domain self:netlink_audit_socket nlmsg { AUDIT_GET };
The approach of defining a new permission ("nlmsg") instead of relying
on the existing permissions (e.g., "nlmsg_read", "nlmsg_readpriv" or
"nlmsg_tty_audit") has been preferred because:
1. This is similar to the other extended permission ("ioctl");
2. With the new extended permission, the coarse-grained mapping is not
necessary anymore. It could eventually be removed, which would be
impossible if the extended permission was defined below these.
3. Having a single extra extended permission considerably simplifies
the implementation here and in libselinux.
Signed-off-by: Thiébaud Weksteen <tweek@google.com>
Signed-off-by: Bram Bonné <brambonne@google.com>
[PM: manual merge fixes for sock_skip_has_perm()]
Signed-off-by: Paul Moore <paul@paul-moore.com>
2024-09-12 11:45:03 +10:00
|
|
|
POLICYDB_CAP_NETLINK_XPERM,
|
2022-03-01 12:39:20 -05:00
|
|
|
__POLICYDB_CAP_MAX
|
2020-08-06 14:34:18 -04:00
|
|
|
};
|
2022-03-01 12:39:20 -05:00
|
|
|
#define POLICYDB_CAP_MAX (__POLICYDB_CAP_MAX - 1)
|
2020-08-06 14:34:18 -04:00
|
|
|
|
2022-05-02 16:43:38 +02:00
|
|
|
extern const char *const selinux_policycap_names[__POLICYDB_CAP_MAX];
|
2020-08-06 14:34:18 -04:00
|
|
|
|
|
|
|
#endif /* _SELINUX_POLICYCAP_H_ */
|