linux/security/selinux/ss
Thiébaud Weksteen d1d991efaf 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-10-07 16:28:11 -04:00
..
avtab.c selinux: replace kmem_cache_create() with KMEM_CACHE() 2024-08-27 18:42:27 -04:00
avtab.h selinux: Add netlink xperm support 2024-10-07 16:28:11 -04:00
conditional.c selinux: constify source policy in cond_policydb_dup() 2024-04-30 19:01:04 -04:00
conditional.h selinux: constify source policy in cond_policydb_dup() 2024-04-30 19:01:04 -04:00
constraint.h selinux: fix style issues in security/selinux/ss/constraint.h 2024-02-23 17:26:02 -05:00
context.c selinux: fix style issues in security/selinux/ss/context.h 2024-02-23 17:26:03 -05:00
context.h selinux: fix style issues in security/selinux/ss/context.h 2024-02-23 17:26:02 -05:00
ebitmap.c selinux: replace kmem_cache_create() with KMEM_CACHE() 2024-08-27 18:42:27 -04:00
ebitmap.h selinux: Use 1UL for EBITMAP_BIT to match maps type 2024-07-02 11:41:05 -04:00
hashtab.c selinux: replace kmem_cache_create() with KMEM_CACHE() 2024-08-27 18:42:27 -04:00
hashtab.h selinux: constify source policy in cond_policydb_dup() 2024-04-30 19:01:04 -04:00
mls_types.h selinux: fix style issues in security/selinux/ss/mls_types.h 2024-02-23 17:26:06 -05:00
mls.c selinux: fix style issues in security/selinux/ss/mls.c 2024-02-23 17:26:05 -05:00
mls.h selinux: fix style issues in security/selinux/ss/mls.h 2024-02-23 17:26:05 -05:00
policydb.c selinux: clarify return code in filename_trans_read_helper_compat() 2024-04-04 16:38:37 -04:00
policydb.h selinux: fix style issues in security/selinux/ss/policydb.h 2024-02-23 17:26:06 -05:00
services.c selinux: Add netlink xperm support 2024-10-07 16:28:11 -04:00
services.h selinux: fix style issues in security/selinux/ss/services.h 2024-02-23 17:26:07 -05:00
sidtab.c selinux: fix style issues in security/selinux/ss/sidtab.c 2024-02-23 17:26:08 -05:00
sidtab.h selinux: fix style issues in security/selinux/ss/sidtab.h 2024-02-23 17:26:07 -05:00
symtab.c selinux: improve symtab string hashing 2024-03-27 19:26:25 -04:00
symtab.h selinux: fix style issues in security/selinux/ss/symtab.h 2024-02-23 17:26:08 -05:00